2
0
RedstoneFuture 2 жил өмнө
parent
commit
b62cc39fa1

+ 3 - 17
missilewars-plugin/src/main/java/de/butzlabben/missilewars/commands/MWCommands.java

@@ -24,7 +24,6 @@ import de.butzlabben.missilewars.Logger;
 import de.butzlabben.missilewars.MissileWars;
 import de.butzlabben.missilewars.MissileWars;
 import de.butzlabben.missilewars.configuration.Config;
 import de.butzlabben.missilewars.configuration.Config;
 import de.butzlabben.missilewars.configuration.Messages;
 import de.butzlabben.missilewars.configuration.Messages;
-import de.butzlabben.missilewars.configuration.arena.Arena;
 import de.butzlabben.missilewars.game.Arenas;
 import de.butzlabben.missilewars.game.Arenas;
 import de.butzlabben.missilewars.game.Game;
 import de.butzlabben.missilewars.game.Game;
 import de.butzlabben.missilewars.game.GameManager;
 import de.butzlabben.missilewars.game.GameManager;
@@ -36,9 +35,6 @@ import de.butzlabben.missilewars.game.missile.MissileFacing;
 import org.bukkit.command.CommandSender;
 import org.bukkit.command.CommandSender;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Player;
 
 
-import java.util.Map;
-import java.util.Optional;
-
 @CommandAlias("mw|missilewars")
 @CommandAlias("mw|missilewars")
 public class MWCommands extends BaseCommand {
 public class MWCommands extends BaseCommand {
 
 
@@ -163,19 +159,9 @@ public class MWCommands extends BaseCommand {
             if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING && game.getArena() == null) {
             if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING && game.getArena() == null) {
                 player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_CAN_NOT_STARTET));
                 player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_CAN_NOT_STARTET));
             } else {
             } else {
-                Map.Entry<String, Integer> mostVotes = null;
-                for (Map.Entry<String, Integer> arena : game.getVotes().entrySet()) {
-                    if (mostVotes == null) {
-                        mostVotes = arena;
-                        continue;
-                    }
-                    if (arena.getValue() > mostVotes.getValue()) mostVotes = arena;
-                }
-                if (mostVotes == null) throw new IllegalStateException("Most votes object was null");
-                Optional<Arena> arena = Arenas.getFromName(mostVotes.getKey());
-                if (arena.isEmpty()) throw new IllegalStateException("Voted arena is not present");
-                game.setArena(arena.get());
-                player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_MAP_SELECTED));
+                game.getMapVoting().setVotedArena();
+                player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_FINISHED)
+                        .replace("%map%", game.getArena().getDisplayName()));
             }
             }
         }
         }
     }
     }

+ 8 - 31
missilewars-plugin/src/main/java/de/butzlabben/missilewars/commands/UserCommands.java

@@ -25,19 +25,14 @@ import co.aikar.commands.annotation.CommandPermission;
 import co.aikar.commands.annotation.Subcommand;
 import co.aikar.commands.annotation.Subcommand;
 import de.butzlabben.missilewars.MissileWars;
 import de.butzlabben.missilewars.MissileWars;
 import de.butzlabben.missilewars.configuration.Messages;
 import de.butzlabben.missilewars.configuration.Messages;
-import de.butzlabben.missilewars.configuration.arena.Arena;
-import de.butzlabben.missilewars.game.Arenas;
 import de.butzlabben.missilewars.game.Game;
 import de.butzlabben.missilewars.game.Game;
 import de.butzlabben.missilewars.game.GameManager;
 import de.butzlabben.missilewars.game.GameManager;
 import de.butzlabben.missilewars.game.Team;
 import de.butzlabben.missilewars.game.Team;
 import de.butzlabben.missilewars.game.enums.GameState;
 import de.butzlabben.missilewars.game.enums.GameState;
