diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2024-07-02 01:55:07 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2024-07-02 01:55:07 -0400 |
commit | ec048c36764120a0f912a775474d5a028f48d9e3 (patch) | |
tree | 81046c47b2ce2571fb45dafe972e69c00d88fc13 /src/main/java/com/MylesAndMore/Tumble/commands | |
parent | 3b63c0e4ef7b14fd89d94170e5e6aa683374f0f8 (diff) | |
download | Tumble-ec048c36764120a0f912a775474d5a028f48d9e3.tar.gz Tumble-ec048c36764120a0f912a775474d5a028f48d9e3.tar.bz2 Tumble-ec048c36764120a0f912a775474d5a028f48d9e3.zip |
Add javadoc comments and other code cleanup
Diffstat (limited to 'src/main/java/com/MylesAndMore/Tumble/commands')
4 files changed, 21 insertions, 2 deletions
diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/ForceStart.java b/src/main/java/com/MylesAndMore/Tumble/commands/ForceStart.java index 2d39c83..bf130ea 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/ForceStart.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/ForceStart.java @@ -32,6 +32,7 @@ public class ForceStart implements SubCommand, CommandExecutor, TabCompleter { Game game; if (args.length < 1 || args[0] == null) { + // no arena passed in, try to infer from game player is in game = arenaManager.findGamePlayerIsIn((Player)sender); if (game == null) { sender.sendMessage(languageManager.fromKey("missing-arena-parameter")); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/ForceStop.java b/src/main/java/com/MylesAndMore/Tumble/commands/ForceStop.java index 24f430c..8ab48c2 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/ForceStop.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/ForceStop.java @@ -32,6 +32,7 @@ public class ForceStop implements SubCommand, CommandExecutor, TabCompleter { Game game; if (args.length < 1 || args[0] == null) { + // no arena passed in, try to infer from game player is in game = arenaManager.findGamePlayerIsIn((Player)sender); if (game == null) { sender.sendMessage(languageManager.fromKey("missing-arena-parameter")); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/Join.java b/src/main/java/com/MylesAndMore/Tumble/commands/Join.java index 1dbbad6..3177f3e 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/Join.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/Join.java @@ -59,6 +59,7 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter { Game game; if (args.length < 2 || args[1] == null) { + // try to infer game type from game taking place in the arena if (arena.game == null) { sender.sendMessage(languageManager.fromKey("specify-game-type")); return false; @@ -80,10 +81,12 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter { } if (arena.game == null) { + // no game is taking place in this arena, start one game = arena.game = new Game(arena, type); } else { + // a game is taking place in this arena, check that it is the right type if (arena.game.type == type) { game = arena.game; } @@ -96,6 +99,7 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter { } } + // check to make sure the arena has a game spawn if (game.arena.gameSpawn == null) { if (p.isOp()) { sender.sendMessage(languageManager.fromKey("arena-not-ready-op")); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/Tumble.java b/src/main/java/com/MylesAndMore/Tumble/commands/Tumble.java index 2cf5b90..67213ee 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/Tumble.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/Tumble.java @@ -42,6 +42,7 @@ public class Tumble implements CommandExecutor, TabCompleter { return false; } + // pass command action through to subCommand subCmd.onCommand(sender, command, args[0], removeFirst(args)); return true; } @@ -49,6 +50,7 @@ public class Tumble implements CommandExecutor, TabCompleter { @Override public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { if (args.length == 1) { + // show only subCommands the user has permission for ArrayList<String> PermittedSubCmds = new ArrayList<>(); for (SubCommand subCmd: subCommands.values()) { if (sender.hasPermission(subCmd.getPermission())) { @@ -63,6 +65,7 @@ public class Tumble implements CommandExecutor, TabCompleter { return Collections.emptyList(); } + // pass tab complete through to subCommand if (subCommands.get(args[0]) instanceof TabCompleter tcmp) { return tcmp.onTabComplete(sender, command, args[0], removeFirst(args)); } @@ -74,13 +77,23 @@ public class Tumble implements CommandExecutor, TabCompleter { return Collections.emptyList(); } + /** + * Create a copy of an array with the first element removed + * @param arr the source array + * @return the source without the first element + */ private String[] removeFirst(String[] arr) { ArrayList<String> tmp = new ArrayList<>(List.of(arr)); tmp.remove(0); return tmp.toArray(new String[0]); } - private static Map.Entry<String, SubCommand> CmdNameAsKey(SubCommand s) { - return Map.entry(s.getCommandName(),s); + /** + * Creates a map entry with the name of the subCommand as the key and the subCommand itself as the value + * @param cmd The subCommand to use + * @return A map entry from the subCommand + */ + private static Map.Entry<String, SubCommand> CmdNameAsKey(SubCommand cmd) { + return Map.entry(cmd.getCommandName(),cmd); } } |