diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 4646e57..631447e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -212,6 +212,8 @@ public class Main extends JavaPlugin implements Listener { public EntityHider getEntityHider() { return entityHider; } + public CommandGroup getCommandGroup() { return commandGroup; } + public boolean supports(int v){ return version >= v; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 4297f3d..d94b48a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -19,22 +19,72 @@ package net.tylermurphy.hideAndSeek.command; -import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.util.CommandGroup; +import net.tylermurphy.hideAndSeek.util.Pair; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Help extends Command { public void execute(Player sender, String[] args) { -// StringBuilder message = new StringBuilder(); -// for(Command command : CommandGroup.COMMAND_REGISTER.values()) { -// message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n")); -// } -// message = new StringBuilder(message.substring(0, message.length() - 1)); -// sender.sendMessage(message.toString()); + final int pageSize = 4; + List> commands = Main.getInstance().getCommandGroup().getCommands(); + int pages = (commands.size() - 1) / pageSize + 1; + int page; + try { + if(args.length < 1) { + page = 1; + } else { + page = Integer.parseInt(args[0]); + if (page < 1) { + throw new IllegalArgumentException("Inavlid Input"); + } + } + } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + String spacer = ChatColor.GRAY + "?" + ChatColor.WHITE; + StringBuilder message = new StringBuilder(); + message.append(String.format("%s================ %sHelp: Page (%s/%s) %s================", + ChatColor.AQUA, ChatColor.WHITE, page, pages, ChatColor.AQUA)); + int lines = 0; + for(Pair pair : commands.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList())) { + Command command = pair.getRight(); + String label = pair.getLeft(); + String start = label.substring(0, label.indexOf(" ")); + String invoke = label.substring(label.indexOf(" ")+1); + message.append(String.format("\n%s %s/%s %s%s %s%s\n%s %s%s%s", + spacer, + ChatColor.AQUA, + start, + ChatColor.WHITE, + invoke, + ChatColor.BLUE, + command.getUsage(), + spacer, + ChatColor.GRAY, + ChatColor.ITALIC, + command.getDescription() + )); + lines += 2; + } + if(lines / 2 < pageSize) { + for(int i = 0; i < pageSize * 2 - lines; i++) { + message.append("\n").append(spacer); + } + } + message.append("\n").append(ChatColor.AQUA).append("==============================================="); + sender.sendMessage(message.toString()); } public String getLabel() { @@ -42,15 +92,15 @@ public class Help extends Command { } public String getUsage() { - return ""; + return "<*page>"; } public String getDescription() { return "Get the commands for the plugin"; } - public List autoComplete(String parameter) { - return null; + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + return Collections.singletonList(parameter); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index ca2a77f..7b219a7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -61,7 +62,7 @@ public class Join extends Command { return "Joins the lobby if game is set to manual join/leave"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index d22aad9..ebfd7ee 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -60,7 +61,7 @@ public class Leave extends Command { return "Leaves the lobby if game is set to manual join/leave"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 9f8392f..1fc2c95 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -66,7 +67,7 @@ public class Reload extends Command { return "Reloads the config"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java index 9978c3c..87cc9a6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java @@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -57,8 +58,8 @@ public class Send extends Command { return "Set the current lobby to another map"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index 874909b..e8adf24 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -51,10 +52,10 @@ public class SetExitLocation extends Command { } public String getDescription() { - return "Sets hide and seeks exit location to current position and world"; + return "Sets the plugins exit location"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 674edd6..0a73591 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; @@ -89,8 +90,8 @@ public class Start extends Command { return "Starts the game either with a random seeker or chosen one"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("player")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("player")) { return Main.getInstance().getBoard().getPlayers().stream().map(Player::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 7c8cabf..9fd9aab 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -57,7 +58,7 @@ public class Stop extends Command { return "Stops the game"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 0a5358d..e795d77 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; @@ -83,7 +84,7 @@ public class Top extends Command { return "Gets the top players in the server."; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return Collections.singletonList(parameter); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index c5917c2..f1feb33 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; @@ -80,7 +81,7 @@ public class Wins extends Command { return "Get the win information for yourself or another player."; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return Collections.singletonList(parameter); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java index 03c2a95..89a5b79 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java @@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; @@ -44,8 +45,8 @@ public class Add extends Command { return "Add a map to the plugin!"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("name")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("name")) { return Collections.singletonList("name"); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java index 4adb806..c5d0352 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.List; @@ -38,7 +39,7 @@ public class Debug extends Command { private Inventory createMenu(net.tylermurphy.hideAndSeek.configuration.Map map, Player sender){ Map> functions = new HashMap<>(); - Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu"); + Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 9, "Debug Menu"); debugMenu.setItem(0, createOption(functions, 0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> { if(mapSaveEnabled) { if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); @@ -75,10 +76,10 @@ public class Debug extends Command { } })); if(map.isBlockHuntEnabled()) { - debugMenu.setItem(9, createOption(functions, 7, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { + debugMenu.setItem(7, createOption(functions, 7, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { PlayerLoader.openBlockHuntPicker(player, map); })); - debugMenu.setItem(10, createOption(functions, 8, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + debugMenu.setItem(8, createOption(functions, 8, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); } debugMenuFunctions.put(sender, functions); return debugMenu; @@ -112,8 +113,8 @@ public class Debug extends Command { return "Run debug commands"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java index 8e74922..34ca8f9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java @@ -4,6 +4,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -48,13 +49,13 @@ public class GoTo extends Command { } public String getDescription() { - return "Get the commands for the plugin"; + return "Teleport to a map spawn zone"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } else if(parameter != null && parameter.equals("spawn")) { + } else if(parameter.equals("spawn")) { return Arrays.asList("spawn","lobby","seekerlobby","exit"); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java index 635c011..65b33d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java @@ -5,6 +5,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -39,7 +40,7 @@ public class List extends Command { return "List all maps in the plugin"; } - public java.util.List autoComplete(String parameter) { + public java.util.List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java index 45dec99..4f708b6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java @@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -43,8 +44,8 @@ public class Remove extends Command { return "Remove a map from the plugin!"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java index 1f95df3..c28d2e9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -27,6 +27,7 @@ import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -89,11 +90,11 @@ public class Save extends Command { } public String getDescription() { - return "Saves current map for the game. May lag server."; + return "Saves the map to its own separate playable map"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java index d9dd8fb..053603b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -84,11 +85,11 @@ public class Status extends Command { } public String getDescription() { - return "Shows what needs to be setup"; + return "Shows what needs to be setup on a map"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java index b8d2e15..ed14380 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -47,11 +48,11 @@ public class Enabled extends Command { return "Sets blockhunt enabled or disabled in a current map"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } - if(parameter != null && parameter.equals("bool")) { + if(parameter.equals("bool")) { return Arrays.asList("true", "false"); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java index 021dae0..bd4cf9f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java @@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -56,11 +57,15 @@ public class Add extends Command { return "Add a blockhunt block to a map!"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } else if(parameter != null && parameter.equals("block")) { - return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList()); + } else if(parameter.equals("block")) { + return Arrays.stream(Material.values()) + .filter(Material::isBlock) + .map(Material::toString) + .filter(s -> s.toUpperCase().startsWith(typed.toUpperCase())) + .collect(Collectors.toList()); } return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java index ecb626f..396f2dd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java @@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.stream.Collectors; @@ -45,8 +46,8 @@ public class List extends Command { return "List all blockhunt blocks in a map"; } - public java.util.List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public java.util.List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java index 7bbd5d3..fed9dfa 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java @@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -56,11 +57,15 @@ public class Remove extends Command { return "Remove a blockhunt block from a map!"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } else if(parameter != null && parameter.equals("block")) { - return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList()); + } else if(parameter.equals("block")) { + return Arrays.stream(Material.values()) + .filter(Material::isBlock) + .map(Material::toString) + .filter(s -> s.toUpperCase().startsWith(typed.toUpperCase())) + .collect(Collectors.toList()); } return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java index 92339b4..1b59abc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java @@ -25,6 +25,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; @@ -99,11 +100,11 @@ public class Border extends Command { } public String getDescription() { - return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; + return "Sets a maps world border information"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return Collections.singletonList(parameter); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java index 9896389..1adfc59 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java @@ -25,6 +25,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -102,8 +103,8 @@ public class Bounds extends Command { return "Sets the map bounds for the game."; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java index c691787..f2395f1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -45,11 +46,11 @@ public class Lobby extends Command { } public String getDescription() { - return "Sets hide and seeks lobby location to current position"; + return "Sets the maps lobby location"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java index 2521f19..ebbef1c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java @@ -5,6 +5,7 @@ import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -34,11 +35,11 @@ public class SeekerLobby extends Command { } public String getDescription() { - return "Sets hide and seeks seeker lobby location to current position"; + return "Sets the maps seeker lobby location"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java index 3e8f77e..c954876 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java @@ -26,6 +26,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -66,11 +67,11 @@ public class Spawn extends Command { } public String getDescription() { - return "Sets hide and seeks spawn location to current position"; + return "Sets the maps game spawn location"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java index d03274d..41fd4d5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command.util; import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -34,10 +34,6 @@ public abstract class Command { public abstract String getDescription(); - public abstract List autoComplete(@Nullable String parameter); + public abstract List autoComplete(@NotNull String parameter, @NotNull String typed); - public boolean hasPermission(Player sender, String permission) { - return sender.hasPermission(permission+"."+getLabel()); - } - } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index 32f4081..5c47860 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -19,8 +19,8 @@ package net.tylermurphy.hideAndSeek.command.util; -import net.tylermurphy.hideAndSeek.command.*; import net.tylermurphy.hideAndSeek.command.map.Save; +import net.tylermurphy.hideAndSeek.util.Pair; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -62,12 +62,12 @@ public class CommandGroup { } public boolean handleCommand(Player player, String permission, String[] args) { - if (args.length < 1 && permission.equals("hs") || !commandRegister.containsKey(args[0].toLowerCase()) ) { + if (args.length < 1 || !commandRegister.containsKey(args[0].toLowerCase()) ) { if (permissionsRequired && !player.hasPermission("hs.about")) { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { player.sendMessage( - String.format("%s%sHide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); @@ -76,20 +76,29 @@ public class CommandGroup { String invoke = args[0].toLowerCase(); if (!invoke.equals("about") && !invoke.equals("help") && Save.runningBackup) { player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); - } else if (permissionsRequired && !player.hasPermission(permission+"."+invoke)) { - player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { try { Object object = commandRegister.get(invoke); - if(object instanceof CommandGroup) return ((CommandGroup) object).handleCommand(player, permission+"."+this.label, Arrays.copyOfRange(args, 1, args.length)); - Command command = (Command) object; - int parameters = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); - if(args.length - 1 < parameters) { - player.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); - return true; + if(object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + return group.handleCommand(player, permission+"."+group.getLabel(), Arrays.copyOfRange(args, 1, args.length)); + } else if(object instanceof Command) { + Command command = (Command) object; + + if (permissionsRequired && !player.hasPermission(permission+"."+command.getLabel())) { + player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); + return true; + } + + int parameterCount = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); + if(args.length - 1 < parameterCount) { + player.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); + return true; + } + + command.execute(player,Arrays.copyOfRange(args, 1, args.length)); } - command.execute(player,Arrays.copyOfRange(args, 1, args.length)); } catch (Exception e) { player.sendMessage(errorPrefix + "An error has occurred."); e.printStackTrace(); @@ -109,67 +118,75 @@ public class CommandGroup { .filter(handle -> handle.toLowerCase().startsWith(invoke)) .filter(handle -> { Object object = commandRegister.get(handle); - if (object instanceof Command) return ((Command) object).hasPermission(player, this.label); - if (object instanceof CommandGroup) - return ((CommandGroup) object).hasPermission(player, this.label); + if (object instanceof Command) { + Command command = (Command) object; + return player.hasPermission(command.getLabel()); + } else if (object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + return group.hasPermission(player, group.getLabel()); + } return false; }) .collect(Collectors.toList()); - } - return commandRegister.keySet().stream().filter(handle -> handle.toLowerCase().startsWith(invoke)).collect(Collectors.toList()); - } else { - if (!commandRegister.containsKey(invoke)) { - return new ArrayList<>(); } else { - Object object = commandRegister.get(invoke); - if(object instanceof CommandGroup) return ((CommandGroup) object).handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length)); - Command command = (Command) object; - String[] usage = command.getUsage().split(" "); - List complete; - if (args.length - 2 < usage.length) { - String parameter = usage[args.length-2]; - String name = parameter.replace("<", "").replace(">", ""); - complete = command.autoComplete(name); - } else { - complete = command.autoComplete(null); - } - if(complete == null) return new ArrayList<>(); - else return complete; + return commandRegister.keySet() + .stream() + .filter(handle -> handle.toLowerCase().startsWith(invoke)) + .collect(Collectors.toList()); } + } else { + if (commandRegister.containsKey(invoke)) { + Object object = commandRegister.get(invoke); + if (object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + return group.handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length)); + } else if (object instanceof Command) { + Command command = (Command) object; + String[] usage = command.getUsage().split(" "); + if (args.length - 2 < usage.length) { + String parameter = usage[args.length - 2]; + String name = parameter.replace("<", "").replace(">", ""); + List list = command.autoComplete(name, args[args.length - 1]); + if (list != null) { + return list; + } + } + } + } + return new ArrayList<>(); } } private boolean hasPermission(Player player, String permission) { for(Object object : commandRegister.values()) { - if(object instanceof Command) if(((Command) object).hasPermission(player, this.label)) return true; - if(object instanceof CommandGroup) if (((CommandGroup) object).hasPermission(player, permission+"."+this.label)) return true; + if(object instanceof Command) { + Command command = (Command) object; + if(player.hasPermission(permission+"."+command.getLabel())) return true; + } else if(object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + if (group.hasPermission(player, permission+"."+group.getLabel())) return true; + } } return false; } - // public static void registerCommands() { -// registerCommand(new About()); -// registerCommand(new Help()); -// registerCommand(new Setup()); -// registerCommand(new Start()); -// registerCommand(new Stop()); -// registerCommand(new SetSpawnLocation()); -// registerCommand(new SetLobbyLocation()); -// registerCommand(new SetSeekerLobbyLocation()); -// registerCommand(new SetExitLocation()); -// registerCommand(new SetBorder()); -// registerCommand(new Reload()); -// registerCommand(new SaveMap()); -// registerCommand(new SetBounds()); -// registerCommand(new Join()); -// registerCommand(new Leave()); -// registerCommand(new Top()); -// registerCommand(new Wins()); -// registerCommand(new Debug()); -// registerCommand(new AddMap()); -// registerCommand(new RemoveMap()); -// registerCommand(new ListMaps()); -// registerCommand(new SetMap()); -// } + public List> getCommands() { + return getCommands(this.getLabel()); + } + + private List> getCommands(String prefix) { + List> commands = new LinkedList<>(); + for(Object object : commandRegister.values()) { + if(object instanceof Command) { + Command command = (Command) object; + commands.add(new Pair<>(prefix+" "+command.getLabel(), command)); + } else if(object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + commands.addAll(group.getCommands(prefix+" "+group.getLabel())); + } + } + return commands; + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Pair.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Pair.java new file mode 100644 index 0000000..0aad195 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Pair.java @@ -0,0 +1,21 @@ +package net.tylermurphy.hideAndSeek.util; + +public class Pair { + + private final L left; + private final R right; + + public Pair(L left, R right) { + this.left = left; + this.right = right; + } + + public L getLeft() { + return left; + } + + public R getRight() { + return right; + } + +}