-import de.butzlabben.missilewars.game.enums.MapChooseProcedure;
 import de.butzlabben.missilewars.player.MWPlayer;
 import de.butzlabben.missilewars.player.MWPlayer;
 import org.bukkit.command.CommandSender;
 import org.bukkit.command.CommandSender;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Player;
 
 
-import java.util.Optional;
-
 @CommandAlias("mw|missilewars")
 @CommandAlias("mw|missilewars")
 public class UserCommands extends BaseCommand {
 public class UserCommands extends BaseCommand {
 
 
@@ -49,7 +44,12 @@ public class UserCommands extends BaseCommand {
         if (!MWCommands.senderIsPlayer(sender)) return;
         if (!MWCommands.senderIsPlayer(sender)) return;
         Player player = (Player) sender;
         Player player = (Player) sender;
 
 
-        if (args.length > 0) {
+        if (args.length < 1) {
+            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_MAP_NEEDED));
+            return;
+        }
+
+        if (args.length > 1) {
             player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
             player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_TO_MANY_ARGUMENTS));
             return;
             return;
         }
         }
@@ -59,31 +59,8 @@ public class UserCommands extends BaseCommand {
             player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_NOT_IN_GAME_AREA));
             player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.GAME_NOT_IN_GAME_AREA));
             return;
             return;
         }
         }
-
-        if (game.getState() != GameState.LOBBY) {
-            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CHANGE_TEAM_NOT_NOW));
-            return;
-        }
-
-        if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING) {
-            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CANT_VOTE));
-            return;
-        }
-
-        if (game.getArena() != null) {
-            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CHANGE_TEAM_NO_LONGER_NOW));
-            return;
-        }
-
-        String arenaName = args[0];
-        Optional<Arena> arena = Arenas.getFromName(arenaName);
-        if (!game.getVotes().containsKey(arenaName) || arena.isEmpty()) {
-            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_MAP));
-            return;
-        }
-
-        game.getVotes().put(arenaName, game.getVotes().get(arenaName) + 1);
-        player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_SUCCESS).replace("%map%", arena.get().getDisplayName()));
+        
+        game.getMapVoting().addVote(player, args[0]);
     }
     }
 
 
     @Subcommand("change")
     @Subcommand("change")

+ 0 - 12
missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/Lobby.java

@@ -38,7 +38,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
-import java.util.Optional;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 @Getter
 @Getter
@@ -84,21 +83,10 @@ public class Lobby {
         return Bukkit.getWorlds().get(0);
         return Bukkit.getWorlds().get(0);
     }
     }
 
 
-    public void checkForWrongArenas() {
-        for (String arenaName : possibleArenas) {
-            Optional<Arena> arena = Arenas.getFromName(arenaName);
-            if (arena.isEmpty()) {
-                Logger.WARN.log("Could not find arena with name \"" + arenaName + "\" for lobby \"" + getName() + "\"");
-            }
-        }
-    }
-
     public List<Arena> getArenas() {
     public List<Arena> getArenas() {
         return possibleArenas
         return possibleArenas
                 .stream()
                 .stream()
                 .map(Arenas::getFromName)
                 .map(Arenas::getFromName)
-                .filter(Optional::isPresent)
-                .map(Optional::get)
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
     }
     }
 
 

+ 5 - 3
missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/Messages.java

