From 1325e042a6e7af37669bcd32e9d7a133f2ae22e6 Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 30 Oct 2022 21:40:59 -0400 Subject: [PATCH] finish beta build of multi map support --- pom.xml | 2 +- .../net/tylermurphy/hideAndSeek/Main.java | 5 +- .../hideAndSeek/command/About.java | 8 +- .../hideAndSeek/command/AddMap.java | 54 ++++++++++++ .../hideAndSeek/command/Debug.java | 84 ++++++++++--------- .../tylermurphy/hideAndSeek/command/Help.java | 6 ++ .../hideAndSeek/command/ICommand.java | 5 ++ .../tylermurphy/hideAndSeek/command/Join.java | 8 +- .../hideAndSeek/command/Leave.java | 8 +- .../hideAndSeek/command/ListMaps.java | 46 ++++++++++ .../hideAndSeek/command/Reload.java | 10 ++- .../hideAndSeek/command/RemoveMap.java | 52 ++++++++++++ .../hideAndSeek/command/SaveMap.java | 12 ++- .../hideAndSeek/command/SetBorder.java | 16 +++- .../hideAndSeek/command/SetBounds.java | 16 +++- .../hideAndSeek/command/SetMap.java | 66 +++++++++++++++ .../hideAndSeek/command/Setup.java | 19 +++-- .../hideAndSeek/command/Start.java | 12 ++- .../tylermurphy/hideAndSeek/command/Stop.java | 9 +- .../tylermurphy/hideAndSeek/command/Top.java | 6 ++ .../tylermurphy/hideAndSeek/command/Wins.java | 8 +- .../command/location/SetExitLocation.java | 11 ++- .../command/location/SetLobbyLocation.java | 13 ++- .../location/SetSeekerLobbyLocation.java | 21 ++++- .../command/location/SetSpawnLocation.java | 19 ++++- .../command/location/util/LocationUtils.java | 8 +- .../hideAndSeek/configuration/Map.java | 52 +++++++++--- .../hideAndSeek/configuration/Maps.java | 37 +++++--- .../tylermurphy/hideAndSeek/game/Game.java | 24 ++++-- .../hideAndSeek/game/PlayerLoader.java | 6 +- .../hideAndSeek/game/events/Border.java | 5 +- .../game/listener/DamageHandler.java | 12 +-- .../game/listener/InteractHandler.java | 2 +- .../game/listener/JoinLeaveHandler.java | 6 +- .../game/listener/MovementHandler.java | 4 +- .../hideAndSeek/util/CommandHandler.java | 14 +++- .../hideAndSeek/util/TabCompleter.java | 20 ++--- .../hideAndSeek/world/WorldLoader.java | 44 ++++------ .../resources/lang/localization_en-US.yml | 15 +++- src/main/resources/plugin.yml | 18 +++- 40 files changed, 631 insertions(+), 152 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java diff --git a/pom.xml b/pom.xml index dfd99ff..bf41e70 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 net.tylermurphy KenshinsHideAndSeek - 1.6.2 + 1.7.0 Hide and Seek Plugin diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 0e890c6..aace88e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -22,6 +22,7 @@ package net.tylermurphy.hideAndSeek; 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.database.Database; import net.tylermurphy.hideAndSeek.game.*; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -30,7 +31,6 @@ import net.tylermurphy.hideAndSeek.game.listener.*; import net.tylermurphy.hideAndSeek.util.PAPIExpansion; import net.tylermurphy.hideAndSeek.util.TabCompleter; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.event.Listener; @@ -62,6 +62,7 @@ public class Main extends JavaPlugin implements Listener { this.updateVersion(); Config.loadConfig(); + Maps.loadMaps(); Localization.loadLocalization(); Items.loadItems(); @@ -73,7 +74,7 @@ public class Main extends JavaPlugin implements Listener { CommandHandler.registerCommands(); - game = new Game(board); + game = new Game(game.getCurrentMap(), board); getServer().getScheduler().runTaskTimer(this, this::onTick,0,1).getTaskId(); 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 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 ""; + } + + public String getDescription() { + return "Add a map to the plugin!"; + } + + public List 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> debugMenuFunctions = new HashMap<>(); - private Inventory debugMenu; + private static final Map>> 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> 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 callback){ + private ItemStack createOption(Map> functions, int slow, Material material, String name, int amount, Consumer 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 callback = debugMenuFunctions.get(slotId); + Consumer 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 ""; } public String getDescription() { return "Run debug commands"; } + public List 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 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 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 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 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 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 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 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 ""; + } + + public String getDescription() { + return "Remove a map from the plugin!"; + } + + public List 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 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 " "; + return " <*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 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 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 ""; + } + + public String getDescription() { + return "Set the current lobby to another map"; + } + + public List 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 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 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 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 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 ""; + return "<*player>"; } public String getDescription() { return "Get the win information for yourself or another player."; } + + public List 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 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 ""; } public String getDescription() { return "Sets hide and seeks lobby location to current position"; } + public List 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 ""; } public String getDescription() { return "Sets hide and seeks seeker lobby location to current position"; } + public List 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 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())); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java index b18a0b0..42cab4b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -1,6 +1,7 @@ package net.tylermurphy.hideAndSeek.configuration; import java.io.File; +import java.util.ArrayList; import java.util.List; import net.tylermurphy.hideAndSeek.Main; @@ -22,7 +23,7 @@ public class Map { seekerLobbyPosition = new Location(null, 0, 0, 0); private String - gameWorldName; + gameWorldName = "world"; private int xBoundMin = 0, @@ -36,10 +37,10 @@ public class Map { worldBorderChange = 0; private boolean - blockhunt; + blockhunt = false; private List - blockhuntBlocks; + blockhuntBlocks = new ArrayList<>(); private final Border worldBorder; @@ -55,7 +56,8 @@ public class Map { public void setSpawn(Location pos) { this.spawnPosition = pos; - this.gameWorldName = pos.getWorld().getName(); + if(pos.getWorld() != null) + this.gameWorldName = pos.getWorld().getName(); } public void setLobby(Location pos) { @@ -73,7 +75,6 @@ public class Map { this.worldBorderChange = 0; this.xWorldBorder = 0; this.zWorldBorder = 0; - this.worldBorder.resetWorldBorder(); } else { this.worldBorderSize = size; this.worldBorderDelay = delay; @@ -81,6 +82,7 @@ public class Map { this.xWorldBorder = x; this.zWorldBorder = z; } + this.worldBorder.resetWorldBorder(); } public void setBlockhunt(boolean enabled, List blocks) { @@ -98,14 +100,31 @@ public class Map { this.zBoundMax = z; } + public Location getGameSpawn() { + if(mapSaveEnabled) { + return new Location( + Bukkit.getWorld("hs_" + gameWorldName), + spawnPosition.getX(), + spawnPosition.getY(), + spawnPosition.getZ() + ); + } else { + return spawnPosition; + } + } + + public String getGameSpawnName() { + return "hs_"+gameWorldName; + } + public Location getSpawn() { - if(mapSaveEnabled) - spawnPosition.setWorld(Bukkit.getWorld("hs_"+gameWorldName)); - else - spawnPosition.setWorld(Bukkit.getWorld(gameWorldName)); return spawnPosition; } + public String getSpawnName() { + return gameWorldName; + } + public Location getLobby() { return lobbyPosition; } @@ -114,6 +133,19 @@ public class Map { return seekerLobbyPosition; } + public Location getGameSeekerLobby() { + if(mapSaveEnabled) { + return new Location( + Bukkit.getWorld("hs_" + gameWorldName), + seekerLobbyPosition.getX(), + seekerLobbyPosition.getY(), + seekerLobbyPosition.getZ() + ); + } else { + return seekerLobbyPosition; + } + } + public boolean isWorldBorderEnabled() { return worldBorderSize > 0; } @@ -158,7 +190,7 @@ public class Map { return new Vector( xBoundMax, 0, - zBoundMin + zBoundMax ); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java index 736fec2..4f18639 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -21,10 +21,17 @@ public class Maps { } public static Map getRandomMap() { - Optional map = MAPS.values().stream().skip(new Random().nextInt(MAPS.values().size())).findFirst(); - if(map.isPresent()) return map.get(); - setMap("default", new Map("default")); - return MAPS.get("default"); + Optional map; + if(MAPS.values().size() > 0) { + Collection setupMaps = MAPS.values().stream().filter(m -> !m.isNotSetup()).collect(Collectors.toList()); + if(setupMaps.size() < 1) { + return null; + } + map = setupMaps.stream().skip(new Random().nextInt(setupMaps.size())).findFirst(); + } else { + map = Optional.empty(); + } + return map.orElse(null); } public static void setMap(String name, Map map) { @@ -32,6 +39,12 @@ public class Maps { saveMaps(); } + public static boolean removeMap(String name) { + boolean status = MAPS.remove(name) != null; + saveMaps(); + return status; + } + public static Collection getAllMaps() { return MAPS.values(); } @@ -69,9 +82,11 @@ public class Maps { data.getInt("worldborder.delay"), data.getInt("worldborder.change") ); + List blockhunt = data.getStringList("blockhunt.blocks"); + if(blockhunt == null) blockhunt = new ArrayList<>(); map.setBlockhunt( - data.getBoolean("blockhunt.enabled"), - data.getStringList("blockhunt.blocks") + data.getBoolean("blockhunt.enabled"), + blockhunt .stream() .map(XMaterial::matchXMaterial) .filter(Optional::isPresent) @@ -113,8 +128,8 @@ public class Maps { data.set("worldborder.pos.delay", map.getWorldBorderData().getY()); data.set("worldborder.pos.change", map.getWorldBorderData().getZ()); data.set("blockhunt.enabled", map.isBlockHuntEnabled()); - data.set("blockhunt.blocks", map.getBlockHunt().stream().map(Material::name)); - maps.set(map.getName(), map); + data.set("blockhunt.blocks", map.getBlockHunt().stream().map(Material::name).collect(Collectors.toList())); + maps.set(map.getName(), data); } manager.set("maps", maps); @@ -128,9 +143,9 @@ public class Maps { } else { data.set("spawns." + name + ".world", "world"); } - data.set("spawns.." + name + ".x", spawn.getX()); - data.set("spawns.." + name + ".y", spawn.getY()); - data.set("spawns.." + name + ".z", spawn.getZ()); + data.set("spawns." + name + ".x", spawn.getX()); + data.set("spawns." + name + ".y", spawn.getY()); + data.set("spawns." + name + ".z", spawn.getZ()); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 2f86849..53e61df 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -59,8 +59,12 @@ public class Game { private boolean hiderLeft; public Game(Board board) { + this(Maps.getRandomMap(), board); + } - this.currentMap = Maps.getRandomMap(); + public Game(Map map, Board board) { + + this.currentMap = map; this.taunt = new Taunt(); this.glow = new Glow(); @@ -140,6 +144,8 @@ public class Game { public void end() { board.getPlayers().forEach(PlayerLoader::unloadPlayer); currentMap.getWorldBorder().resetWorldBorder(); + Map nextMap = Maps.getRandomMap(); + if(nextMap != null) this.currentMap = nextMap; board.getPlayers().forEach(player -> { if (leaveOnEnd) { board.removeBoard(player); @@ -213,7 +219,7 @@ public class Game { } public void onTick() { - if (currentMap.isNotSetup()) return; + if (currentMap == null || currentMap.isNotSetup()) return; if (status == Status.STANDBY) whileWaiting(); else if (status == Status.STARTING) whileStarting(); else if (status == Status.PLAYING) whilePlaying(); @@ -249,7 +255,7 @@ public class Game { board.getPlayers().forEach(player -> { PlayerLoader.resetPlayer(player, board); if(board.isSeeker(player)){ - player.teleport(currentMap.getSpawn()); + player.teleport(currentMap.getGameSpawn()); } }); } else if (startingTimer == 1){ @@ -327,13 +333,19 @@ public class Game { return currentMap; } + public boolean checkCurrentMap() { + if(currentMap != null) return false; + this.currentMap = Maps.getRandomMap(); + return this.currentMap == null; + } + public void setCurrentMap(Map map) { this.currentMap = map; } - public World getGameWorld() { - if(currentMap == null || currentMap.getSpawn() == null) return null; - else return currentMap.getSpawn().getWorld(); + public String getGameWorld() { + if(currentMap == null) return null; + else return currentMap.getGameSpawnName(); } private void checkWinConditions() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java index 83f4eee..d830972 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java @@ -40,7 +40,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class PlayerLoader { public static void loadHider(Player player, Map map){ - player.teleport(map.getSpawn()); + player.teleport(map.getGameSpawn()); loadPlayer(player); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("HIDER_TEAM_NAME"), ChatColor.WHITE + message("HIDERS_SUBTITLE").toString()); @@ -50,13 +50,13 @@ public class PlayerLoader { } public static void loadSeeker(Player player, Map map){ - player.teleport(map.getSeekerLobby()); + player.teleport(map.getGameSeekerLobby()); loadPlayer(player); Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("SEEKER_TEAM_NAME"), ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString()); } public static void loadSpectator(Player player, Map map){ - player.teleport(map.getSpawn()); + player.teleport(map.getGameSpawn()); loadPlayer(player); player.setAllowFlight(true); player.setFlying(true); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/events/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/game/events/Border.java index 9fb7e13..f7ab581 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/events/Border.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/events/Border.java @@ -41,13 +41,14 @@ public class Border { running = true; Main.getInstance().getGame().broadcastMessage(worldBorderPrefix + message("WORLDBORDER_DECREASING").addAmount(change)); currentSize -= map.getWorldBorderData().getZ(); - org.bukkit.WorldBorder border = map.getSpawn().getWorld().getWorldBorder(); + org.bukkit.WorldBorder border = map.getGameSpawn().getWorld().getWorldBorder(); border.setSize(border.getSize()-change,30); delay = 30; } public void resetWorldBorder() { - org.bukkit.WorldBorder border = map.getSpawn().getWorld().getWorldBorder(); + if(map.getGameSpawn().getWorld() == null) return; + org.bukkit.WorldBorder border = map.getGameSpawn().getWorld().getWorldBorder(); if (map.isWorldBorderEnabled()) { border.setSize(map.getWorldBorderData().getX()); border.setCenter(map.getWorldBorderPos().getX(), map.getWorldBorderPos().getY()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java index cd63fd8..08a5a80 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java @@ -31,7 +31,7 @@ public class DamageHandler implements Listener { Player player = (Player) event.getEntity(); Player attacker = null; // If map is not setup we won't be able to process on it :o - if (game.getCurrentMap().isNotSetup()) { return; } + if (game.getCurrentMap() == null || game.getCurrentMap().isNotSetup()) { return; } // If there is an attacker, find them if (event instanceof EntityDamageByEntityEvent) { if (((EntityDamageByEntityEvent) event).getDamager() instanceof Player) @@ -71,9 +71,9 @@ public class DamageHandler implements Listener { if (board.isSpectator(player)) { event.setCancelled(true); if (Main.getInstance().supports(18) && player.getLocation().getBlockY() < -64) { - player.teleport(game.getCurrentMap().getSpawn()); + player.teleport(game.getCurrentMap().getGameSpawn()); } else if (!Main.getInstance().supports(18) && player.getLocation().getY() < 0) { - player.teleport(game.getCurrentMap().getSpawn()); + player.teleport(game.getCurrentMap().getGameSpawn()); } return; } @@ -96,15 +96,15 @@ public class DamageHandler implements Listener { Main.getInstance().getDisguiser().reveal(player); // Teleport player to seeker spawn if(delayedRespawn){ - player.teleport(game.getCurrentMap().getSeekerLobby()); + player.teleport(game.getCurrentMap().getGameSeekerLobby()); player.sendMessage(messagePrefix + message("RESPAWN_NOTICE").addAmount(delayedRespawnDelay)); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { if(game.getStatus() == Status.PLAYING){ - player.teleport(game.getCurrentMap().getSpawn()); + player.teleport(game.getCurrentMap().getGameSpawn()); } }, delayedRespawnDelay * 20L); } else { - player.teleport(game.getCurrentMap().getSpawn()); + player.teleport(game.getCurrentMap().getGameSpawn()); } // Add leaderboard stats board.addDeath(player.getUniqueId()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InteractHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InteractHandler.java index 1f2c388..0326391 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InteractHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InteractHandler.java @@ -50,7 +50,7 @@ public class InteractHandler implements Listener { if (temp.isSimilar(lobbyStartItem) && event.getPlayer().hasPermission("hideandseek.start")) { event.setCancelled(true); - if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { + if (Main.getInstance().getGame().checkCurrentMap()) { event.getPlayer().sendMessage(errorPrefix + message("GAME_SETUP")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/JoinLeaveHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/JoinLeaveHandler.java index 0ad95b5..9af8629 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/JoinLeaveHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/JoinLeaveHandler.java @@ -24,16 +24,16 @@ public class JoinLeaveHandler implements Listener { } Main.getInstance().getBoard().remove(event.getPlayer()); removeItems(event.getPlayer()); - if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) return; + if (Main.getInstance().getGame().checkCurrentMap()) return; if (autoJoin) { Main.getInstance().getGame().join(event.getPlayer()); } else if (teleportToExit) { - if (event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld().getName()) || event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getLobby().getWorld().getName())) { + if (event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld()) || event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getLobby().getWorld().getName())) { event.getPlayer().teleport(exitPosition); event.getPlayer().setGameMode(GameMode.ADVENTURE); } } else { - if (mapSaveEnabled && event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld().getName())) { + if (mapSaveEnabled && event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld())) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY && Main.getInstance().getGame().getStatus() != Status.ENDING) { Main.getInstance().getGame().join(event.getPlayer()); } else { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/MovementHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/MovementHandler.java index 966f581..2558763 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/MovementHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/MovementHandler.java @@ -49,8 +49,8 @@ public class MovementHandler implements Listener { private void checkBounds(PlayerMoveEvent event){ if (!Main.getInstance().getBoard().contains(event.getPlayer())) return; - if (!event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld().getName())) return; - if (!event.getTo().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld().getName())) return; + if (!event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld())) return; + if (!event.getTo().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld())) return; if (event.getPlayer().hasPermission("hideandseek.leavebounds")) return; Map map = Main.getInstance().getGame().getCurrentMap(); if (event.getTo().getBlockX() < map.getBoundsMin().getBlockX() || event.getTo().getBlockX() > map.getBoundsMax().getBlockX() || event.getTo().getBlockZ() < map.getBoundsMin().getZ() || event.getTo().getBlockZ() > map.getBoundsMax().getZ()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java index 2dda402..3b0f1b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java @@ -30,6 +30,7 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; +import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.permissionsRequired; @@ -65,6 +66,10 @@ public class CommandHandler { registerCommand(new Top()); registerCommand(new Wins()); registerCommand(new Debug()); + registerCommand(new AddMap()); + registerCommand(new RemoveMap()); + registerCommand(new ListMaps()); + registerCommand(new SetMap()); } public static boolean handleCommand(CommandSender sender, String[] args) { @@ -85,8 +90,15 @@ public class CommandHandler { } else if (permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) { sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { + try { - COMMAND_REGISTER.get(args[0].toLowerCase()).execute(player,Arrays.copyOfRange(args, 1, args.length)); + ICommand command = COMMAND_REGISTER.get(args[0].toLowerCase()); + int parameters = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); + if(args.length - 1 < parameters) { + sender.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); + return true; + } + command.execute(player,Arrays.copyOfRange(args, 1, args.length)); } catch (Exception e) { sender.sendMessage(errorPrefix + "An error has occurred."); e.printStackTrace(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java index 2605e7b..28154d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java @@ -19,6 +19,7 @@ package net.tylermurphy.hideAndSeek.util; +import net.tylermurphy.hideAndSeek.command.ICommand; import org.bukkit.command.CommandSender; import java.util.ArrayList; @@ -36,21 +37,20 @@ public class TabCompleter { .collect(Collectors.toList()); } else if (args.length > 1) { if (!CommandHandler.COMMAND_REGISTER.containsKey(args[0].toLowerCase())) { - return null; + return new ArrayList<>(); } else { - String[] usage = CommandHandler.COMMAND_REGISTER.get(args[0].toLowerCase()).getUsage().split(" "); + ICommand command = CommandHandler.COMMAND_REGISTER.get(args[0].toLowerCase()); + String[] usage = command.getUsage().split(" "); + List complete; if (args.length - 2 < usage.length) { String parameter = usage[args.length-2]; - if (parameter.equals("")) { - return null; - } else { - List temp = new ArrayList<>(); - temp.add(parameter.replace("<", "").replace(">", "")); - return temp; - } + String name = parameter.replace("<", "").replace(">", ""); + complete = command.autoComplete(name); } else { - return null; + complete = command.autoComplete(null); } + if(complete == null) return new ArrayList<>(); + else return complete; } } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index b4d5798..322519a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -33,45 +33,35 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class WorldLoader { - private Map map; - private String mapName; - private String saveName; + private final Map map; public WorldLoader(Map map) { this.map = map; - this.mapName = map.getSpawn() == null ? "world" : map.getSpawn().getWorld().getName(); - this.saveName = "hideandseek_"+ mapName; - } - - public void setNewMap(Map map){ - this.map = map; - this.mapName = map.getSpawn() == null ? "world" : map.getSpawn().getWorld().getName(); - this.saveName = "hideandseek_"+ mapName; } public World getWorld() { - return Bukkit.getServer().getWorld(saveName); + return Bukkit.getServer().getWorld(map.getGameSpawnName()); } public void unloadMap() { - World world = Bukkit.getServer().getWorld(saveName); + World world = Bukkit.getServer().getWorld(map.getGameSpawnName()); if (world == null) { - Main.getInstance().getLogger().warning(saveName + " already unloaded."); + Main.getInstance().getLogger().warning(map.getGameSpawnName() + " already unloaded."); return; } world.getPlayers().forEach(player -> player.teleport(exitPosition)); if (Bukkit.getServer().unloadWorld(world, false)) { - Main.getInstance().getLogger().info("Successfully unloaded " + saveName); + Main.getInstance().getLogger().info("Successfully unloaded " + map.getGameSpawnName()); }else{ - Main.getInstance().getLogger().severe("COULD NOT UNLOAD " + saveName); + Main.getInstance().getLogger().severe("COULD NOT UNLOAD " + map.getGameSpawnName()); } } public void loadMap() { - Bukkit.getServer().createWorld(new WorldCreator(saveName).generator(new VoidGenerator())); - World world = Bukkit.getServer().getWorld(saveName); + Bukkit.getServer().createWorld(new WorldCreator(map.getGameSpawnName()).generator(new VoidGenerator())); + World world = Bukkit.getServer().getWorld(map.getGameSpawnName()); if (world == null) { - Main.getInstance().getLogger().severe("COULD NOT LOAD " + saveName); + Main.getInstance().getLogger().severe("COULD NOT LOAD " + map.getGameSpawnName()); return; } world.setAutoSave(false); @@ -83,15 +73,15 @@ public class WorldLoader { } public String save() { - World world = Bukkit.getServer().getWorld(mapName); + World world = Bukkit.getServer().getWorld(map.getSpawnName()); if(world == null){ - throw new RuntimeException("Invalid world to save: " + mapName); + return errorPrefix + "Invalid world to save: " + map.getSpawnName(); } - File current = new File(Main.getInstance().getWorldContainer()+File.separator+ mapName); + File current = new File(Main.getInstance().getWorldContainer()+File.separator+ map.getSpawnName()); if (current.exists()) { try { - File destination = new File(Main.getInstance().getWorldContainer()+File.separator+ saveName); - File temp_destination = new File(Main.getInstance().getWorldContainer()+File.separator+"temp_"+ saveName); + File destination = new File(Main.getInstance().getWorldContainer()+File.separator+ map.getGameSpawnName()); + File temp_destination = new File(Main.getInstance().getWorldContainer()+File.separator+"temp_"+ map.getGameSpawnName()); copyFileFolder("region",true); copyFileFolder("entities",true); copyFileFolder("datapacks",false); @@ -104,7 +94,7 @@ public class WorldLoader { } if (!temp_destination.renameTo(destination)) { - throw new RuntimeException("Failed to rename directory: "+temp_destination.getPath()); + return errorPrefix + "Failed to rename directory: " + temp_destination.getPath(); } } catch(IOException e) { e.printStackTrace(); @@ -117,8 +107,8 @@ public class WorldLoader { } private void copyFileFolder(String name, Boolean isMca) throws IOException { - File region = new File(Main.getInstance().getWorldContainer()+File.separator+ mapName +File.separator+name); - File temp = new File(Main.getInstance().getWorldContainer()+File.separator+"temp_"+ saveName +File.separator+name); + File region = new File(Main.getInstance().getWorldContainer()+File.separator+ map.getSpawnName() +File.separator+name); + File temp = new File(Main.getInstance().getWorldContainer()+File.separator+"temp_"+ map.getGameSpawnName() +File.separator+name); if (region.exists() && region.isDirectory()) { if (!temp.exists()) if (!temp.mkdirs()) diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index f03d188..91d7abe 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -17,7 +17,7 @@ Localization: GAME_GAMEOVER_SEEKERS_QUIT: "All seekers have quit." GAME_GAMEOVER_HIDERS_QUIT: "All hiders have quit." GAME_GAMEOVER_TIME: "Seekers ran out of time. Hiders win!" - GAME_SETUP: "Game is not setup. Run /hs setup to see what you need to do." + GAME_SETUP: "There are no setup maps! Run /hs setup on a map to see what you need to do." GAME_INGAME: "You are already in the lobby/game." GAME_NOT_INGAME: "You are not in a lobby/game." GAME_INPROGRESS: "There is currently a game in progress." @@ -77,6 +77,19 @@ Localization: FLYING_ENABLED: "&l&bFlying Enabled" FLYING_DISABLED: "&l&bFlying Disabled" RESPAWN_NOTICE: "You will respawn in {AMOUNT} seconds." + INVALID_MAP: "That is an invalid map name!!" + MAP_ALREADY_EXISTS: "This map already exists!" + INVALID_MAP_NAME: "A map name can only contain numbers or letters" + MAP_CREATED: "Created new map: {AMOUNT}" + MAP_FAIL_DELETE: "Failed to delete map: {AMOUNT}" + MAP_DELETED: "Deleted map: {AMOUNT}" + NO_MAPS: "There are no maps in the plugin rn (/hs addmap)" + MAP_NOT_SETUP: "Map {AMOUNT} is not setup (/hs setup )" + LIST_MAPS: "The current maps are:" + ARGUMENT_COUNT: "This command requires more arguments to run." + GAME_SPAWN_NEEDED: "Game spawn must be set before seeker spawn." + SEEKER_LOBBY_SPAWN_RESET: "Seeker lobby spawn reset since the game spawn was moved to a new world" + SEEKER_LOBBY_INVALID: "Seeker lobby must be in the same world as game spawn" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 3 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f0d8fe5..49655c7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: KenshinsHideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.6.2 +version: 1.7.0 author: KenshinEto load: STARTUP api-version: 1.13 @@ -34,6 +34,10 @@ permissions: hideandseek.wins: true hideandseek.top: true hideandseek.debug: true + hideandseek.addmap: true + hideandseek.removemap: true + hideandseek.listmaps: true + hideandseek.setmap: true hideandseek.about: description: Allows you to run the about command default: true @@ -91,3 +95,15 @@ permissions: hideandseek.debug: description: Opens the debug menu default: op + hideandseek.addmap: + description: Adds a map to the plugin + default: op + hideandseek.removemap: + description: Removes a map from the plugin + default: op + hideandseek.listmaps: + description: Lists all maps in the plugin + default: op + hideandseek.setmap: + description: Sets the current lobby to a new map + default: op