diff --git a/mavenmcserver/src/main/java/mavenmcserver/command/CommandTicTacToe.java b/mavenmcserver/src/main/java/mavenmcserver/command/CommandTicTacToe.java index 20658b7..32ead9e 100644 --- a/mavenmcserver/src/main/java/mavenmcserver/command/CommandTicTacToe.java +++ b/mavenmcserver/src/main/java/mavenmcserver/command/CommandTicTacToe.java @@ -144,15 +144,7 @@ public List onTabComplete(CommandSender sender, Command command, String if(!(sender instanceof Player)) return new ArrayList(); - ArrayList argList = new ArrayList(); - int i = 0; - for(String arg: args) { - if(!arg.trim().isEmpty() || (i == args.length - 1)) { - argList.add(arg); - } - - i++; - } + ArrayList argList = CommandTicTacToe.removeEmptyElementsExceptForLast(args); ArrayList completions = new ArrayList(); @@ -245,6 +237,20 @@ protected static int[] extractIntegerArgs(String args[]) { return integerArguments; } + private static ArrayList removeEmptyElementsExceptForLast(String[] list) { + ArrayList newList = new ArrayList(); + int i = 0; + for(String element: list) { + if(!element.trim().isEmpty() || (i == list.length - 1)) { + newList.add(element); + } + + i++; + } + + return newList; + } + public class InvalidArgCountException extends Exception { private static final long serialVersionUID = 5946362337911270663L; diff --git a/mavenmcserver/src/main/java/mavenmcserver/command/CommandTicTacToeAccept.java b/mavenmcserver/src/main/java/mavenmcserver/command/CommandTicTacToeAccept.java index 01d6840..ad41e32 100644 --- a/mavenmcserver/src/main/java/mavenmcserver/command/CommandTicTacToeAccept.java +++ b/mavenmcserver/src/main/java/mavenmcserver/command/CommandTicTacToeAccept.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.UUID; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -39,12 +38,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St String playerName = args[CommandTicTacToeAccept.PLAYER_NAME_ARG_INDEX]; - Game targetGame = this.getQueuedGameWithPlayers(playerName, (Player)sender); + Game targetGame = Game.getQueuedGameWithPlayers(playerName, (Player)sender); if(targetGame == null) { try { - targetGame = this.getQueuedGameByUUID(args[CommandTicTacToeAccept.PLAYER_NAME_ARG_INDEX]); + targetGame = Game.getQueuedGameByUUID(args[CommandTicTacToeAccept.PLAYER_NAME_ARG_INDEX]); if(targetGame == null) { sender.sendMessage(ChatColor.RED + "This game is not available anymore." + ChatColor.RESET); @@ -61,22 +60,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return true; } - - private Game getQueuedGameWithPlayers(String mainPlayerName, Player opponentPlayer) { - for(Game queuedGame: Game.queuedGames.values()) { - if(queuedGame.config.opponentPlayer != opponentPlayer) continue; - if(queuedGame.config.mainPlayer.getName().equals(mainPlayerName)) { - return queuedGame; - } - } - - return null; - } - - private Game getQueuedGameByUUID(String uuidString) throws IllegalArgumentException { - UUID gameUUID = UUID.fromString(uuidString); - return Game.queuedGames.get(gameUUID); - } @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { diff --git a/mavenmcserver/src/main/java/mavenmcserver/game/Game.java b/mavenmcserver/src/main/java/mavenmcserver/game/Game.java index 3e54daf..a574fc9 100644 --- a/mavenmcserver/src/main/java/mavenmcserver/game/Game.java +++ b/mavenmcserver/src/main/java/mavenmcserver/game/Game.java @@ -59,6 +59,22 @@ public static List getRequestsTo(Player opponentPlayer) { return result; } + public static Game getQueuedGameWithPlayers(String mainPlayerName, Player opponentPlayer) { + for(Game queuedGame: Game.queuedGames.values()) { + if(queuedGame.config.opponentPlayer != opponentPlayer) continue; + if(queuedGame.config.mainPlayer.getName().equals(mainPlayerName)) { + return queuedGame; + } + } + + return null; + } + + public static Game getQueuedGameByUUID(String uuidString) throws IllegalArgumentException { + UUID gameUUID = UUID.fromString(uuidString); + return Game.queuedGames.get(gameUUID); + } + /// Contains all games that are currently running in connection to their players (every game is in this map twice!) public static HashMap runningGames = new HashMap(); diff --git a/mavenmcserver/src/main/resources/classes.uml b/mavenmcserver/src/main/resources/classes.uml index 7d74da6..0a82b34 100644 --- a/mavenmcserver/src/main/resources/classes.uml +++ b/mavenmcserver/src/main/resources/classes.uml @@ -35,6 +35,8 @@ class FieldPoint { +{static}float FIELD_FALL_SOUND_PITCH +{static}HashMap queuedGames +{static}List getRequestsTo(Player opponentPlayer) + +{static}Game getQueuedGameWithPlayers(String mainPlayerName, Player opponentPlayer) /' For use in CommandTicTacToeAccept.java '/ + +{static}Game getQueuedGameByUUID(String uuidString) /' For use in CommandTicTacToeAccept.java '/ +{static}HashMap runningGames +{static}HashMap lostGames