@@ -87,13 +87,13 @@ public class Messages {
         COMMAND_ONLY_PLAYERS("command.only_players", "&cYou are not a player."),
         COMMAND_ONLY_PLAYERS("command.only_players", "&cYou are not a player."),
         COMMAND_TO_MANY_ARGUMENTS("command.to_many_arguments", "&cToo many arguments."),
         COMMAND_TO_MANY_ARGUMENTS("command.to_many_arguments", "&cToo many arguments."),
         COMMAND_INVALID_MISSILE("command.invalid_missile", "&cThe specified missile was not found."),
         COMMAND_INVALID_MISSILE("command.invalid_missile", "&cThe specified missile was not found."),
+        COMMAND_MISSILE_NEEDED("command.missile_needed", "&cPlease specify the missile."),
         COMMAND_INVALID_GAME("command.invalid_game", "&cThe specified game was not found."),
         COMMAND_INVALID_GAME("command.invalid_game", "&cThe specified game was not found."),
         COMMAND_INVALID_MAP("command.invalid_map", "&cThe specified map was not found."),
         COMMAND_INVALID_MAP("command.invalid_map", "&cThe specified map was not found."),
+        COMMAND_MAP_NEEDED("command.map_needed", "&cPlease specify the map."),
         COMMAND_INVALID_TEAM_NUMBER("command.invalid_team_number", "&cThe team number is invalid. Use \"1\" or \"2\" to specify the target team."),
         COMMAND_INVALID_TEAM_NUMBER("command.invalid_team_number", "&cThe team number is invalid. Use \"1\" or \"2\" to specify the target team."),
-        COMMAND_MISSILE_NEEDED("command.missile_needed", "&cPlease specify the missile."),
         COMMAND_TEAM_NUMBER_NEEDED("command.team_number_needed", "&cPlease specify the team number."),
         COMMAND_TEAM_NUMBER_NEEDED("command.team_number_needed", "&cPlease specify the team number."),
-
-        GAME_MAP_SELECTED("game.map_selected", "&7A map was selected. Use \"/mw start\" again to start the round."),
+        
         GAME_PLAYER_JOINED("game.player_joined", "&e%player% &7joined the game (%team%&7)."),
         GAME_PLAYER_JOINED("game.player_joined", "&e%player% &7joined the game (%team%&7)."),
         GAME_PLAYER_LEFT("game.player_left", "&e%player% &7left the game (%team%&7)."),
         GAME_PLAYER_LEFT("game.player_left", "&e%player% &7left the game (%team%&7)."),
         GAME_LEFT("game.left", "&7You left the running MissileWars game."),
         GAME_LEFT("game.left", "&7You left the running MissileWars game."),
@@ -156,6 +156,8 @@ public class Messages {
         VOTE_CANT_VOTE("vote.cant_vote", "&cYou can not vote in this game."),
         VOTE_CANT_VOTE("vote.cant_vote", "&cYou can not vote in this game."),
         VOTE_CHANGE_TEAM_NOT_NOW("vote.change_team_not_now", "&cThe game is not in the right state to vote right now."),
         VOTE_CHANGE_TEAM_NOT_NOW("vote.change_team_not_now", "&cThe game is not in the right state to vote right now."),
         VOTE_CHANGE_TEAM_NO_LONGER_NOW("vote.change_team_no_longer_now", "&cA map was already selected."),
         VOTE_CHANGE_TEAM_NO_LONGER_NOW("vote.change_team_no_longer_now", "&cA map was already selected."),
+        VOTE_MAP_NOT_AVAILABLE("vote.map_not_available", "&cThe selected map is not available for this game."),
+        VOTE_ARENA_ALREADY_SELECTED("vote.arena_already_selected", "&cYou have already voted for this arena."),
 
 
         SIGNEDIT_SIGN_CREATED("signedit.sign_created", "&7Sign was successfully created and connected."),
         SIGNEDIT_SIGN_CREATED("signedit.sign_created", "&7Sign was successfully created and connected."),
         SIGNEDIT_SIGN_REMOVED("signedit.sign_removed", "&7You have successfully removed this missilewars sign."),
         SIGNEDIT_SIGN_REMOVED("signedit.sign_removed", "&7You have successfully removed this missilewars sign."),

+ 12 - 9
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/Arenas.java

@@ -29,16 +29,14 @@ import org.bukkit.Bukkit;
 
 
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
+import java.util.HashMap;
 
 
 public class Arenas {
 public class Arenas {
 
 
-    @Getter private static final List<Arena> arenas = new ArrayList<>();
+    @Getter private static final HashMap<String, Arena> ARENAS = new HashMap<>();
 
 
     public static void load() {
     public static void load() {
-        arenas.clear();
+        ARENAS.clear();
 
 
         File folder = new File(Config.getArenasFolder());
         File folder = new File(Config.getArenasFolder());
 
 
@@ -67,13 +65,13 @@ public class Arenas {
             try {
             try {
                 Arena arena = Serializer.deserialize(config, Arena.class);
                 Arena arena = Serializer.deserialize(config, Arena.class);
                 arena.setFile(config);
                 arena.setFile(config);
-                if (getFromName(arena.getName()).isPresent()) {
+                if (isArenaExists(arena.getName())) {
                     Logger.WARN.log("There are several arenas configured with the name \"" + arena.getName() + "\". Arenas must have a unique name");
                     Logger.WARN.log("There are several arenas configured with the name \"" + arena.getName() + "\". Arenas must have a unique name");
                     continue;
                     continue;
                 }
                 }
                 SetupUtil.checkMap(arena.getTemplateWorld());
                 SetupUtil.checkMap(arena.getTemplateWorld());
                 arena.updateConfig();
                 arena.updateConfig();
-                arenas.add(arena);
+                ARENAS.put(arena.getName(), arena);
             } catch (IOException exception) {
             } catch (IOException exception) {
                 Logger.ERROR.log("Could not load config for arena " + config.getName());
                 Logger.ERROR.log("Could not load config for arena " + config.getName());
                 exception.printStackTrace();
                 exception.printStackTrace();
@@ -81,7 +79,12 @@ public class Arenas {
         }
         }
     }
     }
 
 
-    public static Optional<Arena> getFromName(String name) {
-        return arenas.stream().filter(arena -> arena.getName().equalsIgnoreCase(name)).findFirst();
+    public static Arena getFromName(String arenaName) {
+        if (ARENAS.containsKey(arenaName)) return ARENAS.get(arenaName);
+        return null;
+    }
+
+    public static boolean isArenaExists(String arenaName) {
+        return ARENAS.containsKey(arenaName);
     }
     }
 }
 }

+ 9 - 5
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/Game.java

@@ -80,7 +80,7 @@ public class Game {
     private static final Map<String, Integer> cycles = new HashMap<>();
     private static final Map<String, Integer> cycles = new HashMap<>();
     private static int fights = 0;
     private static int fights = 0;
     private final Map<UUID, MWPlayer> players = new HashMap<>();
     private final Map<UUID, MWPlayer> players = new HashMap<>();
-    private final Map<String, Integer> votes = new HashMap<>(); // Votes for the maps.
+    private final MapVoting mapVoting = new MapVoting(this);
     private final Lobby lobby;
     private final Lobby lobby;
     private final HashMap<UUID, BukkitTask> playerTasks = new HashMap<>();
     private final HashMap<UUID, BukkitTask> playerTasks = new HashMap<>();
     private GameState state = GameState.LOBBY;
     private GameState state = GameState.LOBBY;
@@ -121,8 +121,8 @@ public class Game {
             return;
             return;
         }
         }
 
 
-        if (lobby.getPossibleArenas().stream().noneMatch(a -> Arenas.getFromName(a).isPresent())) {
-            Logger.ERROR.log("None of the specified arenas match a real arena for the lobby " + lobby.getName());
+        if (lobby.getPossibleArenas().stream().noneMatch(Arenas::isArenaExists)) {
+            Logger.ERROR.log("None of the specified arenas match a real arena for the lobby \"" + lobby.getName() + "\".");
             return;
             return;
         }
         }
         
         
@@ -155,17 +155,21 @@ public class Game {
         // choose the game arena
         // choose the game arena
         if (lobby.getMapChooseProcedure() == MapChooseProcedure.FIRST) {
         if (lobby.getMapChooseProcedure() == MapChooseProcedure.FIRST) {
             setArena(lobby.getArenas().get(0));
             setArena(lobby.getArenas().get(0));
+            
         } else if (lobby.getMapChooseProcedure() == MapChooseProcedure.MAPCYCLE) {
         } else if (lobby.getMapChooseProcedure() == MapChooseProcedure.MAPCYCLE) {
             final int lastMapIndex = cycles.getOrDefault(lobby.getName(), -1);
             final int lastMapIndex = cycles.getOrDefault(lobby.getName(), -1);
             List<Arena> arenas = lobby.getArenas();
             List<Arena> arenas = lobby.getArenas();
             int index = lastMapIndex >= arenas.size() - 1 ? 0 : lastMapIndex + 1;
             int index = lastMapIndex >= arenas.size() - 1 ? 0 : lastMapIndex + 1;
             cycles.put(lobby.getName(), index);
             cycles.put(lobby.getName(), index);
             setArena(arenas.get(index));
             setArena(arenas.get(index));
+            
         } else if (lobby.getMapChooseProcedure() == MapChooseProcedure.MAPVOTING) {
         } else if (lobby.getMapChooseProcedure() == MapChooseProcedure.MAPVOTING) {
-            if (lobby.getArenas().size() == 1) {
+            if (mapVoting.onlyOneArenaFound()) {
                 setArena(lobby.getArenas().get(0));
                 setArena(lobby.getArenas().get(0));
+                Logger.WARN.log("Only one arena was found for the lobby \"" + lobby.getName() + "\". The configured map voting was skipped.");
+            } else {
+                mapVoting.startVote();
             }
             }
-            lobby.getArenas().forEach(arena -> votes.put(arena.getName(), 0));
         }
         }
 
 
         scoreboardManager = new ScoreboardManager(this);
         scoreboardManager = new ScoreboardManager(this);

+ 73 - 11
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/MapVoting.java

@@ -20,8 +20,10 @@ package de.butzlabben.missilewars.game;
 
 
 import de.butzlabben.missilewars.configuration.Messages;
 import de.butzlabben.missilewars.configuration.Messages;
 import de.butzlabben.missilewars.configuration.arena.Arena;
 import de.butzlabben.missilewars.configuration.arena.Arena;
+import de.butzlabben.missilewars.game.enums.MapChooseProcedure;
 import de.butzlabben.missilewars.game.enums.VoteState;
 import de.butzlabben.missilewars.game.enums.VoteState;
 import de.butzlabben.missilewars.player.MWPlayer;
 import de.butzlabben.missilewars.player.MWPlayer;
+import lombok.Getter;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Player;
 
 
 import java.util.HashMap;
 import java.util.HashMap;
@@ -33,37 +35,64 @@ public class MapVoting {
 
 
     private final Map<MWPlayer, Arena> arenaVotes = new HashMap<>();
     private final Map<MWPlayer, Arena> arenaVotes = new HashMap<>();
     private Game game;
     private Game game;
-    public VoteState state = VoteState.NULL;
+    @Getter private VoteState state = VoteState.NULL;
 
 
     public MapVoting(Game game) {
     public MapVoting(Game game) {
         this.game = game;
         this.game = game;
     }
     }
 
 
-    public void addVote(Player player, Arena arena) {
-
-        if (game.getArena() != null) {
-            //TODO Message
-            player.sendMessage(Messages.getPrefix() + Messages.getMessage("vote.arenaAlreadySelected").replace("%map%", arena.getDisplayName()));
+    /**
+     * This method saves the incoming votes of the players, provided that all 
+     * conditions for the voting process are met. If the conditions are not met, 
+     * the player will be notified accordingly.
+     * 
+     * @param player (Player) the voter
+     * @param arenaName (String) the voted arena name
+     */
+    public void addVote(Player player, String arenaName) {
+        
+        if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING) {
+            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CANT_VOTE));
+            return;
+        }
+        
+        if (state == VoteState.NULL) {
+            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CHANGE_TEAM_NOT_NOW));
+            return;
+        } else if (state == VoteState.FINISH) {
+            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_CHANGE_TEAM_NO_LONGER_NOW));
             return;
             return;
         }
         }
 
 
+        Arena arena = Arenas.getFromName(arenaName);
+        if (arena == null) {
+            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_MAP));
+            return;
+        }
+        
         if (!game.getLobby().getArenas().contains(arena)) {
         if (!game.getLobby().getArenas().contains(arena)) {
-            //TODO Message
-            player.sendMessage(Messages.getPrefix() + Messages.getMessage("vote.arenaNotExist").replace("%map%", arena.getDisplayName()));
+            player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_MAP_NOT_AVAILABLE));
             return;
             return;
         }
         }
 
 
         MWPlayer mwPlayer = game.getPlayer(player);
         MWPlayer mwPlayer = game.getPlayer(player);
 
 
