diff options
Diffstat (limited to '')
24 files changed, 452 insertions, 65 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 54af32b..54e0de7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -22,11 +22,13 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import java.util.List; + public class About implements ICommand { public void execute(Player sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(%s1.6.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(%s1.7.0 ALPHA%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) ); @@ -44,4 +46,8 @@ public class About implements ICommand { return "Get information about the plugin"; } + public List<String> autoComplete(String parameter) { + return null; + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java new file mode 100644 index 0000000..086280e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java @@ -0,0 +1,54 @@ +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.Main; +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 java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class AddMap implements ICommand { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map != null) { + sender.sendMessage(errorPrefix + message("MAP_ALREADY_EXISTS")); + } else if(!args[0].matches("[a-zA-Z0-9]*") || args[0].length() < 1) { + sender.sendMessage(errorPrefix + message("INVALID_MAP_NAME")); + } else { + Maps.setMap(args[0], new Map(args[0])); + sender.sendMessage(messagePrefix + message("MAP_CREATED").addAmount(args[0])); + } + } + + public String getLabel() { + return "addmap"; + } + + public String getUsage() { + return "<name>"; + } + + public String getDescription() { + return "Add a map to the plugin!"; + } + + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("name")) { + return Collections.singletonList("name"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java index 2ca998e..e877659 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java @@ -13,101 +13,96 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Debug implements ICommand { - private static final Map<Integer, Consumer<Player>> debugMenuFunctions = new HashMap<>(); - private Inventory debugMenu; + private static final Map<Player, Map<Integer, Consumer<Player>>> debugMenuFunctions = new HashMap<>(); public void execute(Player sender, String[] args) { - if(args.length < 1) args = new String[]{""}; - if(debugMenu == null) createMenu(args[0]); + net.tylermurphy.hideAndSeek.configuration.Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + Inventory debugMenu = createMenu(map, sender); sender.openInventory(debugMenu); } - private void createMenu(String mapname){ - net.tylermurphy.hideAndSeek.configuration.Map map = Maps.getMap(mapname); - debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu"); - debugMenu.setItem(0, createOption(0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> { + private Inventory createMenu(net.tylermurphy.hideAndSeek.configuration.Map map, Player sender){ + Map<Integer, Consumer<Player>> functions = new HashMap<>(); + Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu"); + debugMenu.setItem(0, createOption(functions, 0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> { if(mapSaveEnabled) { - if(Main.getInstance().getGame().getCurrentMap().getSpawn().getWorld() == null) Main.getInstance().getGame().getCurrentMap().getWorldLoader().loadMap(); + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); } Main.getInstance().getBoard().addHider(player); - PlayerLoader.loadHider(player, Main.getInstance().getGame().getCurrentMap()); + PlayerLoader.loadHider(player, map); if(Main.getInstance().getGame().getStatus() != Status.STARTING) PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); })); - debugMenu.setItem(1, createOption(1, XMaterial.GOLDEN_CHESTPLATE.parseMaterial(), "&cBecome a &lSeeker", 1, player -> { + debugMenu.setItem(1, createOption(functions, 1, XMaterial.GOLDEN_CHESTPLATE.parseMaterial(), "&cBecome a &lSeeker", 1, player -> { if(mapSaveEnabled) { - if(Main.getInstance().getGame().getCurrentMap().getSpawn().getWorld() == null) Main.getInstance().getGame().getCurrentMap().getWorldLoader().loadMap(); + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); } Main.getInstance().getBoard().addSeeker(player); - PlayerLoader.loadSeeker(player, Main.getInstance().getGame().getCurrentMap()); + PlayerLoader.loadSeeker(player, map); if(Main.getInstance().getGame().getStatus() != Status.STARTING) PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); })); - debugMenu.setItem(2, createOption(2, XMaterial.IRON_CHESTPLATE.parseMaterial(), "&8Become a &lSpectator", 1, player -> { + debugMenu.setItem(2, createOption(functions, 2, XMaterial.IRON_CHESTPLATE.parseMaterial(), "&8Become a &lSpectator", 1, player -> { if(mapSaveEnabled) { - if(Main.getInstance().getGame().getCurrentMap().getSpawn().getWorld() == null) Main.getInstance().getGame().getCurrentMap().getWorldLoader().loadMap(); + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); } Main.getInstance().getBoard().addSpectator(player); - PlayerLoader.loadSpectator(player, Main.getInstance().getGame().getCurrentMap()); + PlayerLoader.loadSpectator(player, map); })); - debugMenu.setItem(3, createOption(3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> { + debugMenu.setItem(3, createOption(functions, 3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> { Main.getInstance().getBoard().remove(player); PlayerLoader.unloadPlayer(player); player.teleport(exitPosition); })); - debugMenu.setItem(4, createOption(4, XMaterial.BARRIER.parseMaterial(), "&cDie In Game", 2, player -> { + debugMenu.setItem(4, createOption(functions, 4, XMaterial.BARRIER.parseMaterial(), "&cDie In Game", 2, player -> { if((Main.getInstance().getBoard().isSeeker(player) || Main.getInstance().getBoard().isHider(player)) && Main.getInstance().getGame().getStatus() == Status.PLAYING){ player.setHealth(0.1); } })); - debugMenu.setItem(6, createOption(6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { - if(map == null) { - player.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } + debugMenu.setItem(6, createOption(functions, 6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { if(mapSaveEnabled) { - if(map.getSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); } - player.teleport(map.getSpawn()); + player.teleport(map.getGameSpawn()); })); - debugMenu.setItem(7, createOption(7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { - if(map == null) { - player.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } + debugMenu.setItem(7, createOption(functions, 7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { player.teleport(map.getLobby()); })); - debugMenu.setItem(8, createOption(8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> player.teleport(exitPosition))); - debugMenu.setItem(9, createOption(9, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { - if(map == null) { - player.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } + debugMenu.setItem(8, createOption(functions, 8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> player.teleport(exitPosition))); + debugMenu.setItem(9, createOption(functions, 9, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { PlayerLoader.openBlockHuntPicker(player, map); })); - debugMenu.setItem(10, createOption(10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + debugMenu.setItem(10, createOption(functions, 10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + debugMenuFunctions.put(sender, functions); + return debugMenu; } - private ItemStack createOption(int slow, Material material, String name, int amount, Consumer<Player> callback){ + private ItemStack createOption(Map<Integer, Consumer<Player>> functions, int slow, Material material, String name, int amount, Consumer<Player> callback){ ItemStack temp = new ItemStack(material, amount); ItemMeta meta = temp.getItemMeta(); meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); temp.setItemMeta(meta); - debugMenuFunctions.put(slow, callback); + functions.put(slow, callback); return temp; } public static void handleOption(Player player, int slotId){ Main.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { - Consumer<Player> callback = debugMenuFunctions.get(slotId); + Consumer<Player> callback = debugMenuFunctions.get(player).get(slotId); if(callback != null) callback.accept(player); }, 0); } @@ -117,11 +112,18 @@ public class Debug implements ICommand { } public String getUsage() { - return "<*map>"; + return "<map>"; } public String getDescription() { return "Run debug commands"; } + public List<String> autoComplete(String parameter) { + if(parameter != null && 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/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 97224d7..5de7210 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -23,6 +23,8 @@ import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.util.CommandHandler; import org.bukkit.entity.Player; +import java.util.List; + public class Help implements ICommand { public void execute(Player sender, String[] args) { @@ -46,4 +48,8 @@ public class Help implements ICommand { return "Get the commands for the plugin"; } + public List<String> autoComplete(String parameter) { + return null; + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java index 275d189..91fd8f9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java @@ -20,6 +20,9 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.List; public interface ICommand { @@ -30,5 +33,7 @@ public interface ICommand { String getUsage(); String getDescription(); + + List<String> autoComplete(@Nullable String parameter); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index cf8944e..c57b953 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -23,13 +23,15 @@ import net.tylermurphy.hideAndSeek.Main; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.List; + import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Join implements ICommand { public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { + if (Main.getInstance().getGame().checkCurrentMap()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -58,4 +60,8 @@ public class Join implements ICommand { return "Joins the lobby if game is set to manual join/leave"; } + public List<String> autoComplete(String parameter) { + 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 fee7ca8..0e860cb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -23,13 +23,15 @@ import net.tylermurphy.hideAndSeek.Main; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.List; + import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Leave implements ICommand { public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { + if (Main.getInstance().getGame().checkCurrentMap()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -57,4 +59,8 @@ public class Leave implements ICommand { return "Leaves the lobby if game is set to manual join/leave"; } + public List<String> autoComplete(String parameter) { + return null; + } + }
\ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java new file mode 100644 index 0000000..0025de5 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java @@ -0,0 +1,46 @@ +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class ListMaps implements ICommand { + + public void execute(Player sender, String[] args) { + Collection<Map> maps = Maps.getAllMaps(); + if(maps.size() < 1) { + sender.sendMessage(errorPrefix + message("NO_MAPS")); + return; + } + StringBuilder response = new StringBuilder(messagePrefix + message("LIST_MAPS")); + for(Map map : maps) { + response.append("\n ").append(map.getName()).append(": ").append(map.isNotSetup() ? ChatColor.RED + "NOT SETUP" : ChatColor.GREEN + "SETUP").append(ChatColor.WHITE); + } + sender.sendMessage(response.toString()); + } + + public String getLabel() { + return "listmaps"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "List all maps in the plugin"; + } + + public List<String> autoComplete(String parameter) { + return null; + } + +}
\ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 56f4517..4a4efbe 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -23,9 +23,12 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Localization; +import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import java.util.List; + import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -39,6 +42,7 @@ public class Reload implements ICommand { return; } Config.loadConfig(); + Maps.loadMaps(); Localization.loadLocalization(); Items.loadItems(); sender.sendMessage(messagePrefix + message("CONFIG_RELOAD")); @@ -55,5 +59,9 @@ public class Reload implements ICommand { public String getDescription() { return "Reloads the config"; } - + + public List<String> autoComplete(String parameter) { + return null; + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java new file mode 100644 index 0000000..b5727c8 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java @@ -0,0 +1,52 @@ +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.Main; +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 java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class RemoveMap implements ICommand { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + } else if(!Maps.removeMap(args[0])){ + sender.sendMessage(errorPrefix + message("MAP_FAIL_DELETE").addAmount(args[0])); + } else { + sender.sendMessage(messagePrefix + message("MAP_DELETED").addAmount(args[0])); + } + } + + public String getLabel() { + return "removemap"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Remove a map from the plugin!"; + } + + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +}
\ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index 4758666..ca2532c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -27,6 +27,9 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import java.util.List; +import java.util.stream.Collectors; + import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -82,5 +85,12 @@ public class SaveMap implements ICommand { public String getDescription() { return "Saves current map for the game. May lag server."; } - + + public List<String> autoComplete(String parameter) { + if(parameter != null && 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/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index 08a8c87..9768030 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -26,6 +26,11 @@ import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -45,7 +50,7 @@ public class SetBorder implements ICommand { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } - if (args.length < 3) { + if (args.length < 4) { map.setWorldBorderData(0, 0, 0, 0, 0); addToConfig("worldBorder.enabled",false); saveConfig(); @@ -91,11 +96,18 @@ public class SetBorder implements ICommand { } public String getUsage() { - return "<map> <size> <delay> <move>"; + return "<map> <*size> <*delay> <*move>"; } public String getDescription() { return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; } + public List<String> autoComplete(String parameter) { + if(parameter != null && 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/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index c22e3a6..563116d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -25,6 +25,9 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import java.util.List; +import java.util.stream.Collectors; + import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -44,7 +47,7 @@ public class SetBounds implements ICommand { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } - if (!sender.getWorld().getName().equals(map.getSpawn().getWorld().getName())) { + if (!sender.getWorld().getName().equals(map.getSpawnName())) { sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); return; } @@ -72,7 +75,7 @@ public class SetBounds implements ICommand { } if (bzl == 0) { bzl = sender.getLocation().getBlockZ(); - } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockZ()) { + } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { first = false; bzs = bzl; bzl = sender.getLocation().getBlockZ(); @@ -82,8 +85,8 @@ public class SetBounds implements ICommand { } map.setBoundMin(bxs, bzs); map.setBoundMax(bxl, bzl); + Maps.setMap(map.getName(), map); sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); - saveConfig(); } public String getLabel() { @@ -98,4 +101,11 @@ public class SetBounds implements ICommand { return "Sets the map bounds for the game."; } + public List<String> autoComplete(String parameter) { + if(parameter != null && 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/SetMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java new file mode 100644 index 0000000..c2c6a6e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java @@ -0,0 +1,66 @@ +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.Main; +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 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 SetMap implements ICommand { + + public void execute(Player sender, String[] args) { + + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + + if(map.isNotSetup()){ + sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP")); + return; + } + + if (!Main.getInstance().getBoard().contains(sender)) { + sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); + return; + } + + Main.getInstance().getGame().setCurrentMap(map); + for(Player player : Main.getInstance().getBoard().getPlayers()) { + player.teleport(map.getLobby()); + } + + } + + public String getLabel() { + return "setmap"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Set the current lobby to another map"; + } + + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +}
\ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index ef052aa..b222c61 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -25,6 +25,8 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; import java.io.File; +import java.util.List; +import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -40,19 +42,19 @@ public class Setup implements ICommand { sender.sendMessage(errorPrefix + message("INVALID_MAP")); return; } - if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0) { + if (map.getSpawn().getWorld() == null || map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0) { msg = msg + "\n" + message("SETUP_GAME"); count++; } - if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0) { + if (map.getLobby().getWorld() == null || map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0) { msg = msg + "\n" + message("SETUP_LOBBY"); count++; } - if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0) { + if (map.getSeekerLobby().getWorld() == null || map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0) { msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); count++; } - if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) { + if (exitWorld == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) { msg = msg + "\n" + message("SETUP_EXIT"); count++; } @@ -62,7 +64,7 @@ public class Setup implements ICommand { count++; } if (mapSaveEnabled) { - File destenation = new File(Main.getInstance().getWorldContainer() + File.separator + map.getSpawn().getWorld().getName()); + File destenation = new File(Main.getInstance().getWorldContainer() + File.separator + map.getGameSpawnName()); if (!destenation.exists()) { msg = msg + "\n" + message("SETUP_SAVEMAP"); count++; @@ -87,4 +89,11 @@ public class Setup implements ICommand { return "Shows what needs to be setup"; } + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + }
\ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 2d847d5..085aeab 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -20,12 +20,15 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.List; import java.util.Optional; import java.util.Random; +import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.minPlayers; @@ -34,7 +37,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Start implements ICommand { public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { + if (Main.getInstance().getGame().checkCurrentMap()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -86,4 +89,11 @@ public class Start implements ICommand { return "Starts the game either with a random seeker or chosen one"; } + public List<String> autoComplete(String parameter) { + if(parameter != null && 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 22ab3fb..4567bb1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -23,6 +23,9 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import java.util.List; +import java.util.stream.Collectors; + import static net.tylermurphy.hideAndSeek.configuration.Config.abortPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -30,7 +33,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Stop implements ICommand { public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { + if (Main.getInstance().getGame().checkCurrentMap()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } @@ -54,4 +57,8 @@ public class Stop implements ICommand { return "Stops the game"; } + public List<String> autoComplete(String parameter) { + 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 72a695c..c57f246 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.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import java.util.Collections; import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; @@ -80,4 +81,9 @@ public class Top implements ICommand { public String getDescription() { return "Gets the top players in the server."; } + + public List<String> autoComplete(String parameter) { + 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 e12d2d4..9ed7345 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -24,6 +24,8 @@ import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import java.util.Collections; +import java.util.List; import java.util.UUID; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; @@ -70,10 +72,14 @@ public class Wins implements ICommand { } public String getUsage() { - return "<player>"; + return "<*player>"; } public String getDescription() { return "Get the win information for yourself or another player."; } + + public List<String> autoComplete(String parameter) { + return Collections.singletonList(parameter); + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java index a616297..1bb1d6f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -22,13 +22,18 @@ package net.tylermurphy.hideAndSeek.command.location; import net.tylermurphy.hideAndSeek.command.ICommand; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetExitLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.EXIT, args[0], map -> { + LocationUtils.setLocation(sender, Locations.EXIT, null, map -> { addToConfig("exit.x", sender.getLocation().getBlockX()); addToConfig("exit.y", sender.getLocation().getBlockY()); addToConfig("exit.z", sender.getLocation().getBlockZ()); @@ -51,4 +56,8 @@ public class SetExitLocation implements ICommand { return "Sets hide and seeks exit location to current position and world"; } + public List<String> autoComplete(String parameter) { + return null; + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java index 4eb5462..84e1109 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -22,8 +22,12 @@ package net.tylermurphy.hideAndSeek.command.location; import net.tylermurphy.hideAndSeek.command.ICommand; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import java.util.List; +import java.util.stream.Collectors; + import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetLobbyLocation implements ICommand { @@ -39,11 +43,18 @@ public class SetLobbyLocation implements ICommand { } public String getUsage() { - return ""; + return "<map>"; } public String getDescription() { return "Sets hide and seeks lobby location to current position"; } + public List<String> autoComplete(String parameter) { + if(parameter != null && 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/location/SetSeekerLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java index 59bec64..c6d9f93 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java @@ -3,14 +3,24 @@ package net.tylermurphy.hideAndSeek.command.location; import net.tylermurphy.hideAndSeek.command.ICommand; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetSeekerLobbyLocation implements ICommand { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { + if(map.isSpawnNotSetup()) { + throw new RuntimeException(message("GAME_SPAWN_NEEDED").toString()); + } + if(!map.getSpawnName().equals(sender.getLocation().getWorld().getName())) { + throw new RuntimeException(message("SEEKER_LOBBY_INVALID").toString()); + } map.setSeekerLobby(sender.getLocation()); }); } @@ -20,11 +30,18 @@ public class SetSeekerLobbyLocation implements ICommand { } public String getUsage() { - return ""; + return "<map>"; } public String getDescription() { return "Sets hide and seeks seeker lobby location to current position"; } + public List<String> autoComplete(String parameter) { + if(parameter != null && 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/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java index 12ac232..50932d6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -22,9 +22,14 @@ package net.tylermurphy.hideAndSeek.command.location; import net.tylermurphy.hideAndSeek.command.ICommand; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import java.util.List; +import java.util.stream.Collectors; + import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -41,7 +46,12 @@ public class SetSpawnLocation implements ICommand { map.setSpawn(sender.getLocation()); - if (!sender.getLocation().getWorld().getName().equals(map.getSpawn().getWorld().getName()) && mapSaveEnabled) { + if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().getName().equals(sender.getLocation().getWorld().getName())) { + sender.sendMessage(message("SEEKER_LOBBY_SPAWN_RESET").toString()); + map.setSeekerLobby(new Location(null, 0, 0, 0)); + } + + if (!sender.getLocation().getWorld().getName().equals(map.getSpawnName()) && mapSaveEnabled) { map.getWorldLoader().unloadMap(); } }); @@ -59,4 +69,11 @@ public class SetSpawnLocation implements ICommand { return "Sets hide and seeks spawn location to current position"; } + public List<String> autoComplete(String parameter) { + if(parameter != null && 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/location/util/LocationUtils.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java index 2655805..69d7c26 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java @@ -38,7 +38,13 @@ public class LocationUtils { } } - consumer.accept(map); + try { + consumer.accept(map); + } catch (Exception e) { + player.sendMessage(errorPrefix + e.getMessage()); + return; + } + if(map != null) Maps.setMap(mapName, map); player.sendMessage(messagePrefix + message(place.message())); |