-        // remove old vote
         if (arenaVotes.containsKey(mwPlayer)) {
         if (arenaVotes.containsKey(mwPlayer)) {
+
+            if (arenaVotes.get(mwPlayer) == arena) {
+                player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_ARENA_ALREADY_SELECTED)
+                        .replace("%map%", arena.getDisplayName()));
+                return;
+            }
+
+            // remove old vote
             arenaVotes.remove(mwPlayer);
             arenaVotes.remove(mwPlayer);
         }
         }
 
 
         // add new vote
         // add new vote
         arenaVotes.put(mwPlayer, arena);
         arenaVotes.put(mwPlayer, arena);
 
 
-        player.sendMessage(Messages.getMessage("vote.success").replace("%map%", arena.getDisplayName()));
+        player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.VOTE_SUCCESS).replace("%map%", arena.getDisplayName()));
     }
     }
 
 
     /**
     /**
@@ -71,7 +100,7 @@ public class MapVoting {
      *
      *
      * @return (Arena) the winner arena for this vote
      * @return (Arena) the winner arena for this vote
      */
      */
-    public Arena getVotedArena() {
+    private Arena getVotedArena() {
 
 
         Arena arena = arenaVotes.values().stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
         Arena arena = arenaVotes.values().stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
                 .entrySet()
                 .entrySet()
@@ -79,15 +108,48 @@ public class MapVoting {
                 .max(Map.Entry.comparingByValue()).orElseThrow()
                 .max(Map.Entry.comparingByValue()).orElseThrow()
                 .getKey();
                 .getKey();
 
 
+        // If no one voted:
+        if (arena == null) arena = game.getLobby().getArenas().get(0);
+        
         return arena;
         return arena;
     }
     }
 
 
+    /**
+     * This method unlocks the map voting.
+     */
     public void startVote() {
     public void startVote() {
         state = VoteState.RUNNING;
         state = VoteState.RUNNING;
     }
     }
 
 
+    /**
+     * This method locks the map voting again.
+     */
     public void stopVote() {
     public void stopVote() {
         state = VoteState.FINISH;
         state = VoteState.FINISH;
     }
     }
 
 
+    /**
+     * This method checks if there is only one arena map available for this lobby and 
+     * therefore no map vote is necessary.
+     * 
+     * @return (Boolean) true, if only one map exists for this lobby
+     */
+    public boolean onlyOneArenaFound() {
+        return (game.getLobby().getArenas().size() == 1);
+    }
+
+    /**
+     * This method sets the selected arena of map voting for the current game.
+     */
+    public void setVotedArena() {
+        if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING) return;
+        if (onlyOneArenaFound()) return;
+
+        stopVote();
+        
+        Arena arena = game.getMapVoting().getVotedArena();
+        if (arena == null) throw new IllegalStateException("Voted arena is not present");
+        game.setArena(arena);
+    }
+    
 }
 }

+ 2 - 26
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/timer/LobbyTimer.java

@@ -19,16 +19,10 @@
 package de.butzlabben.missilewars.game.timer;
 package de.butzlabben.missilewars.game.timer;
 
 
 import de.butzlabben.missilewars.configuration.Messages;
 import de.butzlabben.missilewars.configuration.Messages;
-import de.butzlabben.missilewars.configuration.arena.Arena;
-import de.butzlabben.missilewars.game.Arenas;
 import de.butzlabben.missilewars.game.Game;
 import de.butzlabben.missilewars.game.Game;
-import de.butzlabben.missilewars.game.enums.MapChooseProcedure;
 import de.butzlabben.missilewars.player.MWPlayer;
 import de.butzlabben.missilewars.player.MWPlayer;
 import org.bukkit.Sound;
 import org.bukkit.Sound;
 
 
-import java.util.Map;
-import java.util.Optional;
-
 /**
 /**
  * @author Butzlabben
  * @author Butzlabben
  * @since 11.01.2018
  * @since 11.01.2018
@@ -85,7 +79,7 @@ public class LobbyTimer extends Timer implements Runnable {
                 playPling();
                 playPling();
                 break;
                 break;
             case 10:
             case 10:
-                checkVote();
+                getGame().getMapVoting().setVotedArena();
                 broadcast(Messages.getMessage(true, Messages.MessageEnum.LOBBY_TIMER_GAME_STARTS_IN).replace("%seconds%", Integer.toString(seconds)));
                 broadcast(Messages.getMessage(true, Messages.MessageEnum.LOBBY_TIMER_GAME_STARTS_IN).replace("%seconds%", Integer.toString(seconds)));
                 playPling();
                 playPling();
                 break;
                 break;
@@ -112,23 +106,5 @@ public class LobbyTimer extends Timer implements Runnable {
             mwPlayer.getPlayer().playSound(mwPlayer.getPlayer().getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 100, 3);
             mwPlayer.getPlayer().playSound(mwPlayer.getPlayer().getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 100, 3);
         }
         }
     }
     }
-
-    private void checkVote() {
-        Game game = getGame();
-        if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING) return;
-        if (game.getArena() != null) return;
-
-        Map.Entry<String, Integer> mostVotes = null;
-        for (Map.Entry<String, Integer> arena : game.getVotes().entrySet()) {
-            if (mostVotes == null) {
-                mostVotes = arena;
-                continue;
-            }
-            if (arena.getValue() > mostVotes.getValue()) mostVotes = arena;
-        }
-        if (mostVotes == null) throw new IllegalStateException("Most votes object was null");
-        Optional<Arena> arena = Arenas.getFromName(mostVotes.getKey());
-        if (arena.isEmpty()) throw new IllegalStateException("Voted arena is not present");
-        game.setArena(arena.get());
-    }
+    
 }
 }

+ 5 - 11
missilewars-plugin/src/main/java/de/butzlabben/missilewars/util/SetupUtil.java

@@ -23,14 +23,10 @@ import de.butzlabben.missilewars.MissileWars;
 import de.butzlabben.missilewars.configuration.Config;
 import de.butzlabben.missilewars.configuration.Config;
 import de.butzlabben.missilewars.configuration.arena.Arena;
 import de.butzlabben.missilewars.configuration.arena.Arena;
 import de.butzlabben.missilewars.game.Arenas;
 import de.butzlabben.missilewars.game.Arenas;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.*;
 import java.net.URL;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Files;
@@ -39,8 +35,6 @@ import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipInputStream;
-import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.plugin.java.JavaPlugin;
 
 
 /**
 /**
  * @author Butzlabben
  * @author Butzlabben
@@ -106,7 +100,7 @@ public class SetupUtil {
             shieldFolder.mkdir();
             shieldFolder.mkdir();
         }
         }
 
 
-        for (Arena arena : Arenas.getArenas()) {
+        for (Arena arena : Arenas.getARENAS().values()) {
             File shield = new File(shieldFolder, arena.getShieldConfiguration().getSchematic());
             File shield = new File(shieldFolder, arena.getShieldConfiguration().getSchematic());
             if (!shield.isFile()) {
             if (!shield.isFile()) {
                 String resource = "shield.schematic";
                 String resource = "shield.schematic";