From 667a365e7b406063617e336798ec95a0e524e2b1 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 30 Oct 2022 15:39:34 -0400 Subject: start adding multi map support --- .../java/net/tylermurphy/hideAndSeek/Main.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Debug.java | 53 ++++-- .../net/tylermurphy/hideAndSeek/command/Join.java | 2 +- .../net/tylermurphy/hideAndSeek/command/Leave.java | 2 +- .../tylermurphy/hideAndSeek/command/SaveMap.java | 18 +- .../tylermurphy/hideAndSeek/command/SetBorder.java | 45 +++-- .../tylermurphy/hideAndSeek/command/SetBounds.java | 55 +++--- .../net/tylermurphy/hideAndSeek/command/Setup.java | 21 ++- .../net/tylermurphy/hideAndSeek/command/Start.java | 2 +- .../net/tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../command/location/SetExitLocation.java | 9 +- .../command/location/SetLobbyLocation.java | 5 +- .../command/location/SetSeekerLobbyLocation.java | 5 +- .../command/location/SetSpawnLocation.java | 20 +-- .../command/location/util/LocationUtils.java | 46 ++--- .../hideAndSeek/configuration/Config.java | 100 ++--------- .../hideAndSeek/configuration/ConfigManager.java | 18 +- .../tylermurphy/hideAndSeek/configuration/Map.java | 196 +++++++++++++++++++++ .../hideAndSeek/configuration/Maps.java | 136 ++++++++++++++ .../net/tylermurphy/hideAndSeek/game/Board.java | 5 +- .../tylermurphy/hideAndSeek/game/Disguiser.java | 12 +- .../net/tylermurphy/hideAndSeek/game/Game.java | 74 ++++---- .../tylermurphy/hideAndSeek/game/PlayerLoader.java | 34 ++-- .../hideAndSeek/game/events/Border.java | 43 +++-- .../hideAndSeek/game/listener/DamageHandler.java | 16 +- .../hideAndSeek/game/listener/InteractHandler.java | 2 +- .../game/listener/InventoryHandler.java | 28 ++- .../game/listener/JoinLeaveHandler.java | 14 +- .../hideAndSeek/game/listener/MovementHandler.java | 11 +- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 25 +-- src/main/resources/config.yml | 44 +---- src/main/resources/maps.yml | 1 + 32 files changed, 653 insertions(+), 395 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java create mode 100644 src/main/resources/maps.yml diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 4d8581f..0e890c6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -39,6 +39,7 @@ import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.List; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -90,7 +91,8 @@ public class Main extends JavaPlugin implements Listener { board.getPlayers().forEach(player -> { board.removeBoard(player); PlayerLoader.unloadPlayer(player); - player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + if(!Objects.equals(exitWorld, "")) + player.teleport(exitPosition); }); Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java index 61d0c46..2ca998e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java @@ -2,11 +2,10 @@ package net.tylermurphy.hideAndSeek.command; import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.PlayerLoader; import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -18,7 +17,7 @@ import java.util.Map; import java.util.function.Consumer; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Debug implements ICommand { @@ -26,41 +25,43 @@ public class Debug implements ICommand { private Inventory debugMenu; public void execute(Player sender, String[] args) { - if(debugMenu == null) createMenu(); + if(args.length < 1) args = new String[]{""}; + if(debugMenu == null) createMenu(args[0]); sender.openInventory(debugMenu); } - private void createMenu(){ + 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 -> { if(mapSaveEnabled) { - if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap(); + if(Main.getInstance().getGame().getCurrentMap().getSpawn().getWorld() == null) Main.getInstance().getGame().getCurrentMap().getWorldLoader().loadMap(); } Main.getInstance().getBoard().addHider(player); - PlayerLoader.loadHider(player, Main.getInstance().getGame().getGameWorld()); + PlayerLoader.loadHider(player, Main.getInstance().getGame().getCurrentMap()); 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 -> { if(mapSaveEnabled) { - if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap(); + if(Main.getInstance().getGame().getCurrentMap().getSpawn().getWorld() == null) Main.getInstance().getGame().getCurrentMap().getWorldLoader().loadMap(); } Main.getInstance().getBoard().addSeeker(player); - PlayerLoader.loadSeeker(player, Main.getInstance().getGame().getGameWorld()); + PlayerLoader.loadSeeker(player, Main.getInstance().getGame().getCurrentMap()); 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 -> { if(mapSaveEnabled) { - if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap(); + if(Main.getInstance().getGame().getCurrentMap().getSpawn().getWorld() == null) Main.getInstance().getGame().getCurrentMap().getWorldLoader().loadMap(); } Main.getInstance().getBoard().addSpectator(player); - PlayerLoader.loadSpectator(player, Main.getInstance().getGame().getGameWorld()); + PlayerLoader.loadSpectator(player, Main.getInstance().getGame().getCurrentMap()); })); debugMenu.setItem(3, createOption(3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> { Main.getInstance().getBoard().remove(player); PlayerLoader.unloadPlayer(player); - player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + player.teleport(exitPosition); })); debugMenu.setItem(4, createOption(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){ @@ -68,14 +69,30 @@ public class Debug implements ICommand { } })); debugMenu.setItem(6, createOption(6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { + if(map == null) { + player.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } if(mapSaveEnabled) { - if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap(); + if(map.getSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + player.teleport(map.getSpawn()); + })); + debugMenu.setItem(7, createOption(7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { + if(map == null) { + player.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + 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; } - player.teleport(new Location(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + PlayerLoader.openBlockHuntPicker(player, map); })); - debugMenu.setItem(7, createOption(7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(), lobbyPosition.getY(), lobbyPosition.getZ())))); - debugMenu.setItem(8, createOption(8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())))); - debugMenu.setItem(9, createOption(9, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, PlayerLoader::openBlockHuntPicker)); debugMenu.setItem(10, createOption(10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); } @@ -100,7 +117,7 @@ public class Debug implements ICommand { } public String getUsage() { - return ""; + return "<*map>"; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 941cec0..cf8944e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -29,7 +29,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Join implements ICommand { public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().isNotSetup()) { + if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index 092ff50..fee7ca8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -29,7 +29,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Leave implements ICommand { public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().isNotSetup()) { + if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index 1e66395..4758666 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -20,8 +20,9 @@ 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.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -42,21 +43,26 @@ public class SaveMap implements ICommand { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } sender.sendMessage(messagePrefix + message("MAPSAVE_START")); sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); - World world = Bukkit.getServer().getWorld(spawnWorld); + World world = map.getSpawn().getWorld(); if (world == null) { - throw new RuntimeException("Unable to get world: " + spawnWorld); + throw new RuntimeException("Unable to get spawn world"); } world.save(); BukkitRunnable runnable = new BukkitRunnable() { public void run() { sender.sendMessage( - Main.getInstance().getGame().getWorldLoader().save() + map.getWorldLoader().save() ); runningBackup = false; } @@ -70,7 +76,7 @@ public class SaveMap implements ICommand { } public String getUsage() { - return ""; + return ""; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index b456e6a..08a8c87 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -20,6 +20,8 @@ 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 org.bukkit.util.Vector; @@ -34,16 +36,21 @@ public class SetBorder implements ICommand { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - if (spawnPosition == null) { + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } if (args.length < 3) { - worldBorderEnabled = false; + map.setWorldBorderData(0, 0, 0, 0, 0); addToConfig("worldBorder.enabled",false); saveConfig(); sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); - Main.getInstance().getGame().getBorder().resetWorldBorder(spawnWorld); + Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); return; } int num,delay,change; @@ -67,28 +74,16 @@ public class SetBorder implements ICommand { sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); return; } - Vector vec = new Vector(); - vec.setX(sender.getLocation().getBlockX()); - vec.setY(0); - vec.setZ(sender.getLocation().getBlockZ()); - if (spawnPosition.distance(vec) > 100) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); - return; - } - worldBorderPosition = vec; - worldBorderSize = num; - worldBorderDelay = delay; - worldBorderChange = change; - worldBorderEnabled = true; - addToConfig("worldBorder.x", worldBorderPosition.getBlockX()); - addToConfig("worldBorder.z", worldBorderPosition.getBlockZ()); - addToConfig("worldBorder.delay", worldBorderDelay); - addToConfig("worldBorder.size", worldBorderSize); - addToConfig("worldBorder.enabled", true); - addToConfig("worldBorder.move", worldBorderChange); + map.setWorldBorderData( + sender.getLocation().getBlockX(), + sender.getLocation().getBlockZ(), + num, + delay, + change + ); + Maps.setMap(map.getName(), map); sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); - saveConfig(); - Main.getInstance().getGame().getBorder().resetWorldBorder(spawnWorld); + map.getWorldBorder().resetWorldBorder(); } public String getLabel() { @@ -96,7 +91,7 @@ public class SetBorder implements ICommand { } public String getUsage() { - return " "; + return " "; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index 434e4a6..c22e3a6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -20,6 +20,8 @@ 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; @@ -33,11 +35,16 @@ public class SetBounds implements ICommand { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - if (spawnPosition == null) { + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } - if (!sender.getWorld().getName().equals(spawnWorld)) { + if (!sender.getWorld().getName().equals(map.getSpawn().getWorld().getName())) { sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); return; } @@ -46,37 +53,35 @@ public class SetBounds implements ICommand { return; } boolean first = true; - if (saveMinX != 0 && saveMinZ != 0 && saveMaxX != 0 && saveMaxZ != 0) { - saveMinX = 0; saveMinZ= 0; saveMaxX = 0; saveMaxZ = 0; + int bxs = map.getBoundsMin().getBlockX(); + int bzs = map.getBoundsMin().getBlockZ(); + int bxl = map.getBoundsMax().getBlockX(); + int bzl = map.getBoundsMax().getBlockZ(); + if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { + bxs = bzs = bxl = bzl = 0; } - if (saveMaxX == 0) { - addToConfig("bounds.max.x", sender.getLocation().getBlockX()); - saveMaxX = sender.getLocation().getBlockX(); - } else if (saveMaxX < sender.getLocation().getBlockX()) { + if (bxl == 0) { + bxl = sender.getLocation().getBlockX(); + } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { first = false; - addToConfig("bounds.max.x", sender.getLocation().getBlockX()); - addToConfig("bounds.min.x", saveMaxX); - saveMinX = saveMaxX; - saveMaxX = sender.getLocation().getBlockX(); + bxs = bxl; + bxl = sender.getLocation().getBlockX(); } else { first = false; - addToConfig("bounds.min.x", sender.getLocation().getBlockX()); - saveMinX = sender.getLocation().getBlockX(); + bxs = sender.getLocation().getBlockX(); } - if (saveMaxZ == 0) { - addToConfig("bounds.max.z", sender.getLocation().getBlockZ()); - saveMaxZ = sender.getLocation().getBlockZ(); - } else if (saveMaxZ < sender.getLocation().getBlockZ()) { + if (bzl == 0) { + bzl = sender.getLocation().getBlockZ(); + } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockZ()) { first = false; - addToConfig("bounds.max.z", sender.getLocation().getBlockZ()); - addToConfig("bounds.min.z", saveMaxZ); - saveMinZ = saveMaxZ; - saveMaxZ = sender.getLocation().getBlockZ(); + bzs = bzl; + bzl = sender.getLocation().getBlockZ(); } else { first = false; - addToConfig("bounds.min.z", sender.getLocation().getBlockZ()); - saveMinZ = sender.getLocation().getBlockZ(); + bzs = sender.getLocation().getBlockZ(); } + map.setBoundMin(bxs, bzs); + map.setBoundMax(bxl, bzl); sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); saveConfig(); } @@ -86,7 +91,7 @@ public class SetBounds implements ICommand { } public String getUsage() { - return ""; + return ""; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index e961188..ef052aa 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -20,6 +20,8 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; import java.io.File; @@ -33,16 +35,20 @@ public class Setup implements ICommand { String msg = message("SETUP").toString(); int count = 0; - - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0) { msg = msg + "\n" + message("SETUP_GAME"); count++; } - if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) { + if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0) { msg = msg + "\n" + message("SETUP_LOBBY"); count++; } - if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0) { + if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0) { msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); count++; } @@ -50,12 +56,13 @@ public class Setup implements ICommand { msg = msg + "\n" + message("SETUP_EXIT"); count++; } - if (saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) { + if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || + map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { msg = msg + "\n" + message("SETUP_BOUNDS"); count++; } if (mapSaveEnabled) { - File destenation = new File(Main.getInstance().getWorldContainer() + File.separator + Main.getInstance().getGame().getGameWorld()); + File destenation = new File(Main.getInstance().getWorldContainer() + File.separator + map.getSpawn().getWorld().getName()); if (!destenation.exists()) { msg = msg + "\n" + message("SETUP_SAVEMAP"); count++; @@ -73,7 +80,7 @@ public class Setup implements ICommand { } public String getUsage() { - return ""; + return ""; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 18bcbba..2d847d5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -34,7 +34,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().isNotSetup()) { + if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 9280b53..22ab3fb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -30,7 +30,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().isNotSetup()) { + if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } 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 93c0d8c..a616297 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -28,9 +28,14 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetExitLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.EXIT, vector -> { + LocationUtils.setLocation(sender, Locations.EXIT, args[0], map -> { + addToConfig("exit.x", sender.getLocation().getBlockX()); + addToConfig("exit.y", sender.getLocation().getBlockY()); + addToConfig("exit.z", sender.getLocation().getBlockZ()); + addToConfig("exit.world", sender.getLocation().getWorld().getName()); + exitPosition = sender.getLocation(); exitWorld = sender.getLocation().getWorld().getName(); - exitPosition = vector; + saveConfig(); }); } 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 eb228f9..4eb5462 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -29,9 +29,8 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetLobbyLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.LOBBY, vector -> { - lobbyWorld = sender.getLocation().getWorld().getName(); - lobbyPosition = vector; + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); }); } 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 c6c3ccb..59bec64 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java @@ -10,9 +10,8 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetSeekerLobbyLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.SEEKER, vector -> { - seekerLobbyWorld = sender.getLocation().getWorld().getName(); - seekerLobbyPosition = vector; + LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { + map.setSeekerLobby(sender.getLocation()); }); } 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 5ecfb8d..12ac232 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -19,11 +19,11 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.ICommand; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -31,19 +31,19 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetSpawnLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.GAME, vector -> { - if (worldBorderEnabled && vector.distance(worldBorderPosition) > 100) { + LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { + + if (map.isWorldBorderEnabled() && + new Vector(sender.getLocation().getX(), 0, sender.getLocation().getZ()).distance(map.getWorldBorderPos()) > 100) { sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); throw new RuntimeException("World border not enabled or not in valid position!"); } - if (!sender.getLocation().getWorld().getName().equals(spawnWorld)) { - Main.getInstance().getGame().getWorldLoader().unloadMap(); - Main.getInstance().getGame().getWorldLoader().setNewMap(sender.getLocation().getWorld().getName()); - } + map.setSpawn(sender.getLocation()); - spawnWorld = sender.getLocation().getWorld().getName(); - spawnPosition = vector; + if (!sender.getLocation().getWorld().getName().equals(map.getSpawn().getWorld().getName()) && mapSaveEnabled) { + map.getWorldLoader().unloadMap(); + } }); } @@ -52,7 +52,7 @@ public class SetSpawnLocation implements ICommand { } public String getUsage() { - return ""; + return ""; } public String getDescription() { 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 50d1776..2655805 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 @@ -1,12 +1,11 @@ package net.tylermurphy.hideAndSeek.command.location.util; 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.Location; -import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; @@ -18,42 +17,31 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; */ public class LocationUtils { - /** - * Provides a vector for a player - * @param player the player to create the vector for - * @return the vector - */ - private static @Nullable Vector vector(Player player) { + public static void setLocation(@NotNull Player player, @NotNull Locations place, String mapName, @NotNull Consumer consumer) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { player.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return null; + return; } if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ player.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return null; + return; } - Location loc = player.getLocation(); - return new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - } - - public static void setLocation(Player player, Locations place, @Nullable Consumer consumer) { - Vector vec = vector(player); - - World world = player.getLocation().getWorld(); - if(world == null) { - throw new RuntimeException("Unable to get world: " + spawnWorld); + Map map = null; + if(mapName != null) { + map = Maps.getMap(mapName); + if (map == null) { + player.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } } - consumer.accept(vec); - + consumer.accept(map); + if(map != null) + Maps.setMap(mapName, map); player.sendMessage(messagePrefix + message(place.message())); - addToConfig(place.path("x"), vec.getX()); - addToConfig(place.path("y"), vec.getY()); - addToConfig(place.path("z"), vec.getZ()); - addToConfig(place.path("world"), player.getLocation().getWorld().getName()); - saveConfig(); } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index a71369f..3a43e15 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -24,12 +24,13 @@ import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XSound; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.CountdownDisplay; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -49,10 +50,6 @@ public class Config { abortPrefix, gameOverPrefix, warningPrefix, - spawnWorld, - seekerLobbyWorld, - exitWorld, - lobbyWorld, locale, leaveServer, placeholderError, @@ -62,20 +59,13 @@ public class Config { databasePort, databaseUser, databasePass, - databaseName; - - public static Vector - spawnPosition, - lobbyPosition, - exitPosition, - seekerLobbyPosition, - worldBorderPosition; + databaseName, + exitWorld; public static boolean nameTagsVisible, permissionsRequired, announceMessagesToNonPlayers, - worldBorderEnabled, tauntEnabled, tauntCountdown, tauntLast, @@ -93,20 +83,11 @@ public class Config { mapSaveEnabled, allowNaturalCauses, saveInventory, - blockhuntEnabled, delayedRespawn; public static int minPlayers, - worldBorderSize, - worldBorderDelay, - currentWorldborderSize, - worldBorderChange, gameLength, - saveMinX, - saveMinZ, - saveMaxX, - saveMaxZ, tauntDelay, glowLength, countdown, @@ -132,9 +113,6 @@ public class Config { blockedCommands, blockedInteracts; - public static List - blockhuntBlocks; - public static String LOBBY_TITLE, GAME_TITLE, @@ -166,6 +144,9 @@ public class Config { public static CountdownDisplay countdownDisplay; + + public static Location + exitPosition; public static void loadConfig() { @@ -173,50 +154,8 @@ public class Config { config.saveConfig(); ConfigManager leaderboard = ConfigManager.create("leaderboard.yml"); - //Spawn - spawnPosition = new Vector( - config.getDouble("spawns.game.x"), - Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.game.y"))), - config.getDouble("spawns.game.z") - ); - spawnWorld = config.getString("spawns.game.world"); - - ///Lobby - lobbyPosition = new Vector( - config.getDouble("spawns.lobby.x"), - Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.lobby.y"))), - config.getDouble("spawns.lobby.z") - ); - lobbyWorld = config.getString("spawns.lobby.world"); - - ///Seeker Lobby - seekerLobbyPosition = new Vector( - config.getDouble("spawns.seeker.x"), - Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.seeker.y"))), - config.getDouble("spawns.seeker.z") - ); - seekerLobbyWorld = config.getString("spawns.seeker.world"); - announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers"); - exitPosition = new Vector( - config.getDouble("spawns.exit.x"), - Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.exit.y"))), - config.getDouble("spawns.exit.z") - ); - exitWorld = config.getString("spawns.exit.world"); - - //World border - worldBorderPosition = new Vector( - config.getInt("worldBorder.x"), - 0, - config.getInt("worldBorder.z") - ); - worldBorderSize = Math.max(100, config.getInt("worldBorder.size")); - worldBorderDelay = Math.max(1, config.getInt("worldBorder.delay")); - worldBorderEnabled = config.getBoolean("worldBorder.enabled"); - worldBorderChange = config.getInt("worldBorder.moveAmount"); - //Prefix char SYMBOLE = '\u00A7'; String SYMBOLE_STRING = String.valueOf(SYMBOLE); @@ -229,11 +168,14 @@ public class Config { gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOLE_STRING); warningPrefix = config.getString("prefix.warning").replace("&", SYMBOLE_STRING); - //Map Bounds - saveMinX = config.getInt("bounds.min.x"); - saveMinZ = config.getInt("bounds.min.z"); - saveMaxX = config.getInt("bounds.max.x"); - saveMaxZ = config.getInt("bounds.max.z"); + // Locations + exitPosition = new Location( + Bukkit.getWorld(config.getString("exit.world")), + config.getInt("exit.x"), + config.getInt("exit.y"), + config.getInt("exit.z") + ); + exitWorld = config.getString("exit.world"); mapSaveEnabled = config.getBoolean("mapSaveEnabled"); //Taunt @@ -305,18 +247,6 @@ public class Config { } bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy"); leaveServer = config.getString("leaveServer"); - blockhuntEnabled = config.getBoolean("blockhunt.enabled") && Main.getInstance().supports(9); - blockhuntBlocks = new ArrayList<>(); - tempInteracts = config.getStringList("blockhunt.blocks"); - for(String id : tempInteracts) { - Optional optional_mat = XMaterial.matchXMaterial(id); - if (optional_mat.isPresent()) { - Material mat = optional_mat.get().parseMaterial(); - if (mat != null) { - blockhuntBlocks.add(mat); - } - } - } solidifyTime = Math.max(20,config.getInt("blockhunt.solidifyTime")); //Leaderboard diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 5e28258..e09001e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -25,8 +25,8 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import java.io.*; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.List; import java.util.Map; @@ -188,6 +188,10 @@ public class ConfigManager { config.set(path, defaultConfig.get(path)); } + public void resetAll() { + config = new YamlConfiguration(); + } + public void resetFile(String newDefaultFilename) { this.defaultFilename = newDefaultFilename; @@ -226,6 +230,14 @@ public class ConfigManager { config.set(path, value); } + public void overwriteConfig() { + try { + this.config.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + public void saveConfig() { try { InputStream is = Main.getInstance().getResource(defaultFilename); @@ -233,7 +245,7 @@ public class ConfigManager { throw new RuntimeException("Could not create input stream for "+defaultFilename); } StringBuilder textBuilder = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); - Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name()))); + Reader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); int c; while((c = reader.read()) != -1) { textBuilder.append((char) c); @@ -285,7 +297,7 @@ public class ConfigManager { yamlString = builder.toString(); } } - Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); + Writer fileWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8)); fileWriter.write(yamlString); fileWriter.close(); } catch (IOException e) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java new file mode 100644 index 0000000..b18a0b0 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -0,0 +1,196 @@ +package net.tylermurphy.hideAndSeek.configuration; + +import java.io.File; +import java.util.List; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.events.Border; +import net.tylermurphy.hideAndSeek.world.VoidGenerator; +import net.tylermurphy.hideAndSeek.world.WorldLoader; +import org.bukkit.*; +import org.bukkit.util.Vector; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class Map { + + private final String name; + + private Location + spawnPosition = new Location(null, 0, 0, 0), + lobbyPosition = new Location(null, 0, 0, 0), + seekerLobbyPosition = new Location(null, 0, 0, 0); + + private String + gameWorldName; + + private int + xBoundMin = 0, + zBoundMin = 0, + xBoundMax = 0, + zBoundMax = 0, + xWorldBorder = 0, + zWorldBorder = 0, + worldBorderSize = 0, + worldBorderDelay = 0, + worldBorderChange = 0; + + private boolean + blockhunt; + + private List + blockhuntBlocks; + + private final Border + worldBorder; + + private final WorldLoader + worldLoader; + + public Map(String name) { + this.name = name; + this.worldBorder = new Border(this); + this.worldLoader = new WorldLoader(this); + } + + public void setSpawn(Location pos) { + this.spawnPosition = pos; + this.gameWorldName = pos.getWorld().getName(); + } + + public void setLobby(Location pos) { + this.lobbyPosition = pos; + } + + public void setSeekerLobby(Location pos) { + this.seekerLobbyPosition = pos; + } + + public void setWorldBorderData(int x, int z, int size, int delay, int move) { + if(size < 1) { + this.worldBorderSize = 0; + this.worldBorderDelay = 0; + this.worldBorderChange = 0; + this.xWorldBorder = 0; + this.zWorldBorder = 0; + this.worldBorder.resetWorldBorder(); + } else { + this.worldBorderSize = size; + this.worldBorderDelay = delay; + this.worldBorderChange = move; + this.xWorldBorder = x; + this.zWorldBorder = z; + } + } + + public void setBlockhunt(boolean enabled, List blocks) { + this.blockhunt = enabled; + this.blockhuntBlocks = blocks; + } + + public void setBoundMin(int x, int z) { + this.xBoundMin = x; + this.zBoundMin = z; + } + + public void setBoundMax(int x, int z) { + this.xBoundMax = x; + this.zBoundMax = z; + } + + public Location getSpawn() { + if(mapSaveEnabled) + spawnPosition.setWorld(Bukkit.getWorld("hs_"+gameWorldName)); + else + spawnPosition.setWorld(Bukkit.getWorld(gameWorldName)); + return spawnPosition; + } + + public Location getLobby() { + return lobbyPosition; + } + + public Location getSeekerLobby() { + return seekerLobbyPosition; + } + + public boolean isWorldBorderEnabled() { + return worldBorderSize > 0; + } + + public Vector getWorldBorderPos() { + return new Vector( + xWorldBorder, + 0, + zWorldBorder + ); + } + + public Vector getWorldBorderData() { + return new Vector( + worldBorderSize, + worldBorderDelay, + worldBorderChange + ); + } + + public Border getWorldBorder() { + return worldBorder; + } + + public boolean isBlockHuntEnabled() { + return blockhunt; + } + + public List getBlockHunt() { + return blockhuntBlocks; + } + + public Vector getBoundsMin() { + return new Vector( + xBoundMin, + 0, + zBoundMin + ); + } + + public Vector getBoundsMax() { + return new Vector( + xBoundMax, + 0, + zBoundMin + ); + } + + public String getName() { + return name; + } + + public WorldLoader getWorldLoader() { + return worldLoader; + } + + public boolean isNotSetup() { + if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true; + if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true; + if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true; + if (exitPosition.getWorld() == null) { + Bukkit.getServer().createWorld(new WorldCreator(exitWorld).generator(new VoidGenerator())); + World world = Bukkit.getServer().getWorld(exitWorld); + if(world == null) return true; + } + if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0) return true; + if (mapSaveEnabled) { + File destination = new File(Main.getInstance().getWorldContainer() + File.separator + spawnPosition.getWorld().getName()); + if (!destination.exists()) return true; + } + if(isWorldBorderEnabled() && + new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true; + return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; + } + + public boolean isSpawnNotSetup() { + return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java new file mode 100644 index 0000000..736fec2 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -0,0 +1,136 @@ +package net.tylermurphy.hideAndSeek.configuration; + +import java.util.*; +import java.util.stream.Collectors; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; + +import com.cryptomorin.xseries.XMaterial; + +public class Maps { + + private static final HashMap MAPS = new HashMap<>(); + + public static Map getMap(String name) { + return MAPS.get(name); + } + + 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"); + } + + public static void setMap(String name, Map map) { + MAPS.put(name, map); + saveMaps(); + } + + public static Collection getAllMaps() { + return MAPS.values(); + } + + public static void loadMaps() { + + ConfigManager manager = ConfigManager.create("maps.yml"); + + ConfigurationSection maps = manager.getConfigurationSection("maps"); + if(maps == null) return; + Set keys = maps.getKeys(false); + if(keys == null) return; + + MAPS.clear(); + for(String key : keys) { + System.out.println(key); + MAPS.put(key, parseMap(maps, key)); + } + + } + + private static Map parseMap(ConfigurationSection maps, String name) { + ConfigurationSection data = maps.getConfigurationSection(name); + if(data == null) return null; + Map map = new Map(name); + map.setSpawn(setSpawn(data, "game")); + map.setLobby(setSpawn(data, "lobby")); + map.setSeekerLobby(setSpawn(data, "seeker")); + map.setBoundMin(data.getInt("bounds.min.x"), data.getInt("bounds.min.z")); + map.setBoundMax(data.getInt("bounds.max.x"), data.getInt("bounds.max.z")); + map.setWorldBorderData( + data.getInt("worldborder.pos.x"), + data.getInt("worldborder.pos.z"), + data.getInt("worldborder.size"), + data.getInt("worldborder.delay"), + data.getInt("worldborder.change") + ); + map.setBlockhunt( + data.getBoolean("blockhunt.enabled"), + data.getStringList("blockhunt.blocks") + .stream() + .map(XMaterial::matchXMaterial) + .filter(Optional::isPresent) + .map(e -> e.get().parseMaterial()) + .filter(Objects::nonNull) + .collect(Collectors.toList()) + ); + return map; + } + + private static Location setSpawn(ConfigurationSection data, String spawn) { + String worldName = data.getString("spawns."+spawn+".world"); + if(worldName == null) return new Location(null, 0, 0, 0); + World world = Bukkit.getWorld(worldName); + if(world == null) return new Location(null, 0, 0, 0); + double x = data.getDouble("spawns."+spawn+".x"); + double y = data.getDouble("spawns."+spawn+".y"); + double z = data.getDouble("spawns."+spawn+".z"); + return new Location(world, x, y, z); + } + + private static void saveMaps() { + + ConfigManager manager = ConfigManager.create("maps.yml"); + ConfigurationSection maps = new YamlConfiguration(); + + for(Map map : MAPS.values()) { + ConfigurationSection data = new YamlConfiguration(); + saveSpawn(data, map.getSpawn(), "game"); + saveSpawn(data, map.getLobby(), "lobby"); + saveSpawn(data, map.getSeekerLobby(), "seeker"); + data.set("bounds.min.x", map.getBoundsMin().getX()); + data.set("bounds.min.z", map.getBoundsMin().getZ()); + data.set("bounds.max.x", map.getBoundsMax().getX()); + data.set("bounds.max.z", map.getBoundsMax().getZ()); + data.set("worldborder.pos.x", map.getWorldBorderPos().getX()); + data.set("worldborder.pos.z", map.getWorldBorderPos().getZ()); + data.set("worldborder.pos.size", map.getWorldBorderData().getX()); + 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); + } + + manager.set("maps", maps); + manager.overwriteConfig(); + + } + + private static void saveSpawn(ConfigurationSection data, Location spawn, String name) { + if(spawn.getWorld() != null) { + data.set("spawns." + name + ".world", spawn.getWorld().getName()); + } 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()); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 55dfa3c..18cad40 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -35,7 +35,6 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -@SuppressWarnings("deprecation") public class Board { private final List Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); @@ -244,7 +243,7 @@ public class Board { Status status = Main.getInstance().getGame().getStatus(); Taunt taunt = Main.getInstance().getGame().getTaunt(); - Border worldBorder = Main.getInstance().getGame().getBorder(); + Border worldBorder = Main.getInstance().getGame().getCurrentMap().getWorldBorder(); Glow glow = Main.getInstance().getGame().getGlow(); int i = 0; @@ -259,7 +258,7 @@ public class Board { String value = getTeam(player); board.setLine(String.valueOf(i), line.replace("{TEAM}", value)); } else if (line.contains("{BORDER}")) { - if (!worldBorderEnabled) continue; + if (!Main.getInstance().getGame().getCurrentMap().isWorldBorderEnabled()) continue; if (worldBorder == null || status == Status.STARTING) { board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replace("{AMOUNT}", "0"))); } else if (!worldBorder.isRunning()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java index 2f8cbf6..dabb735 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java @@ -2,17 +2,17 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.game.util.Disguise; import org.bukkit.Material; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; import java.util.HashMap; -import java.util.Map; public class Disguiser { - private final Map disguises; + private final HashMap disguises; public Disguiser(){ this.disguises = new HashMap<>(); @@ -35,7 +35,7 @@ public class Disguiser { } public void check(){ - for(Map.Entry set : disguises.entrySet()){ + for(HashMap.Entry set : disguises.entrySet()){ Disguise disguise = set.getValue(); Player player = set.getKey(); if(!player.isOnline()) { @@ -47,9 +47,9 @@ public class Disguiser { } } - public void disguise(Player player, Material material){ - if(!blockhuntEnabled){ - player.sendMessage(errorPrefix + "Please enable blockhunt in config.yml to enable disguises. Blockhunt does not work on 1.8"); + public void disguise(Player player, Material material, Map map){ + if(!map.isBlockHuntEnabled()){ + player.sendMessage(errorPrefix + "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8"); return; } if(disguises.containsKey(player)){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 71c3e84..2f86849 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -24,18 +24,17 @@ import com.cryptomorin.xseries.messages.Titles; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.game.events.Border; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.events.Glow; import net.tylermurphy.hideAndSeek.game.events.Taunt; import net.tylermurphy.hideAndSeek.game.listener.RespawnHandler; import net.tylermurphy.hideAndSeek.game.util.*; -import net.tylermurphy.hideAndSeek.world.WorldLoader; import org.bukkit.*; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.io.File; import java.util.*; import java.util.stream.Collectors; @@ -46,24 +45,25 @@ public class Game { private final Taunt taunt; private final Glow glow; - private final Border worldBorder; - private final WorldLoader worldLoader; private final Board board; private Status status; + private Map currentMap; + private int gameTick; private int lobbyTimer; private int startingTimer; private int gameTimer; private boolean hiderLeft; - public Game(Board board){ + public Game(Board board) { + + this.currentMap = Maps.getRandomMap(); + this.taunt = new Taunt(); this.glow = new Glow(); - this.worldBorder = new Border(); - this.worldLoader = new WorldLoader(spawnWorld); this.status = Status.STANDBY; @@ -92,18 +92,10 @@ public class Game { return glow; } - public Border getBorder(){ - return worldBorder; - } - public Taunt getTaunt(){ return taunt; } - public WorldLoader getWorldLoader(){ - return worldLoader; - } - public void start() { try { Optional rand = board.getPlayers().stream().skip(new Random().nextInt(board.size())).findFirst(); @@ -115,17 +107,17 @@ public class Game { } public void start(Player seeker) { - if (mapSaveEnabled) worldLoader.rollback(); + if (mapSaveEnabled) currentMap.getWorldLoader().rollback(); board.reload(); board.addSeeker(seeker); - PlayerLoader.loadSeeker(seeker, getGameWorld()); + PlayerLoader.loadSeeker(seeker, currentMap); board.getPlayers().forEach(player -> { if(board.isSeeker(player)) return; board.addHider(player); - PlayerLoader.loadHider(player, getGameWorld()); + PlayerLoader.loadHider(player, currentMap); }); board.getPlayers().forEach(board::createGameBoard); - worldBorder.resetWorldBorder(getGameWorld()); + currentMap.getWorldBorder().resetWorldBorder(); if (gameLength > 0) gameTimer = gameLength; status = Status.STARTING; startingTimer = 30; @@ -147,21 +139,21 @@ public class Game { public void end() { board.getPlayers().forEach(PlayerLoader::unloadPlayer); - worldBorder.resetWorldBorder(getGameWorld()); + currentMap.getWorldBorder().resetWorldBorder(); board.getPlayers().forEach(player -> { if (leaveOnEnd) { board.removeBoard(player); board.remove(player); handleBungeeLeave(player); } else { - player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + player.teleport(currentMap.getLobby()); board.createLobbyBoard(player); board.addHider(player); - PlayerLoader.joinPlayer(player); + PlayerLoader.joinPlayer(player, currentMap); } }); RespawnHandler.temp_loc.clear(); - if (mapSaveEnabled) worldLoader.unloadMap(); + if (mapSaveEnabled) currentMap.getWorldLoader().unloadMap(); board.reloadLobbyBoards(); status = Status.ENDED; } @@ -172,14 +164,14 @@ public class Game { ItemStack[] data = player.getInventory().getContents(); Main.getInstance().getDatabase().getInventoryData().saveInventory(player.getUniqueId(), data); } - PlayerLoader.joinPlayer(player); + PlayerLoader.joinPlayer(player, currentMap); board.addHider(player); board.createLobbyBoard(player); board.reloadLobbyBoards(); if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); else broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); } else { - PlayerLoader.loadSpectator(player, getGameWorld()); + PlayerLoader.loadSpectator(player, currentMap); board.addSpectator(player); board.createGameBoard(player); player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); @@ -216,12 +208,12 @@ public class Game { out.writeUTF(leaveServer); player.sendPluginMessage(Main.getInstance(), "BungeeCord", out.toByteArray()); } else { - player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + player.teleport(exitPosition); } } public void onTick() { - if (isNotSetup()) return; + if (currentMap.isNotSetup()) return; if (status == Status.STANDBY) whileWaiting(); else if (status == Status.STARTING) whileStarting(); else if (status == Status.PLAYING) whilePlaying(); @@ -257,7 +249,7 @@ public class Game { board.getPlayers().forEach(player -> { PlayerLoader.resetPlayer(player, board); if(board.isSeeker(player)){ - player.teleport(new Location(Bukkit.getWorld(getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + player.teleport(currentMap.getSpawn()); } }); } else if (startingTimer == 1){ @@ -317,7 +309,7 @@ public class Game { board.reloadGameBoards(); gameTimer--; } - if (worldBorderEnabled) worldBorder.update(); + if (currentMap.isWorldBorderEnabled()) currentMap.getWorldBorder().update(); if (tauntEnabled) taunt.update(); if (glowEnabled || alwaysGlow) glow.update(); } @@ -331,21 +323,17 @@ public class Game { } } - public boolean isNotSetup() { - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true; - if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true; - if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true; - if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0) return true; - if (mapSaveEnabled) { - File destination = new File(Main.getInstance().getWorldContainer() + File.separator + getGameWorld()); - if (!destination.exists()) return true; - } - return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0; + public Map getCurrentMap() { + return currentMap; + } + + public void setCurrentMap(Map map) { + this.currentMap = map; } - public String getGameWorld() { - if (mapSaveEnabled) return "hideandseek_"+spawnWorld; - else return spawnWorld; + public World getGameWorld() { + if(currentMap == null || currentMap.getSpawn() == null) return null; + else return currentMap.getSpawn().getWorld(); } 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 eedfabe..83f4eee 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/PlayerLoader.java @@ -23,9 +23,8 @@ import com.cryptomorin.xseries.messages.Titles; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Items; -import org.bukkit.Bukkit; +import net.tylermurphy.hideAndSeek.configuration.Map; import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Player; @@ -35,30 +34,29 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.lobbyPosition; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @SuppressWarnings("deprecation") public class PlayerLoader { - public static void loadHider(Player player, String gameWorld){ - player.teleport(new Location(Bukkit.getWorld(gameWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + public static void loadHider(Player player, Map map){ + player.teleport(map.getSpawn()); 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()); - if(blockhuntEnabled){ - openBlockHuntPicker(player); + if(map.isBlockHuntEnabled()){ + openBlockHuntPicker(player, map); } } - public static void loadSeeker(Player player, String gameWorld){ - player.teleport(new Location(Bukkit.getWorld(gameWorld), seekerLobbyPosition.getX(),seekerLobbyPosition.getY(),seekerLobbyPosition.getZ())); + public static void loadSeeker(Player player, Map map){ + player.teleport(map.getSeekerLobby()); 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, String gameWorld){ - player.teleport(new Location(Bukkit.getWorld(gameWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + public static void loadSpectator(Player player, Map map){ + player.teleport(map.getSpawn()); loadPlayer(player); player.setAllowFlight(true); player.setFlying(true); @@ -115,8 +113,8 @@ public class PlayerLoader { player.setFallDistance(0.0F); } - public static void joinPlayer(Player player){ - player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + public static void joinPlayer(Player player, Map map){ + player.teleport(map.getLobby()); loadPlayer(player); if (lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start"))) player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem); @@ -143,11 +141,11 @@ public class PlayerLoader { } } - public static void openBlockHuntPicker(Player player){ - int slots = ((blockhuntBlocks.size()-1)/9)*9+9; - Inventory inventory = Main.getInstance().getServer().createInventory(null, slots, "Select a Block"); - for(int i=0;i { if(game.getStatus() == Status.PLAYING){ - player.teleport(new Location(Bukkit.getWorld(game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + player.teleport(game.getCurrentMap().getSpawn()); } }, delayedRespawnDelay * 20L); } else { - player.teleport(new Location(Bukkit.getWorld(game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + player.teleport(game.getCurrentMap().getSpawn()); } // 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 3440780..1f2c388 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().isNotSetup()) { + if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) { event.getPlayer().sendMessage(errorPrefix + message("GAME_SETUP")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java index e72bea0..2439b2b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java @@ -24,6 +24,8 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.Debug; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -79,17 +81,22 @@ public class InventoryHandler implements Listener { private void checkForBlockHuntMenu(InventoryClickEvent event){ boolean test; + String mapName; if(Main.getInstance().supports(14)){ - test = event.getView().getTitle().equals("Select a Block"); + test = event.getView().getTitle().startsWith("Select a Block: "); + mapName = event.getView().getTitle().substring("Select a Block: ".length()); } else { - test = event.getInventory().getName().equals("Select a Block"); + test = event.getInventory().getName().startsWith("Select a Block: "); + mapName = event.getInventory().getName().substring("Select a Block: ".length()); } if(!test) return; event.setCancelled(true); - Material mat = blockhuntBlocks.get(event.getRawSlot()); + Map map = Maps.getMap(mapName); + if(map == null) return; + Material mat = map.getBlockHunt().get(event.getRawSlot()); if(mat == null) return; Player player = (Player) event.getWhoClicked(); - Main.getInstance().getDisguiser().disguise(player, mat); + Main.getInstance().getDisguiser().disguise(player, mat, map); player.closeInventory(); } @@ -97,17 +104,22 @@ public class InventoryHandler implements Listener { public void onInventoryClose(InventoryCloseEvent event){ if (!(event.getPlayer() instanceof Player)) return; boolean test; + String mapName; if(Main.getInstance().supports(14)){ - test = event.getView().getTitle().equals("Select a Block"); + test = event.getView().getTitle().startsWith("Select a Block: "); + mapName = event.getView().getTitle().substring("Select a Block: ".length()); } else { - test = event.getInventory().getName().equals("Select a Block"); + test = event.getInventory().getName().startsWith("Select a Block: "); + mapName = event.getInventory().getName().substring("Select a Block: ".length()); } if(!test) return; - Material mat = blockhuntBlocks.get(0); + Map map = Maps.getMap(mapName); + if(map == null) return; + Material mat = map.getBlockHunt().get(0); if(mat == null) return; Player player = (Player) event.getPlayer(); if(Main.getInstance().getDisguiser().disguised(player)) return; - Main.getInstance().getDisguiser().disguise(player, mat); + Main.getInstance().getDisguiser().disguise(player, mat, map); player.closeInventory(); } 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 6d88ebf..0ad95b5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/JoinLeaveHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/JoinLeaveHandler.java @@ -4,9 +4,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.game.PlayerLoader; import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.Bukkit; import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -17,8 +15,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; - public class JoinLeaveHandler implements Listener { @EventHandler(priority = EventPriority.HIGHEST) @@ -28,20 +24,20 @@ public class JoinLeaveHandler implements Listener { } Main.getInstance().getBoard().remove(event.getPlayer()); removeItems(event.getPlayer()); - if (Main.getInstance().getGame().isNotSetup()) return; + if (Main.getInstance().getGame().getCurrentMap().isNotSetup()) return; if (autoJoin) { Main.getInstance().getGame().join(event.getPlayer()); } else if (teleportToExit) { - if (event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld()) || event.getPlayer().getWorld().getName().equals(lobbyWorld)) { - event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + if (event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld().getName()) || 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())) { + if (mapSaveEnabled && event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld().getName())) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY && Main.getInstance().getGame().getStatus() != Status.ENDING) { Main.getInstance().getGame().join(event.getPlayer()); } else { - event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + event.getPlayer().teleport(exitPosition); event.getPlayer().setGameMode(GameMode.ADVENTURE); } } 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 e6e32f6..966f581 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/MovementHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/MovementHandler.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.game.listener; import com.google.common.collect.Sets; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.game.listener.events.PlayerJumpEvent; import org.bukkit.Material; import org.bukkit.event.EventHandler; @@ -12,9 +13,6 @@ import org.bukkit.event.player.PlayerMoveEvent; import java.util.Set; import java.util.UUID; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.saveMaxZ; - public class MovementHandler implements Listener { private final Set prevPlayersOnGround = Sets.newHashSet(); @@ -51,10 +49,11 @@ 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())) return; - if (!event.getTo().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld())) 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().hasPermission("hideandseek.leavebounds")) return; - if (event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMaxX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ) { + 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()) { event.setCancelled(true); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 1d4ff71..b4d5798 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -20,8 +20,8 @@ package net.tylermurphy.hideAndSeek.world; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Map; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -32,17 +32,20 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class WorldLoader { - + + private Map map; private String mapName; private String saveName; - public WorldLoader(String mapName) { - this.mapName = mapName; + public WorldLoader(Map map) { + this.map = map; + this.mapName = map.getSpawn() == null ? "world" : map.getSpawn().getWorld().getName(); this.saveName = "hideandseek_"+ mapName; } - public void setNewMap(String mapName){ - this.mapName = mapName; + public void setNewMap(Map map){ + this.map = map; + this.mapName = map.getSpawn() == null ? "world" : map.getSpawn().getWorld().getName(); this.saveName = "hideandseek_"+ mapName; } @@ -56,7 +59,7 @@ public class WorldLoader { Main.getInstance().getLogger().warning(saveName + " already unloaded."); return; } - world.getPlayers().forEach(player -> player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()))); + world.getPlayers().forEach(player -> player.teleport(exitPosition)); if (Bukkit.getServer().unloadWorld(world, false)) { Main.getInstance().getLogger().info("Successfully unloaded " + saveName); }else{ @@ -127,10 +130,10 @@ public class WorldLoader { } for (String file : files) { if (isMca) { - int minX = (int)Math.floor(saveMinX / 512.0); - int minZ = (int)Math.floor(saveMinZ / 512.0); - int maxX = (int)Math.floor(saveMaxX / 512.0); - int maxZ = (int)Math.floor(saveMaxZ / 512.0); + int minX = (int)Math.floor(map.getBoundsMin().getX() / 512.0); + int minZ = (int)Math.floor(map.getBoundsMin().getZ() / 512.0); + int maxX = (int)Math.floor(map.getBoundsMax().getX() / 512.0); + int maxZ = (int)Math.floor(map.getBoundsMax().getZ() / 512.0); String[] parts = file.split("\\."); if (parts.length > 1) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1d61cdc..6463898 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -292,41 +292,9 @@ blockedInteracts: [FURNACE, CRAFTING_TABLE, ANVIL, CHEST, BARREL] # ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # # ---------------------------------------------------------- # -# The 2 coordinate bounds that will contain your hideAndSeek map. Its recommended -# that you use /hs setbounds for this, and not edit this directly, as breaking -# this section will completely break the entire plugin when you run /hs savemap. -bounds: - min: - x: 0 - z: 0 - max: - x: 0 - z: 0 - -# Spawn locations where players are teleported -spawns: - # Location where players are teleported into the game (/hs start) - game: - x: 0 - y: 0 - z: 0 - world: world - # Location where players are teleported into the lobby (/hs join) - lobby: - x: 0 - y: 0 - z: 0 - world: world - # Location where seekers wait during the hiding grace period - seeker: - x: 0 - y: 0 - z: 0 - # Currently is not used, seekers are teleported to spawns.game.world - world: world - # Location where players are teleported when they exit (/hs leave) - exit: - x: 0 - y: 0 - z: 0 - world: world \ No newline at end of file +# Location where players are teleported when they exit (/hs leave) +exit: + x: 0 + y: 0 + z: 0 + world: world \ No newline at end of file diff --git a/src/main/resources/maps.yml b/src/main/resources/maps.yml new file mode 100644 index 0000000..8505162 --- /dev/null +++ b/src/main/resources/maps.yml @@ -0,0 +1 @@ +maps: \ No newline at end of file -- cgit v1.2.3-freya From 1325e042a6e7af37669bcd32e9d7a133f2ae22e6 Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 30 Oct 2022 21:40:59 -0400 Subject: finish beta build of multi map support --- pom.xml | 2 +- .../java/net/tylermurphy/hideAndSeek/Main.java | 5 +- .../net/tylermurphy/hideAndSeek/command/About.java | 8 ++- .../tylermurphy/hideAndSeek/command/AddMap.java | 54 ++++++++++++++ .../net/tylermurphy/hideAndSeek/command/Debug.java | 84 +++++++++++----------- .../net/tylermurphy/hideAndSeek/command/Help.java | 6 ++ .../tylermurphy/hideAndSeek/command/ICommand.java | 5 ++ .../net/tylermurphy/hideAndSeek/command/Join.java | 8 ++- .../net/tylermurphy/hideAndSeek/command/Leave.java | 8 ++- .../tylermurphy/hideAndSeek/command/ListMaps.java | 46 ++++++++++++ .../tylermurphy/hideAndSeek/command/Reload.java | 10 ++- .../tylermurphy/hideAndSeek/command/RemoveMap.java | 52 ++++++++++++++ .../tylermurphy/hideAndSeek/command/SaveMap.java | 12 +++- .../tylermurphy/hideAndSeek/command/SetBorder.java | 16 ++++- .../tylermurphy/hideAndSeek/command/SetBounds.java | 16 ++++- .../tylermurphy/hideAndSeek/command/SetMap.java | 66 +++++++++++++++++ .../net/tylermurphy/hideAndSeek/command/Setup.java | 19 +++-- .../net/tylermurphy/hideAndSeek/command/Start.java | 12 +++- .../net/tylermurphy/hideAndSeek/command/Stop.java | 9 ++- .../net/tylermurphy/hideAndSeek/command/Top.java | 6 ++ .../net/tylermurphy/hideAndSeek/command/Wins.java | 8 ++- .../command/location/SetExitLocation.java | 11 ++- .../command/location/SetLobbyLocation.java | 13 +++- .../command/location/SetSeekerLobbyLocation.java | 21 +++++- .../command/location/SetSpawnLocation.java | 19 ++++- .../command/location/util/LocationUtils.java | 8 ++- .../tylermurphy/hideAndSeek/configuration/Map.java | 52 +++++++++++--- .../hideAndSeek/configuration/Maps.java | 37 +++++++--- .../net/tylermurphy/hideAndSeek/game/Game.java | 24 +++++-- .../tylermurphy/hideAndSeek/game/PlayerLoader.java | 6 +- .../hideAndSeek/game/events/Border.java | 5 +- .../hideAndSeek/game/listener/DamageHandler.java | 12 ++-- .../hideAndSeek/game/listener/InteractHandler.java | 2 +- .../game/listener/JoinLeaveHandler.java | 6 +- .../hideAndSeek/game/listener/MovementHandler.java | 4 +- .../hideAndSeek/util/CommandHandler.java | 14 +++- .../tylermurphy/hideAndSeek/util/TabCompleter.java | 20 +++--- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 44 +++++------- src/main/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 -- cgit v1.2.3-freya From 7530fe5e2dad89cabd694aefc91758a651ca9196 Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Mon, 31 Oct 2022 23:28:45 -0400 Subject: 1.7.0 beta 1 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 55 +++++-- .../net/tylermurphy/hideAndSeek/command/About.java | 3 +- .../tylermurphy/hideAndSeek/command/AddMap.java | 54 ------- .../net/tylermurphy/hideAndSeek/command/Debug.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Help.java | 17 ++- .../tylermurphy/hideAndSeek/command/ICommand.java | 39 ----- .../net/tylermurphy/hideAndSeek/command/Join.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Leave.java | 3 +- .../tylermurphy/hideAndSeek/command/ListMaps.java | 46 ------ .../tylermurphy/hideAndSeek/command/Reload.java | 3 +- .../tylermurphy/hideAndSeek/command/RemoveMap.java | 52 ------- .../tylermurphy/hideAndSeek/command/SaveMap.java | 96 ------------ .../tylermurphy/hideAndSeek/command/SetBorder.java | 113 -------------- .../tylermurphy/hideAndSeek/command/SetBounds.java | 111 -------------- .../tylermurphy/hideAndSeek/command/SetMap.java | 66 -------- .../net/tylermurphy/hideAndSeek/command/Setup.java | 99 ------------ .../net/tylermurphy/hideAndSeek/command/Start.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Stop.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Top.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Wins.java | 3 +- .../command/location/SetExitLocation.java | 6 +- .../command/location/SetLobbyLocation.java | 8 +- .../command/location/SetSeekerLobbyLocation.java | 6 +- .../command/location/SetSpawnLocation.java | 6 +- .../hideAndSeek/command/map/AddMap.java | 54 +++++++ .../hideAndSeek/command/map/ListMaps.java | 47 ++++++ .../hideAndSeek/command/map/RemoveMap.java | 53 +++++++ .../hideAndSeek/command/map/SaveMap.java | 97 ++++++++++++ .../hideAndSeek/command/map/SetBorder.java | 112 ++++++++++++++ .../hideAndSeek/command/map/SetBounds.java | 112 ++++++++++++++ .../hideAndSeek/command/map/SetMap.java | 67 ++++++++ .../tylermurphy/hideAndSeek/command/map/Setup.java | 97 ++++++++++++ .../hideAndSeek/command/util/Command.java | 43 ++++++ .../hideAndSeek/command/util/CommandGroup.java | 170 +++++++++++++++++++++ .../tylermurphy/hideAndSeek/configuration/Map.java | 64 +++++--- .../hideAndSeek/configuration/Maps.java | 30 ++-- .../net/tylermurphy/hideAndSeek/game/Game.java | 4 - .../hideAndSeek/game/listener/DamageHandler.java | 1 - .../hideAndSeek/util/CommandHandler.java | 111 -------------- .../tylermurphy/hideAndSeek/util/TabCompleter.java | 59 ------- 40 files changed, 1001 insertions(+), 923 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index aace88e..b22af5b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -19,6 +19,9 @@ package net.tylermurphy.hideAndSeek; +import net.tylermurphy.hideAndSeek.command.*; +import net.tylermurphy.hideAndSeek.command.location.*; +import net.tylermurphy.hideAndSeek.command.map.*; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Localization; @@ -26,13 +29,13 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.game.*; import net.tylermurphy.hideAndSeek.game.util.Status; -import net.tylermurphy.hideAndSeek.util.CommandHandler; +import net.tylermurphy.hideAndSeek.command.util.CommandGroup; 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.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; @@ -43,8 +46,8 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; -import static net.tylermurphy.hideAndSeek.configuration.Config.exitWorld; +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Main extends JavaPlugin implements Listener { @@ -56,6 +59,7 @@ public class Main extends JavaPlugin implements Listener { private Disguiser disguiser; private EntityHider entityHider; private Game game; + private CommandGroup commandGroup; public void onEnable() { Main.instance = this; @@ -72,9 +76,36 @@ public class Main extends JavaPlugin implements Listener { this.entityHider = new EntityHider(this, EntityHider.Policy.BLACKLIST); this.registerListeners(); - CommandHandler.registerCommands(); - - game = new Game(game.getCurrentMap(), board); + this.commandGroup = new CommandGroup("hs", + new About(), + new Debug(), + new Help(), + new Reload(), + new Join(), + new Leave(), + new Start(), + new Stop(), + new CommandGroup("map", + new CommandGroup("set", + new SetLobbyLocation(), + new SetSpawnLocation(), + new SetSeekerLobbyLocation(), + new SetBorder(), + new SetBounds() + ), + new AddMap(), + new RemoveMap(), + new ListMaps(), + new SetMap(), + new Setup(), + new SaveMap() + ), + new SetExitLocation(), + new Top(), + new Wins() + ); + + game = new Game(null, board); getServer().getScheduler().runTaskTimer(this, this::onTick,0,1).getTaskId(); @@ -102,7 +133,7 @@ public class Main extends JavaPlugin implements Listener { } private void onTick() { - if(game.getStatus() == Status.ENDED) game = new Game(board); + if(game.getStatus() == Status.ENDED) game = new Game(game.getCurrentMap(), board); game.onTick(); disguiser.check(); } @@ -130,11 +161,15 @@ public class Main extends JavaPlugin implements Listener { } public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - return CommandHandler.handleCommand(sender, args); + if (!(sender instanceof Player)) { + sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); + return true; + } + return commandGroup.handleCommand((Player)sender, "", args); } public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { - return TabCompleter.handleTabComplete(sender, args); + return commandGroup.handleTabComplete(sender, args); } public static Main getInstance() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 54e0de7..119888b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -19,12 +19,13 @@ package net.tylermurphy.hideAndSeek.command; +import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.util.List; -public class About implements ICommand { +public class About extends Command { public void execute(Player sender, String[] args) { sender.sendMessage( diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java deleted file mode 100644 index 086280e..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java +++ /dev/null @@ -1,54 +0,0 @@ -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 e877659..2eb0eb9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.command; import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.PlayerLoader; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -21,7 +22,7 @@ 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 { +public class Debug extends Command { private static final Map>> debugMenuFunctions = new HashMap<>(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 5de7210..4297f3d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -20,20 +20,21 @@ package net.tylermurphy.hideAndSeek.command; import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.util.CommandHandler; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.CommandGroup; import org.bukkit.entity.Player; import java.util.List; -public class Help implements ICommand { +public class Help extends Command { public void execute(Player sender, String[] args) { - StringBuilder message = new StringBuilder(); - for(ICommand command : CommandHandler.COMMAND_REGISTER.values()) { - message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n")); - } - message = new StringBuilder(message.substring(0, message.length() - 1)); - sender.sendMessage(message.toString()); +// StringBuilder message = new StringBuilder(); +// for(Command command : CommandGroup.COMMAND_REGISTER.values()) { +// message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n")); +// } +// message = new StringBuilder(message.substring(0, message.length() - 1)); +// sender.sendMessage(message.toString()); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java deleted file mode 100644 index 91fd8f9..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public interface ICommand { - - void execute(Player sender, String[] args); - - String getLabel(); - - 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 c57b953..ca2a77f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -28,7 +29,7 @@ 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 class Join extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index 0e860cb..d22aad9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -28,7 +29,7 @@ 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 class Leave extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java deleted file mode 100644 index 0025de5..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java +++ /dev/null @@ -1,46 +0,0 @@ -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 4a4efbe..51bc509 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Localization; @@ -33,7 +34,7 @@ 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 Reload implements ICommand { +public class Reload extends Command { public void execute(Player sender, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java deleted file mode 100644 index b5727c8..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java +++ /dev/null @@ -1,52 +0,0 @@ -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 deleted file mode 100644 index ca2532c..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -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.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; - -public class SaveMap implements ICommand { - - public static boolean runningBackup = false; - - public void execute(Player sender, String[] args) { - if (!mapSaveEnabled) { - sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); - return; - } - 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.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - sender.sendMessage(messagePrefix + message("MAPSAVE_START")); - sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); - World world = map.getSpawn().getWorld(); - if (world == null) { - throw new RuntimeException("Unable to get spawn world"); - } - world.save(); - BukkitRunnable runnable = new BukkitRunnable() { - public void run() { - sender.sendMessage( - map.getWorldLoader().save() - ); - runningBackup = false; - } - }; - runnable.runTaskAsynchronously(Main.getInstance()); - runningBackup = true; - } - - public String getLabel() { - return "saveMap"; - } - - public String getUsage() { - return ""; - } - - 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 deleted file mode 100644 index 9768030..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -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 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; - -public class SetBorder 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.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - if (args.length < 4) { - map.setWorldBorderData(0, 0, 0, 0, 0); - addToConfig("worldBorder.enabled",false); - saveConfig(); - sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); - Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); - return; - } - int num,delay,change; - try { num = Integer.parseInt(args[0]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); - return; - } - try { delay = Integer.parseInt(args[1]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); - return; - } - try { change = Integer.parseInt(args[2]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); - return; - } - if (num < 100) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); - return; - } - if (change < 1) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); - return; - } - map.setWorldBorderData( - sender.getLocation().getBlockX(), - sender.getLocation().getBlockZ(), - num, - delay, - change - ); - Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); - map.getWorldBorder().resetWorldBorder(); - } - - public String getLabel() { - return "setBorder"; - } - - public String getUsage() { - 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 deleted file mode 100644 index 563116d..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -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.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetBounds 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.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - if (!sender.getWorld().getName().equals(map.getSpawnName())) { - sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); - return; - } - if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { - sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - boolean first = true; - int bxs = map.getBoundsMin().getBlockX(); - int bzs = map.getBoundsMin().getBlockZ(); - int bxl = map.getBoundsMax().getBlockX(); - int bzl = map.getBoundsMax().getBlockZ(); - if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { - bxs = bzs = bxl = bzl = 0; - } - if (bxl == 0) { - bxl = sender.getLocation().getBlockX(); - } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { - first = false; - bxs = bxl; - bxl = sender.getLocation().getBlockX(); - } else { - first = false; - bxs = sender.getLocation().getBlockX(); - } - if (bzl == 0) { - bzl = sender.getLocation().getBlockZ(); - } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { - first = false; - bzs = bzl; - bzl = sender.getLocation().getBlockZ(); - } else { - first = false; - bzs = sender.getLocation().getBlockZ(); - } - map.setBoundMin(bxs, bzs); - map.setBoundMax(bxl, bzl); - Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); - } - - public String getLabel() { - return "setBounds"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - 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 deleted file mode 100644 index c2c6a6e..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java +++ /dev/null @@ -1,66 +0,0 @@ -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 deleted file mode 100644 index b222c61..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -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; - -public class Setup implements ICommand { - - public void execute(Player sender, String[] args) { - - String msg = message("SETUP").toString(); - int count = 0; - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - 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().getWorld() == null || map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_LOBBY"); - count++; - } - 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 (exitWorld == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_EXIT"); - count++; - } - if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || - map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { - msg = msg + "\n" + message("SETUP_BOUNDS"); - count++; - } - if (mapSaveEnabled) { - File destenation = new File(Main.getInstance().getWorldContainer() + File.separator + map.getGameSpawnName()); - if (!destenation.exists()) { - msg = msg + "\n" + message("SETUP_SAVEMAP"); - count++; - } - } - if (count < 1) { - sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); - } else { - sender.sendMessage(msg); - } - } - - public String getLabel() { - return "setup"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - 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 085aeab..54ad4af 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -34,7 +34,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.minPlayers; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Start implements ICommand { +public class Start extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 4567bb1..1582be9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -20,17 +20,17 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; import 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; -public class Stop implements ICommand { +public class Stop extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index c57f246..8116eaf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -30,7 +31,7 @@ import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Top implements ICommand { +public class Top extends Command { public void execute(Player sender, String[] args) { int page; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index 9ed7345..c5917c2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -31,7 +32,7 @@ import java.util.UUID; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Wins implements ICommand { +public class Wins extends Command { public void execute(Player sender, String[] args) { Main.getInstance().getServer().getScheduler().runTaskAsynchronously(Main.getInstance(), () -> { 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 1bb1d6f..01e1512 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -19,18 +19,16 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.util.Command; 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 class SetExitLocation extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.EXIT, null, map -> { 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 84e1109..da41d91 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -19,7 +19,7 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; @@ -28,9 +28,7 @@ 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 { +public class SetLobbyLocation extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { @@ -39,7 +37,7 @@ public class SetLobbyLocation implements ICommand { } public String getLabel() { - return "setlobby"; + return "lobby"; } public String getUsage() { 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 c6d9f93..8a5ebd1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; @@ -11,7 +11,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetSeekerLobbyLocation implements ICommand { +public class SetSeekerLobbyLocation extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { @@ -26,7 +26,7 @@ public class SetSeekerLobbyLocation implements ICommand { } public String getLabel() { - return "setseekerlobby"; + return "seekerlobby"; } public String getUsage() { 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 50932d6..82f71d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -19,7 +19,7 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; @@ -33,7 +33,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetSpawnLocation implements ICommand { +public class SetSpawnLocation extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { @@ -58,7 +58,7 @@ public class SetSpawnLocation implements ICommand { } public String getLabel() { - return "setspawn"; + return "spawn"; } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java new file mode 100644 index 0000000..55b4267 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java @@ -0,0 +1,54 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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.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 extends Command { + + 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 "add"; + } + + 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/map/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java new file mode 100644 index 0000000..79490a7 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java @@ -0,0 +1,47 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.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 extends Command { + + 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 "list"; + } + + 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/map/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java new file mode 100644 index 0000000..216cca9 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java @@ -0,0 +1,53 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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 extends Command { + + 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 "remove"; + } + + 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/map/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java new file mode 100644 index 0000000..f3eb4d7 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java @@ -0,0 +1,97 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +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; + +public class SaveMap extends Command { + + public static boolean runningBackup = false; + + public void execute(Player sender, String[] args) { + if (!mapSaveEnabled) { + sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); + return; + } + 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.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + sender.sendMessage(messagePrefix + message("MAPSAVE_START")); + sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); + World world = map.getSpawn().getWorld(); + if (world == null) { + throw new RuntimeException("Unable to get spawn world"); + } + world.save(); + BukkitRunnable runnable = new BukkitRunnable() { + public void run() { + sender.sendMessage( + map.getWorldLoader().save() + ); + runningBackup = false; + } + }; + runnable.runTaskAsynchronously(Main.getInstance()); + runningBackup = true; + } + + public String getLabel() { + return "save"; + } + + public String getUsage() { + return ""; + } + + 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/map/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java new file mode 100644 index 0000000..8362e02 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java @@ -0,0 +1,112 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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.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; + +public class SetBorder extends Command { + + 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.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + if (args.length < 4) { + map.setWorldBorderData(0, 0, 0, 0, 0); + addToConfig("worldBorder.enabled",false); + saveConfig(); + sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); + Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); + return; + } + int num,delay,change; + try { num = Integer.parseInt(args[1]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + try { delay = Integer.parseInt(args[2]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); + return; + } + try { change = Integer.parseInt(args[3]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); + return; + } + if (num < 100) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); + return; + } + if (change < 1) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); + return; + } + map.setWorldBorderData( + sender.getLocation().getBlockX(), + sender.getLocation().getBlockZ(), + num, + delay, + change + ); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); + map.getWorldBorder().resetWorldBorder(); + } + + public String getLabel() { + return "border"; + } + + public String getUsage() { + 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/map/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java new file mode 100644 index 0000000..92bf5a4 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java @@ -0,0 +1,112 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SetBounds extends Command { + + 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.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + if (!sender.getWorld().getName().equals(map.getSpawnName())) { + sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); + return; + } + if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { + sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + boolean first = true; + int bxs = map.getBoundsMin().getBlockX(); + int bzs = map.getBoundsMin().getBlockZ(); + int bxl = map.getBoundsMax().getBlockX(); + int bzl = map.getBoundsMax().getBlockZ(); + if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { + bxs = bzs = bxl = bzl = 0; + } + if (bxl == 0) { + bxl = sender.getLocation().getBlockX(); + } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { + first = false; + bxs = bxl; + bxl = sender.getLocation().getBlockX(); + } else { + first = false; + bxs = sender.getLocation().getBlockX(); + } + if (bzl == 0) { + bzl = sender.getLocation().getBlockZ(); + } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { + first = false; + bzs = bzl; + bzl = sender.getLocation().getBlockZ(); + } else { + first = false; + bzs = sender.getLocation().getBlockZ(); + } + map.setBoundMin(bxs, bzs); + map.setBoundMax(bxl, bzl); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); + } + + public String getLabel() { + return "bounds"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + 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/map/SetMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java new file mode 100644 index 0000000..2df5824 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java @@ -0,0 +1,67 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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 extends Command { + + 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 "goto"; + } + + 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/map/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java new file mode 100644 index 0000000..46b41f7 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java @@ -0,0 +1,97 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import 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; + +public class Setup extends Command { + + public void execute(Player sender, String[] args) { + + String msg = message("SETUP").toString(); + int count = 0; + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + msg = msg + "\n" + message("SETUP_GAME"); + count++; + } + if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + msg = msg + "\n" + message("SETUP_LOBBY"); + count++; + } + if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !Map.worldExists(map.getSeekerLobbyName())) { + msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); + count++; + } + if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld)) { + msg = msg + "\n" + message("SETUP_EXIT"); + count++; + } + if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || + map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { + msg = msg + "\n" + message("SETUP_BOUNDS"); + count++; + } + if (mapSaveEnabled && !Map.worldExists(map.getGameSpawnName())) { + msg = msg + "\n" + message("SETUP_SAVEMAP"); + count++; + } + if (count < 1) { + sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); + } else { + sender.sendMessage(msg); + } + } + + public String getLabel() { + return "setup"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + 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/util/Command.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java new file mode 100644 index 0000000..d03274d --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java @@ -0,0 +1,43 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.util; + +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public abstract class Command { + + public abstract void execute(Player sender, String[] args); + + public abstract String getLabel(); + + public abstract String getUsage(); + + public abstract String getDescription(); + + public abstract List autoComplete(@Nullable String parameter); + + public boolean hasPermission(Player sender, String permission) { + return sender.hasPermission(permission+"."+getLabel()); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java new file mode 100644 index 0000000..9079ccc --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -0,0 +1,170 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.util; + +import net.tylermurphy.hideAndSeek.command.*; +import net.tylermurphy.hideAndSeek.command.map.SaveMap; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.permissionsRequired; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class CommandGroup { + + private final Map commandRegister; + private final String label; + + public CommandGroup(String label, Object... data) { + this.label = label; + this.commandRegister = new HashMap<>(); + for(Object o : data) registerCommand(o); + } + + public String getLabel() { + return label; + } + + private void registerCommand(Object object) { + if(object instanceof Command) { + Command command = (Command) object; + if (!commandRegister.containsKey(command.getLabel())) { + commandRegister.put(command.getLabel().toLowerCase(), command); + } + } else if(object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + if (!commandRegister.containsKey(group.getLabel())) { + commandRegister.put(group.getLabel().toLowerCase(), group); + } + } + } + + public boolean handleCommand(Player player, String permission, String[] args) { + if (args.length < 1 && permission.equals("hs") || !commandRegister.containsKey(args[0].toLowerCase()) ) { + if (permissionsRequired && !player.hasPermission("hs.about")) { + player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); + } else { + new About().execute(player, null); + } + } else { + String invoke = args[0].toLowerCase(); + if (!invoke.equals("about") && !invoke.equals("help") && SaveMap.runningBackup) { + player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); + } else if (permissionsRequired && !player.hasPermission(permission+"."+invoke)) { + player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); + } else { + try { + Object object = commandRegister.get(invoke); + if(object instanceof CommandGroup) return ((CommandGroup) object).handleCommand(player, permission+"."+this.label, Arrays.copyOfRange(args, 1, args.length)); + Command command = (Command) object; + + int parameters = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); + if(args.length - 1 < parameters) { + player.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); + return true; + } + command.execute(player,Arrays.copyOfRange(args, 1, args.length)); + } catch (Exception e) { + player.sendMessage(errorPrefix + "An error has occurred."); + e.printStackTrace(); + } + } + } + return true; + } + + public List handleTabComplete(CommandSender sender, String[] args) { + String invoke = args[0].toLowerCase(); + if (args.length == 1) { + if(sender instanceof Player) { + Player player = (Player) sender; + return new ArrayList<>(commandRegister.keySet()) + .stream() + .filter(handle -> handle.toLowerCase().startsWith(invoke)) + .filter(handle -> { + Object object = commandRegister.get(handle); + if (object instanceof Command) return ((Command) object).hasPermission(player, this.label); + if (object instanceof CommandGroup) + return ((CommandGroup) object).hasPermission(player, this.label); + return false; + }) + .collect(Collectors.toList()); + } + return commandRegister.keySet().stream().filter(handle -> handle.toLowerCase().startsWith(invoke)).collect(Collectors.toList()); + } else { + if (!commandRegister.containsKey(invoke)) { + return new ArrayList<>(); + } else { + Object object = commandRegister.get(invoke); + if(object instanceof CommandGroup) return ((CommandGroup) object).handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length)); + Command command = (Command) object; + String[] usage = command.getUsage().split(" "); + List complete; + if (args.length - 2 < usage.length) { + String parameter = usage[args.length-2]; + String name = parameter.replace("<", "").replace(">", ""); + complete = command.autoComplete(name); + } else { + complete = command.autoComplete(null); + } + if(complete == null) return new ArrayList<>(); + else return complete; + } + } + } + + private boolean hasPermission(Player player, String permission) { + for(Object object : commandRegister.values()) { + if(object instanceof Command) if(((Command) object).hasPermission(player, this.label)) return true; + if(object instanceof CommandGroup) if (((CommandGroup) object).hasPermission(player, permission+"."+this.label)) return true; + } + return false; + } + + // public static void registerCommands() { +// registerCommand(new About()); +// registerCommand(new Help()); +// registerCommand(new Setup()); +// registerCommand(new Start()); +// registerCommand(new Stop()); +// registerCommand(new SetSpawnLocation()); +// registerCommand(new SetLobbyLocation()); +// registerCommand(new SetSeekerLobbyLocation()); +// registerCommand(new SetExitLocation()); +// registerCommand(new SetBorder()); +// registerCommand(new Reload()); +// registerCommand(new SaveMap()); +// registerCommand(new SetBounds()); +// registerCommand(new Join()); +// registerCommand(new Leave()); +// registerCommand(new Top()); +// registerCommand(new Wins()); +// registerCommand(new Debug()); +// registerCommand(new AddMap()); +// registerCommand(new RemoveMap()); +// registerCommand(new ListMaps()); +// registerCommand(new SetMap()); +// } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java index 42cab4b..5e9b6ae 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -23,7 +23,9 @@ public class Map { seekerLobbyPosition = new Location(null, 0, 0, 0); private String - gameWorldName = "world"; + spawnWorldName = "world", + lobbyWorldName = "world", + seekerLobbyWorldName = "world"; private int xBoundMin = 0, @@ -57,15 +59,31 @@ public class Map { public void setSpawn(Location pos) { this.spawnPosition = pos; if(pos.getWorld() != null) - this.gameWorldName = pos.getWorld().getName(); + this.spawnWorldName = pos.getWorld().getName(); } public void setLobby(Location pos) { this.lobbyPosition = pos; + if(pos.getWorld() != null) + this.lobbyWorldName = pos.getWorld().getName(); } public void setSeekerLobby(Location pos) { this.seekerLobbyPosition = pos; + if(pos.getWorld() != null) + this.seekerLobbyWorldName = pos.getWorld().getName(); + } + + public void setSpawnName(String name) { + this.spawnWorldName = name; + } + + public void setLobbyName(String name) { + this.lobbyWorldName = name; + } + + public void setSeekerLobbyName(String name) { + this.seekerLobbyWorldName = name; } public void setWorldBorderData(int x, int z, int size, int delay, int move) { @@ -103,7 +121,7 @@ public class Map { public Location getGameSpawn() { if(mapSaveEnabled) { return new Location( - Bukkit.getWorld("hs_" + gameWorldName), + Bukkit.getWorld("hs_" + spawnWorldName), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ() @@ -114,7 +132,10 @@ public class Map { } public String getGameSpawnName() { - return "hs_"+gameWorldName; + if(mapSaveEnabled) + return "hs_"+ spawnWorldName; + else + return spawnWorldName; } public Location getSpawn() { @@ -122,21 +143,29 @@ public class Map { } public String getSpawnName() { - return gameWorldName; + return spawnWorldName; } public Location getLobby() { return lobbyPosition; } + public String getLobbyName() { + return lobbyWorldName; + } + public Location getSeekerLobby() { return seekerLobbyPosition; } + public String getSeekerLobbyName() { + return seekerLobbyWorldName; + } + public Location getGameSeekerLobby() { if(mapSaveEnabled) { return new Location( - Bukkit.getWorld("hs_" + gameWorldName), + Bukkit.getWorld("hs_" + getSeekerLobbyName()), seekerLobbyPosition.getX(), seekerLobbyPosition.getY(), seekerLobbyPosition.getZ() @@ -203,19 +232,11 @@ public class Map { } public boolean isNotSetup() { - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true; - if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true; - if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true; - if (exitPosition.getWorld() == null) { - Bukkit.getServer().createWorld(new WorldCreator(exitWorld).generator(new VoidGenerator())); - World world = Bukkit.getServer().getWorld(exitWorld); - if(world == null) return true; - } - if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0) return true; - if (mapSaveEnabled) { - File destination = new File(Main.getInstance().getWorldContainer() + File.separator + spawnPosition.getWorld().getName()); - if (!destination.exists()) return true; - } + if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !Map.worldExists(spawnWorldName)) return true; + if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !Map.worldExists(lobbyWorldName)) return true; + if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld) ) return true; + if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !Map.worldExists(seekerLobbyWorldName)) return true; + if (mapSaveEnabled && !Map.worldExists(getGameSpawnName())) return true; if(isWorldBorderEnabled() && new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true; return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; @@ -225,4 +246,9 @@ public class Map { return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0; } + public static boolean worldExists(String worldName) { + File destination = new File(Main.getInstance().getWorldContainer()+File.separator+worldName); + return destination.isDirectory(); + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java index 4f18639..ff1b396 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -60,7 +60,6 @@ public class Maps { MAPS.clear(); for(String key : keys) { - System.out.println(key); MAPS.put(key, parseMap(maps, key)); } @@ -71,8 +70,11 @@ public class Maps { if(data == null) return null; Map map = new Map(name); map.setSpawn(setSpawn(data, "game")); + map.setSpawnName(data.getString("spawns.game.world")); map.setLobby(setSpawn(data, "lobby")); + map.setLobbyName(data.getString("spawns.lobby.world")); map.setSeekerLobby(setSpawn(data, "seeker")); + map.setSeekerLobbyName(data.getString("spawns.seeker.world")); map.setBoundMin(data.getInt("bounds.min.x"), data.getInt("bounds.min.z")); map.setBoundMax(data.getInt("bounds.max.x"), data.getInt("bounds.max.z")); map.setWorldBorderData( @@ -100,8 +102,8 @@ public class Maps { private static Location setSpawn(ConfigurationSection data, String spawn) { String worldName = data.getString("spawns."+spawn+".world"); if(worldName == null) return new Location(null, 0, 0, 0); + if(!Map.worldExists(worldName)) return new Location(null, 0, 0, 0); World world = Bukkit.getWorld(worldName); - if(world == null) return new Location(null, 0, 0, 0); double x = data.getDouble("spawns."+spawn+".x"); double y = data.getDouble("spawns."+spawn+".y"); double z = data.getDouble("spawns."+spawn+".z"); @@ -115,9 +117,9 @@ public class Maps { for(Map map : MAPS.values()) { ConfigurationSection data = new YamlConfiguration(); - saveSpawn(data, map.getSpawn(), "game"); - saveSpawn(data, map.getLobby(), "lobby"); - saveSpawn(data, map.getSeekerLobby(), "seeker"); + saveSpawn(data, map.getSpawn(), "game", map); + saveSpawn(data, map.getLobby(), "lobby", map); + saveSpawn(data, map.getSeekerLobby(), "seeker", map); data.set("bounds.min.x", map.getBoundsMin().getX()); data.set("bounds.min.z", map.getBoundsMin().getZ()); data.set("bounds.max.x", map.getBoundsMax().getX()); @@ -137,15 +139,25 @@ public class Maps { } - private static void saveSpawn(ConfigurationSection data, Location spawn, String name) { - if(spawn.getWorld() != null) { - data.set("spawns." + name + ".world", spawn.getWorld().getName()); - } else { + private static void saveSpawn(ConfigurationSection data, Location spawn, String name, Map map) { + String worldName = getWorldName(name, map); + if(worldName == null || !Map.worldExists(worldName)) { data.set("spawns." + name + ".world", "world"); + } else { + data.set("spawns." + name + ".world", worldName); } data.set("spawns." + name + ".x", spawn.getX()); data.set("spawns." + name + ".y", spawn.getY()); data.set("spawns." + name + ".z", spawn.getZ()); } + private static String getWorldName(String name, Map map) { + switch (name) { + case "game": return map.getSpawnName(); + case "lobby": return map.getLobbyName(); + case "seeker": return map.getSeekerLobbyName(); + default: return null; + } + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 53e61df..4dd5fa9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -58,10 +58,6 @@ public class Game { private int gameTimer; private boolean hiderLeft; - public Game(Board board) { - this(Maps.getRandomMap(), board); - } - public Game(Map map, Board board) { this.currentMap = map; 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 08a5a80..d6eceb2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java @@ -42,7 +42,6 @@ public class DamageHandler implements Listener { } // Makes sure that if there was an attacking player, that the event is allowed for the game if (attacker != null) { - System.out.println(event.getFinalDamage() + " " + player.getDisplayName() + " " + attacker.getDisplayName()); // Cancel if one player is in the game but other isn't if ((board.contains(player) && !board.contains(attacker)) || (!board.contains(player) && board.contains(attacker))) { event.setCancelled(true); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java deleted file mode 100644 index 3b0f1b4..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.util; - -import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.command.location.SetExitLocation; -import net.tylermurphy.hideAndSeek.command.location.SetLobbyLocation; -import net.tylermurphy.hideAndSeek.command.location.SetSeekerLobbyLocation; -import net.tylermurphy.hideAndSeek.command.location.SetSpawnLocation; -import org.bukkit.command.CommandSender; -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; -import static net.tylermurphy.hideAndSeek.configuration.Localization.LOCAL; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class CommandHandler { - - public static final Map COMMAND_REGISTER = new LinkedHashMap<>(); - - private static void registerCommand(ICommand command) { - if (!COMMAND_REGISTER.containsKey(command.getLabel())) { - COMMAND_REGISTER.put(command.getLabel().toLowerCase(), command); - } - } - - public static void registerCommands() { - registerCommand(new About()); - registerCommand(new Help()); - registerCommand(new Setup()); - registerCommand(new Start()); - registerCommand(new Stop()); - registerCommand(new SetSpawnLocation()); - registerCommand(new SetLobbyLocation()); - registerCommand(new SetSeekerLobbyLocation()); - registerCommand(new SetExitLocation()); - registerCommand(new SetBorder()); - registerCommand(new Reload()); - registerCommand(new SaveMap()); - registerCommand(new SetBounds()); - registerCommand(new Join()); - registerCommand(new Leave()); - registerCommand(new Top()); - registerCommand(new Wins()); - registerCommand(new Debug()); - registerCommand(new AddMap()); - registerCommand(new RemoveMap()); - registerCommand(new ListMaps()); - registerCommand(new SetMap()); - } - - public static boolean handleCommand(CommandSender sender, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); - return true; - } - Player player = (Player) sender; - if (args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) { - if (permissionsRequired && !sender.hasPermission("hideandseek.about")) { - sender.sendMessage(errorPrefix + LOCAL.get("")); - } else { - COMMAND_REGISTER.get("about").execute(player, null); - } - } else { - if (!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) { - sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); - } else if (permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) { - sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); - } else { - - try { - 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(); - } - } - } - return true; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java deleted file mode 100644 index 28154d1..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.util; - -import net.tylermurphy.hideAndSeek.command.ICommand; -import org.bukkit.command.CommandSender; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - -public class TabCompleter { - - public static List handleTabComplete(CommandSender sender, String[] args) { - if (args.length == 1) { - return new ArrayList<>(CommandHandler.COMMAND_REGISTER.keySet()) - .stream() - .filter(handle -> sender.hasPermission("hideandseek."+handle.toLowerCase()) && handle.toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT))) - .collect(Collectors.toList()); - } else if (args.length > 1) { - if (!CommandHandler.COMMAND_REGISTER.containsKey(args[0].toLowerCase())) { - return new ArrayList<>(); - } else { - 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]; - String name = parameter.replace("<", "").replace(">", ""); - complete = command.autoComplete(name); - } else { - complete = command.autoComplete(null); - } - if(complete == null) return new ArrayList<>(); - else return complete; - } - } - return null; - } - -} -- cgit v1.2.3-freya From bb254145ed0bb56d0482f6ba34e05cb728a7c8cc Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Wed, 2 Nov 2022 07:18:00 -0400 Subject: 1.7.0 beta 2 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 74 ++++++----- .../net/tylermurphy/hideAndSeek/command/About.java | 54 -------- .../net/tylermurphy/hideAndSeek/command/Debug.java | 130 ------------------- .../tylermurphy/hideAndSeek/command/Reload.java | 21 ++-- .../net/tylermurphy/hideAndSeek/command/Send.java | 67 ++++++++++ .../hideAndSeek/command/SetExitLocation.java | 61 +++++++++ .../net/tylermurphy/hideAndSeek/command/Start.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../net/tylermurphy/hideAndSeek/command/Top.java | 2 +- .../command/location/LocationUtils.java | 53 ++++++++ .../hideAndSeek/command/location/Locations.java | 26 ++++ .../command/location/SetExitLocation.java | 61 --------- .../command/location/SetLobbyLocation.java | 58 --------- .../command/location/SetSeekerLobbyLocation.java | 47 ------- .../command/location/SetSpawnLocation.java | 79 ------------ .../command/location/util/LocationUtils.java | 53 -------- .../command/location/util/Locations.java | 26 ---- .../tylermurphy/hideAndSeek/command/map/Add.java | 54 ++++++++ .../hideAndSeek/command/map/AddMap.java | 54 -------- .../tylermurphy/hideAndSeek/command/map/Debug.java | 130 +++++++++++++++++++ .../tylermurphy/hideAndSeek/command/map/GoTo.java | 63 ++++++++++ .../tylermurphy/hideAndSeek/command/map/List.java | 46 +++++++ .../hideAndSeek/command/map/ListMaps.java | 47 ------- .../hideAndSeek/command/map/Remove.java | 53 ++++++++ .../hideAndSeek/command/map/RemoveMap.java | 53 -------- .../tylermurphy/hideAndSeek/command/map/Save.java | 98 +++++++++++++++ .../hideAndSeek/command/map/SaveMap.java | 97 -------------- .../hideAndSeek/command/map/SetBorder.java | 112 ----------------- .../hideAndSeek/command/map/SetBounds.java | 112 ----------------- .../hideAndSeek/command/map/SetMap.java | 67 ---------- .../tylermurphy/hideAndSeek/command/map/Setup.java | 97 -------------- .../hideAndSeek/command/map/Status.java | 95 ++++++++++++++ .../hideAndSeek/command/map/blockhunt/Enabled.java | 43 +++++++ .../hideAndSeek/command/map/set/Border.java | 112 +++++++++++++++++ .../hideAndSeek/command/map/set/Bounds.java | 112 +++++++++++++++++ .../hideAndSeek/command/map/set/Lobby.java | 58 +++++++++ .../hideAndSeek/command/map/set/SeekerLobby.java | 47 +++++++ .../hideAndSeek/command/map/set/Spawn.java | 79 ++++++++++++ .../hideAndSeek/command/util/CommandGroup.java | 13 +- .../hideAndSeek/configuration/Config.java | 39 ------ .../hideAndSeek/configuration/ConfigManager.java | 139 ++++++++++++++------- .../hideAndSeek/configuration/Leaderboard.java | 51 ++++++++ .../hideAndSeek/configuration/Localization.java | 2 +- .../net/tylermurphy/hideAndSeek/game/Board.java | 13 +- .../tylermurphy/hideAndSeek/game/Disguiser.java | 3 +- .../hideAndSeek/game/listener/ChatHandler.java | 2 +- .../hideAndSeek/game/listener/DisguiseHandler.java | 3 +- .../game/listener/InventoryHandler.java | 4 +- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 4 +- src/main/resources/config.yml | 107 ++++++++-------- src/main/resources/lang/localization_en-US.yml | 19 ++- src/main/resources/leaderboard.yml | 7 +- 52 files changed, 1496 insertions(+), 1357 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/About.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Send.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index b22af5b..b1e2a83 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -20,15 +20,11 @@ package net.tylermurphy.hideAndSeek; import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.command.location.*; import net.tylermurphy.hideAndSeek.command.map.*; -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.command.map.set.*; +import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.game.*; -import net.tylermurphy.hideAndSeek.game.util.Status; import net.tylermurphy.hideAndSeek.command.util.CommandGroup; import net.tylermurphy.hideAndSeek.game.listener.*; import net.tylermurphy.hideAndSeek.util.PAPIExpansion; @@ -41,7 +37,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import java.io.File; -import java.util.List; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -65,10 +60,17 @@ public class Main extends JavaPlugin implements Listener { Main.instance = this; this.updateVersion(); - Config.loadConfig(); - Maps.loadMaps(); - Localization.loadLocalization(); - Items.loadItems(); + try { + Config.loadConfig(); + Maps.loadMaps(); + Localization.loadLocalization(); + Items.loadItems(); + Leaderboard.loadLeaderboard(); + } catch (Exception e) { + getLogger().severe(e.getMessage()); + Bukkit.getPluginManager().disablePlugin(this); + return; + } this.board = new Board(); this.database = new Database(); @@ -77,28 +79,27 @@ public class Main extends JavaPlugin implements Listener { this.registerListeners(); this.commandGroup = new CommandGroup("hs", - new About(), - new Debug(), new Help(), new Reload(), new Join(), new Leave(), + new Send(), new Start(), new Stop(), new CommandGroup("map", new CommandGroup("set", - new SetLobbyLocation(), - new SetSpawnLocation(), - new SetSeekerLobbyLocation(), - new SetBorder(), - new SetBounds() + new Lobby(), + new Spawn(), + new SeekerLobby(), + new Border(), + new Bounds() ), - new AddMap(), - new RemoveMap(), - new ListMaps(), - new SetMap(), - new Setup(), - new SaveMap() + new Add(), + new Remove(), + new List(), + new Status(), + new Save(), + new Debug() ), new SetExitLocation(), new Top(), @@ -120,20 +121,25 @@ public class Main extends JavaPlugin implements Listener { version = 0; - board.getPlayers().forEach(player -> { - board.removeBoard(player); - PlayerLoader.unloadPlayer(player); - if(!Objects.equals(exitWorld, "")) - player.teleport(exitPosition); - }); + if(board != null) { + board.getPlayers().forEach(player -> { + board.removeBoard(player); + PlayerLoader.unloadPlayer(player); + if (!Objects.equals(exitWorld, "")) + player.teleport(exitPosition); + }); + board.cleanup(); + } + + if(disguiser != null) { + disguiser.cleanUp(); + } Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this); - board.cleanup(); - disguiser.cleanUp(); } private void onTick() { - if(game.getStatus() == Status.ENDED) game = new Game(game.getCurrentMap(), board); + if(game.getStatus() == net.tylermurphy.hideAndSeek.game.util.Status.ENDED) game = new Game(game.getCurrentMap(), board); game.onTick(); disguiser.check(); } @@ -168,7 +174,7 @@ public class Main extends JavaPlugin implements Listener { return commandGroup.handleCommand((Player)sender, "", args); } - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + public java.util.List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { return commandGroup.handleTabComplete(sender, args); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java deleted file mode 100644 index 119888b..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.List; - -public class About extends Command { - - public void execute(Player sender, String[] args) { - sender.sendMessage( - 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) - ); - } - - public String getLabel() { - return "about"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Get information about the plugin"; - } - - public List autoComplete(String parameter) { - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java deleted file mode 100644 index 2eb0eb9..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java +++ /dev/null @@ -1,130 +0,0 @@ -package net.tylermurphy.hideAndSeek.command; - -import com.cryptomorin.xseries.XMaterial; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.PlayerLoader; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -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 extends Command { - - private static final Map>> debugMenuFunctions = new HashMap<>(); - - public void execute(Player sender, String[] args) { - 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 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(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - Main.getInstance().getBoard().addHider(player); - PlayerLoader.loadHider(player, map); - if(Main.getInstance().getGame().getStatus() != Status.STARTING) - PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); - })); - debugMenu.setItem(1, createOption(functions, 1, XMaterial.GOLDEN_CHESTPLATE.parseMaterial(), "&cBecome a &lSeeker", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - Main.getInstance().getBoard().addSeeker(player); - PlayerLoader.loadSeeker(player, map); - if(Main.getInstance().getGame().getStatus() != Status.STARTING) - PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); - })); - debugMenu.setItem(2, createOption(functions, 2, XMaterial.IRON_CHESTPLATE.parseMaterial(), "&8Become a &lSpectator", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - Main.getInstance().getBoard().addSpectator(player); - PlayerLoader.loadSpectator(player, map); - })); - 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(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(functions, 6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - player.teleport(map.getGameSpawn()); - })); - debugMenu.setItem(7, createOption(functions, 7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { - player.teleport(map.getLobby()); - })); - 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(functions, 10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); - debugMenuFunctions.put(sender, functions); - return debugMenu; - } - - 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); - 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(player).get(slotId); - if(callback != null) callback.accept(player); - }, 0); - } - - public String getLabel() { - return "debug"; - } - - public String getUsage() { - 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/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 51bc509..9f8392f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -21,10 +21,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; -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.configuration.*; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; @@ -42,10 +39,18 @@ public class Reload extends Command { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - Config.loadConfig(); - Maps.loadMaps(); - Localization.loadLocalization(); - Items.loadItems(); + + try { + Config.loadConfig(); + Maps.loadMaps(); + Localization.loadLocalization(); + Items.loadItems(); + Leaderboard.loadLeaderboard(); + } catch (Exception e) { + sender.sendMessage(errorPrefix + message("CONFIG_ERROR")); + return; + } + sender.sendMessage(messagePrefix + message("CONFIG_RELOAD")); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java new file mode 100644 index 0000000..9978c3c --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java @@ -0,0 +1,67 @@ +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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 Send extends Command { + + 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 "send"; + } + + 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/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java new file mode 100644 index 0000000..874909b --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -0,0 +1,61 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import org.bukkit.entity.Player; + +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class SetExitLocation extends Command { + + public void execute(Player sender, String[] args) { + 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()); + addToConfig("exit.world", sender.getLocation().getWorld().getName()); + exitPosition = sender.getLocation(); + exitWorld = sender.getLocation().getWorld().getName(); + saveConfig(); + }); + } + + public String getLabel() { + return "setexit"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + 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/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 54ad4af..674edd6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -57,7 +57,7 @@ public class Start extends Command { if (args.length < 1) { Optional rand = Main.getInstance().getBoard().getPlayers().stream().skip(new Random().nextInt(Main.getInstance().getBoard().size())).findFirst(); if (!rand.isPresent()) { - Main.getInstance().getLogger().warning("Failed to select random seeker."); + sender.sendMessage(errorPrefix + message("START_FAILED_SEEKER")); return; } seekerName = rand.get().getName(); @@ -82,7 +82,7 @@ public class Start extends Command { } public String getUsage() { - return ""; + return "<*player>"; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 1582be9..7c8cabf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -34,7 +34,7 @@ public class Stop extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { - sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); + sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } if (Main.getInstance().getGame().getStatus() == Status.STARTING || Main.getInstance().getGame().getStatus() == Status.PLAYING) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 8116eaf..0a5358d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -76,7 +76,7 @@ public class Top extends Command { } public String getUsage() { - return ""; + return "<*page>"; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java new file mode 100644 index 0000000..5e4afb5 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java @@ -0,0 +1,53 @@ +package net.tylermurphy.hideAndSeek.command.location; + +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 org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +/** + * @author bobby29831 + */ +public class LocationUtils { + + public static void setLocation(@NotNull Player player, @NotNull Locations place, String mapName, @NotNull Consumer consumer) { + + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + player.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + + if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ + player.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + + Map map = null; + if(mapName != null) { + map = Maps.getMap(mapName); + if (map == null) { + player.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + } + + 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())); + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java new file mode 100644 index 0000000..dd73dac --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java @@ -0,0 +1,26 @@ +package net.tylermurphy.hideAndSeek.command.location; + +/** + * @author bobby29831 + */ +public enum Locations { + + GAME("spawns.game"), + LOBBY("spawns.lobby"), + EXIT("spawns.exit"), + SEEKER("spawns.seeker"); + + private final String path; + Locations(String path) { + this.path = path; + } + + public String message() { + return this + "_SPAWN"; + } + + public String path(String additive) { + return path + "." + additive; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java deleted file mode 100644 index 01e1512..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.location; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; -import org.bukkit.entity.Player; - -import java.util.List; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -public class SetExitLocation extends Command { - - public void execute(Player sender, String[] args) { - 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()); - addToConfig("exit.world", sender.getLocation().getWorld().getName()); - exitPosition = sender.getLocation(); - exitWorld = sender.getLocation().getWorld().getName(); - saveConfig(); - }); - } - - public String getLabel() { - return "setexit"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - 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 deleted file mode 100644 index da41d91..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.location; - -import net.tylermurphy.hideAndSeek.command.util.Command; -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; - -public class SetLobbyLocation extends Command { - - public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { - map.setLobby(sender.getLocation()); - }); - } - - public String getLabel() { - return "lobby"; - } - - public String getUsage() { - 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 deleted file mode 100644 index 8a5ebd1..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.location; - -import net.tylermurphy.hideAndSeek.command.util.Command; -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.Localization.message; - -public class SetSeekerLobbyLocation extends Command { - - 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()); - }); - } - - public String getLabel() { - return "seekerlobby"; - } - - public String getUsage() { - 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 deleted file mode 100644 index 82f71d1..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.location; - -import net.tylermurphy.hideAndSeek.command.util.Command; -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; - -public class SetSpawnLocation extends Command { - - public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { - - if (map.isWorldBorderEnabled() && - new Vector(sender.getLocation().getX(), 0, sender.getLocation().getZ()).distance(map.getWorldBorderPos()) > 100) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); - throw new RuntimeException("World border not enabled or not in valid position!"); - } - - map.setSpawn(sender.getLocation()); - - 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(); - } - }); - } - - public String getLabel() { - return "spawn"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - 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 deleted file mode 100644 index 69d7c26..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.location.util; - -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 org.jetbrains.annotations.NotNull; - -import java.util.function.Consumer; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -/** - * @author bobby29831 - */ -public class LocationUtils { - - public static void setLocation(@NotNull Player player, @NotNull Locations place, String mapName, @NotNull Consumer consumer) { - - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - player.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - - if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ - player.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - - Map map = null; - if(mapName != null) { - map = Maps.getMap(mapName); - if (map == null) { - player.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - } - - 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())); - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java deleted file mode 100644 index 35f74ea..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.location.util; - -/** - * @author bobby29831 - */ -public enum Locations { - - GAME("spawns.game"), - LOBBY("spawns.lobby"), - EXIT("spawns.exit"), - SEEKER("spawns.seeker"); - - private final String path; - Locations(String path) { - this.path = path; - } - - public String message() { - return this + "_SPAWN"; - } - - public String path(String additive) { - return path + "." + additive; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java new file mode 100644 index 0000000..03c2a95 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java @@ -0,0 +1,54 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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.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 Add extends Command { + + 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 "add"; + } + + 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/map/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java deleted file mode 100644 index 55b4267..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -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.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 extends Command { - - 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 "add"; - } - - 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/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java new file mode 100644 index 0000000..2ec0525 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -0,0 +1,130 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import com.cryptomorin.xseries.XMaterial; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.PlayerLoader; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +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 extends Command { + + private static final Map>> debugMenuFunctions = new HashMap<>(); + + public void execute(Player sender, String[] args) { + 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 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(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addHider(player); + PlayerLoader.loadHider(player, map); + if(Main.getInstance().getGame().getStatus() != Status.STARTING) + PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); + })); + debugMenu.setItem(1, createOption(functions, 1, XMaterial.GOLDEN_CHESTPLATE.parseMaterial(), "&cBecome a &lSeeker", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addSeeker(player); + PlayerLoader.loadSeeker(player, map); + if(Main.getInstance().getGame().getStatus() != Status.STARTING) + PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); + })); + debugMenu.setItem(2, createOption(functions, 2, XMaterial.IRON_CHESTPLATE.parseMaterial(), "&8Become a &lSpectator", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addSpectator(player); + PlayerLoader.loadSpectator(player, map); + })); + 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(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(functions, 6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + player.teleport(map.getGameSpawn()); + })); + debugMenu.setItem(7, createOption(functions, 7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { + player.teleport(map.getLobby()); + })); + 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(functions, 10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + debugMenuFunctions.put(sender, functions); + return debugMenu; + } + + 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); + 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(player).get(slotId); + if(callback != null) callback.accept(player); + }, 0); + } + + public String getLabel() { + return "debug"; + } + + public String getUsage() { + 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/map/GoTo.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java new file mode 100644 index 0000000..8e74922 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java @@ -0,0 +1,63 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class GoTo extends Command { + + public void execute(Player sender, String[] args) { + 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").addAmount(map.getName())); + return; + } + switch (args[1].toLowerCase()) { + case "spawn": + sender.teleport(map.getSpawn()); break; + case "lobby": + sender.teleport(map.getLobby()); break; + case "seekerlobby": + sender.teleport(map.getSeekerLobby()); break; + case "exit": + sender.teleport(exitPosition); break; + default: + sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1].toLowerCase())); + } + } + + public String getLabel() { + return "goto"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Get the commands for 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()); + } else if(parameter != null && parameter.equals("spawn")) { + return Arrays.asList("spawn","lobby","seekerlobby","exit"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java new file mode 100644 index 0000000..635c011 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java @@ -0,0 +1,46 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.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 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 List extends Command { + + 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 "list"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "List all maps in the plugin"; + } + + public java.util.List autoComplete(String parameter) { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java deleted file mode 100644 index 79490a7..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.command.util.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 extends Command { - - 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 "list"; - } - - 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/map/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java new file mode 100644 index 0000000..45dec99 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java @@ -0,0 +1,53 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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 Remove extends Command { + + 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 "remove"; + } + + 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/map/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java deleted file mode 100644 index 216cca9..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -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 extends Command { - - 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 "remove"; - } - - 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/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java new file mode 100644 index 0000000..b93250f --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -0,0 +1,98 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +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; + +public class Save extends Command { + + public static boolean runningBackup = false; + + public void execute(Player sender, String[] args) { + if (!mapSaveEnabled) { + sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); + return; + } + 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.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + sender.sendMessage(messagePrefix + message("MAPSAVE_START")); + sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); + World world = map.getSpawn().getWorld(); + if (world == null) { + sender.sendMessage(warningPrefix + message("MAPSAVE_FAIL_WORLD")); + return; + } + world.save(); + BukkitRunnable runnable = new BukkitRunnable() { + public void run() { + sender.sendMessage( + map.getWorldLoader().save() + ); + runningBackup = false; + } + }; + runnable.runTaskAsynchronously(Main.getInstance()); + runningBackup = true; + } + + public String getLabel() { + return "save"; + } + + public String getUsage() { + return ""; + } + + 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/map/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java deleted file mode 100644 index f3eb4d7..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -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; - -public class SaveMap extends Command { - - public static boolean runningBackup = false; - - public void execute(Player sender, String[] args) { - if (!mapSaveEnabled) { - sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); - return; - } - 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.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - sender.sendMessage(messagePrefix + message("MAPSAVE_START")); - sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); - World world = map.getSpawn().getWorld(); - if (world == null) { - throw new RuntimeException("Unable to get spawn world"); - } - world.save(); - BukkitRunnable runnable = new BukkitRunnable() { - public void run() { - sender.sendMessage( - map.getWorldLoader().save() - ); - runningBackup = false; - } - }; - runnable.runTaskAsynchronously(Main.getInstance()); - runningBackup = true; - } - - public String getLabel() { - return "save"; - } - - public String getUsage() { - return ""; - } - - 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/map/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java deleted file mode 100644 index 8362e02..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -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.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; - -public class SetBorder extends Command { - - 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.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - if (args.length < 4) { - map.setWorldBorderData(0, 0, 0, 0, 0); - addToConfig("worldBorder.enabled",false); - saveConfig(); - sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); - Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); - return; - } - int num,delay,change; - try { num = Integer.parseInt(args[1]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); - return; - } - try { delay = Integer.parseInt(args[2]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); - return; - } - try { change = Integer.parseInt(args[3]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); - return; - } - if (num < 100) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); - return; - } - if (change < 1) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); - return; - } - map.setWorldBorderData( - sender.getLocation().getBlockX(), - sender.getLocation().getBlockZ(), - num, - delay, - change - ); - Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); - map.getWorldBorder().resetWorldBorder(); - } - - public String getLabel() { - return "border"; - } - - public String getUsage() { - 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/map/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java deleted file mode 100644 index 92bf5a4..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -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.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetBounds extends Command { - - 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.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - if (!sender.getWorld().getName().equals(map.getSpawnName())) { - sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); - return; - } - if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { - sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - boolean first = true; - int bxs = map.getBoundsMin().getBlockX(); - int bzs = map.getBoundsMin().getBlockZ(); - int bxl = map.getBoundsMax().getBlockX(); - int bzl = map.getBoundsMax().getBlockZ(); - if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { - bxs = bzs = bxl = bzl = 0; - } - if (bxl == 0) { - bxl = sender.getLocation().getBlockX(); - } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { - first = false; - bxs = bxl; - bxl = sender.getLocation().getBlockX(); - } else { - first = false; - bxs = sender.getLocation().getBlockX(); - } - if (bzl == 0) { - bzl = sender.getLocation().getBlockZ(); - } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { - first = false; - bzs = bzl; - bzl = sender.getLocation().getBlockZ(); - } else { - first = false; - bzs = sender.getLocation().getBlockZ(); - } - map.setBoundMin(bxs, bzs); - map.setBoundMax(bxl, bzl); - Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); - } - - public String getLabel() { - return "bounds"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - 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/map/SetMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java deleted file mode 100644 index 2df5824..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java +++ /dev/null @@ -1,67 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -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 extends Command { - - 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 "goto"; - } - - 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/map/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java deleted file mode 100644 index 46b41f7..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.entity.Player; - -import 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; - -public class Setup extends Command { - - public void execute(Player sender, String[] args) { - - String msg = message("SETUP").toString(); - int count = 0; - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { - msg = msg + "\n" + message("SETUP_GAME"); - count++; - } - if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { - msg = msg + "\n" + message("SETUP_LOBBY"); - count++; - } - if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !Map.worldExists(map.getSeekerLobbyName())) { - msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); - count++; - } - if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld)) { - msg = msg + "\n" + message("SETUP_EXIT"); - count++; - } - if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || - map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { - msg = msg + "\n" + message("SETUP_BOUNDS"); - count++; - } - if (mapSaveEnabled && !Map.worldExists(map.getGameSpawnName())) { - msg = msg + "\n" + message("SETUP_SAVEMAP"); - count++; - } - if (count < 1) { - sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); - } else { - sender.sendMessage(msg); - } - } - - public String getLabel() { - return "setup"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - 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/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java new file mode 100644 index 0000000..29442c1 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -0,0 +1,95 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Status extends Command { + + public void execute(Player sender, String[] args) { + + String msg = message("SETUP").toString(); + int count = 0; + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + msg = msg + "\n" + message("SETUP_GAME"); + count++; + } + if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + msg = msg + "\n" + message("SETUP_LOBBY"); + count++; + } + if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !Map.worldExists(map.getSeekerLobbyName())) { + msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); + count++; + } + if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld)) { + msg = msg + "\n" + message("SETUP_EXIT"); + count++; + } + if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || + map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { + msg = msg + "\n" + message("SETUP_BOUNDS"); + count++; + } + if (mapSaveEnabled && !Map.worldExists(map.getGameSpawnName())) { + msg = msg + "\n" + message("SETUP_SAVEMAP"); + count++; + } + if (count < 1) { + sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); + } else { + sender.sendMessage(msg); + } + } + + public String getLabel() { + return "status"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + 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/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java new file mode 100644 index 0000000..9d47390 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -0,0 +1,43 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt; + +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class Enabled extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "enabled"; + } + + public String getUsage() { + 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()); + } + if(parameter != null && parameter.equals("bool")) { + return Arrays.asList("true", "false"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java new file mode 100644 index 0000000..92339b4 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java @@ -0,0 +1,112 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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.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; + +public class Border extends Command { + + 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.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + if (args.length < 4) { + map.setWorldBorderData(0, 0, 0, 0, 0); + addToConfig("worldBorder.enabled",false); + saveConfig(); + sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); + Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); + return; + } + int num,delay,change; + try { num = Integer.parseInt(args[1]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + try { delay = Integer.parseInt(args[2]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); + return; + } + try { change = Integer.parseInt(args[3]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); + return; + } + if (num < 100) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); + return; + } + if (change < 1) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); + return; + } + map.setWorldBorderData( + sender.getLocation().getBlockX(), + sender.getLocation().getBlockZ(), + num, + delay, + change + ); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay).addAmount(change)); + map.getWorldBorder().resetWorldBorder(); + } + + public String getLabel() { + return "border"; + } + + public String getUsage() { + 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/map/set/Bounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java new file mode 100644 index 0000000..9896389 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java @@ -0,0 +1,112 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +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.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Bounds extends Command { + + 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.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + if (!sender.getWorld().getName().equals(map.getSpawnName())) { + sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); + return; + } + if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { + sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + boolean first = true; + int bxs = map.getBoundsMin().getBlockX(); + int bzs = map.getBoundsMin().getBlockZ(); + int bxl = map.getBoundsMax().getBlockX(); + int bzl = map.getBoundsMax().getBlockZ(); + if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { + bxs = bzs = bxl = bzl = 0; + } + if (bxl == 0) { + bxl = sender.getLocation().getBlockX(); + } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { + first = false; + bxs = bxl; + bxl = sender.getLocation().getBlockX(); + } else { + first = false; + bxs = sender.getLocation().getBlockX(); + } + if (bzl == 0) { + bzl = sender.getLocation().getBlockZ(); + } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { + first = false; + bzs = bzl; + bzl = sender.getLocation().getBlockZ(); + } else { + first = false; + bzs = sender.getLocation().getBlockZ(); + } + map.setBoundMin(bxs, bzs); + map.setBoundMax(bxl, bzl); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); + } + + public String getLabel() { + return "bounds"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + 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/map/set/Lobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java new file mode 100644 index 0000000..c691787 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java @@ -0,0 +1,58 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +public class Lobby extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "lobby"; + } + + public String getUsage() { + 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/map/set/SeekerLobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java new file mode 100644 index 0000000..2521f19 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java @@ -0,0 +1,47 @@ +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SeekerLobby extends Command { + + 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()); + }); + } + + public String getLabel() { + return "seekerlobby"; + } + + public String getUsage() { + 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/map/set/Spawn.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java new file mode 100644 index 0000000..3e8f77e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java @@ -0,0 +1,79 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.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; + +public class Spawn extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { + + if (map.isWorldBorderEnabled() && + new Vector(sender.getLocation().getX(), 0, sender.getLocation().getZ()).distance(map.getWorldBorderPos()) > 100) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); + throw new RuntimeException("World border not enabled or not in valid position!"); + } + + map.setSpawn(sender.getLocation()); + + 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(); + } + }); + } + + public String getLabel() { + return "spawn"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + 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/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index 9079ccc..e7f43eb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -20,7 +20,8 @@ package net.tylermurphy.hideAndSeek.command.util; import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.command.map.SaveMap; +import net.tylermurphy.hideAndSeek.command.map.Save; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -38,7 +39,7 @@ public class CommandGroup { public CommandGroup(String label, Object... data) { this.label = label; - this.commandRegister = new HashMap<>(); + this.commandRegister = new LinkedHashMap<>(); for(Object o : data) registerCommand(o); } @@ -65,11 +66,15 @@ public class CommandGroup { if (permissionsRequired && !player.hasPermission("hs.about")) { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { - new About().execute(player, null); + player.sendMessage( + 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) + ); } } else { String invoke = args[0].toLowerCase(); - if (!invoke.equals("about") && !invoke.equals("help") && SaveMap.runningBackup) { + if (!invoke.equals("about") && !invoke.equals("help") && Save.runningBackup) { player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); } else if (permissionsRequired && !player.hasPermission(permission+"."+invoke)) { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 3a43e15..0000c30 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -101,7 +101,6 @@ public class Config { lobbyItemStartPosition, flightToggleItemPosition, teleportItemPosition, - solidifyTime, delayedRespawnDelay; public static float @@ -113,24 +112,6 @@ public class Config { blockedCommands, blockedInteracts; - public static String - LOBBY_TITLE, - GAME_TITLE, - COUNTDOWN_WAITING, - COUNTDOWN_COUNTING, - COUNTDOWN_ADMINSTART, - TAUNT_COUNTING, - TAUNT_ACTIVE, - TAUNT_EXPIRED, - GLOW_ACTIVE, - GLOW_INACTIVE, - BORDER_COUNTING, - BORDER_DECREASING; - - public static List - LOBBY_CONTENTS, - GAME_CONTENTS; - public static ItemStack lobbyLeaveItem, lobbyStartItem, @@ -152,7 +133,6 @@ public class Config { config = ConfigManager.create("config.yml"); config.saveConfig(); - ConfigManager leaderboard = ConfigManager.create("leaderboard.yml"); announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers"); @@ -247,25 +227,6 @@ public class Config { } bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy"); leaveServer = config.getString("leaveServer"); - solidifyTime = Math.max(20,config.getInt("blockhunt.solidifyTime")); - - //Leaderboard - LOBBY_TITLE = leaderboard.getString("lobby.title"); - GAME_TITLE = leaderboard.getString("game.title"); - LOBBY_CONTENTS = leaderboard.getStringList("lobby.content"); - Collections.reverse(LOBBY_CONTENTS); - GAME_CONTENTS = leaderboard.getStringList("game.content"); - Collections.reverse(GAME_CONTENTS); - COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting"); - COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting"); - COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart"); - TAUNT_COUNTING = leaderboard.getString("taunt.counting"); - TAUNT_ACTIVE = leaderboard.getString("taunt.active"); - TAUNT_EXPIRED = leaderboard.getString("taunt.expired"); - GLOW_ACTIVE = leaderboard.getString("glow.active"); - GLOW_INACTIVE = leaderboard.getString("glow.inactive"); - BORDER_COUNTING = leaderboard.getString("border.counting"); - BORDER_DECREASING = leaderboard.getString("border.decreasing"); //Lobby Items if (config.getBoolean("lobbyItems.leave.enabled")) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index e09001e..b7671c2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -93,6 +93,7 @@ public class ConfigManager { try { this.config.load(reader); } catch(InvalidConfigurationException e) { + Main.getInstance().getLogger().severe(e.getMessage()); throw new RuntimeException("Invalid configuration in config file: "+file.getPath()); } catch(IOException e) { throw new RuntimeException("Could not access file: "+file.getPath()); @@ -107,9 +108,10 @@ public class ConfigManager { try { this.defaultConfig.load(default_reader); } catch(InvalidConfigurationException e) { - throw new RuntimeException("Invalid configuration in config file: "+file.getPath()); + Main.getInstance().getLogger().severe(e.getMessage()); + throw new RuntimeException("Invalid configuration in internal config file: "+defaultFilename); } catch(IOException e) { - throw new RuntimeException("Could not access file: "+file.getPath()); + throw new RuntimeException("Could not access internal file: "+defaultFilename); } try{ @@ -240,69 +242,110 @@ public class ConfigManager { public void saveConfig() { try { + // open config file InputStream is = Main.getInstance().getResource(defaultFilename); + // if failed error if (is == null) { throw new RuntimeException("Could not create input stream for "+defaultFilename); } + // manually read in each character to preserve string data StringBuilder textBuilder = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); Reader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); int c; - while((c = reader.read()) != -1) { + while((c = reader.read()) != -1) textBuilder.append((char) c); - } - String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8); - Map temp = config.getValues(true); - for(Map.Entry entry: temp.entrySet()) { - if (entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List) { - String[] parts = entry.getKey().split("\\."); - int index = 0; - int i = 0; - for(String part : parts) { - if (i == 0) { - index = yamlString.indexOf(part+":", index); - } else { - index = yamlString.indexOf(" " + part+":", index); - index++; - } - i++; - if (index == -1) break; - } - if (index < 10) continue; - int start = yamlString.indexOf(' ', index); - int end = yamlString.indexOf('\n', index); - if (end == -1) end = yamlString.length(); - StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); - if (entry.getValue() instanceof List) { - if (((List) entry.getValue()).isEmpty()) { - replace.append("[]"); - } else { - replace.append("["); - for (Object o : (List) entry.getValue()) { - replace.append(o.toString()).append(", "); - } - replace = new StringBuilder(replace.substring(0, replace.length() - 2)); - replace.append("]"); - } + // store yaml file into a string + String yaml = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8); + // get config values + Map data = config.getValues(true); + // write each stored config value into the yaml string + for(Map.Entry entry: data.entrySet()) { + // if type isn't supported, skip + if(!isSupported(entry.getValue())) continue; + // get index of key in yaml string + int index = getIndex(yaml, entry.getKey()); + // if index not found, skip + if (index < 10) continue; + // get start and end of the value + int start = yaml.indexOf(' ', index) + 1; + int end = yaml.indexOf('\n', index); + // if end not found, set it to the end of the file + if (end == -1) end = yaml.length(); + // create new replace sting + StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); + // get value + Object value = entry.getValue(); + // if the value is a list, + if (value instanceof List) { + end = yaml.indexOf(']', start) + 1; + List list = (List) entry.getValue(); + if (list.isEmpty()) { + // if list is empty, put an empty list + replace.append("[]"); } else { - replace.append(entry.getValue()); - } - if (entry.getValue() instanceof String) { - replace.append("\""); - replace.reverse(); - replace.append("\""); - replace.reverse(); + // if list has values, populate values into the string + // get gap before key + int gap = whitespaceBefore(yaml, index); + String space = new String(new char[gap]).replace('\0', ' '); + replace.append("[\n"); + for (int i = 0; i < list.size(); i++) { + replace.append(space).append(" ").append(convert(list.get(i))); + if(i != list.size() -1) replace.append(",\n"); + } + replace.append('\n').append(space).append("]"); } - StringBuilder builder = new StringBuilder(yamlString); - builder.replace(start+1, end, replace.toString()); - yamlString = builder.toString(); + // otherwise just put the value directly + } else { + replace.append(convert(value)); } + // replace the new value in the yaml string + StringBuilder builder = new StringBuilder(yaml); + builder.replace(start, end, replace.toString()); + yaml = builder.toString(); } + + // write yaml string to file Writer fileWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8)); - fileWriter.write(yamlString); + fileWriter.write(yaml); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } } + private int getIndex(String yaml, String key) { + String[] parts = key.split("\\."); + int index = 0; + for(String part : parts) { + if (index == 0) { + index = yaml.indexOf(part + ":", index); + } else { + index = yaml.indexOf(" " + part + ":", index) + 1; + } + if (index == -1) break; + } + return index; + } + + public boolean isSupported(Object o) { + return o instanceof Integer || + o instanceof Double || + o instanceof String || + o instanceof Boolean || + o instanceof List; + } + + public int whitespaceBefore(String yaml, int index) { + int count = 0; + for(int i = index - 1; yaml.charAt(i) == ' '; i--) count++; + return count; + } + + private String convert(Object o) { + if(o instanceof String) { + return "\"" + o + "\""; + } + return o.toString(); + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java new file mode 100644 index 0000000..63dc850 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java @@ -0,0 +1,51 @@ +package net.tylermurphy.hideAndSeek.configuration; + +import java.util.Collections; +import java.util.List; + +public class Leaderboard { + + public static String + LOBBY_TITLE, + GAME_TITLE, + COUNTDOWN_WAITING, + COUNTDOWN_COUNTING, + COUNTDOWN_ADMINSTART, + TAUNT_COUNTING, + TAUNT_ACTIVE, + TAUNT_EXPIRED, + GLOW_ACTIVE, + GLOW_INACTIVE, + BORDER_COUNTING, + BORDER_DECREASING; + + public static List + LOBBY_CONTENTS, + GAME_CONTENTS; + + public static void loadLeaderboard() { + + ConfigManager leaderboard = ConfigManager.create("leaderboard.yml"); + + LOBBY_TITLE = leaderboard.getString("lobby.title"); + GAME_TITLE = leaderboard.getString("game.title"); + LOBBY_CONTENTS = leaderboard.getStringList("lobby.content"); + Collections.reverse(LOBBY_CONTENTS); + GAME_CONTENTS = leaderboard.getStringList("game.content"); + Collections.reverse(GAME_CONTENTS); + COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting"); + COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting"); + COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart"); + TAUNT_COUNTING = leaderboard.getString("taunt.counting"); + TAUNT_ACTIVE = leaderboard.getString("taunt.active"); + TAUNT_EXPIRED = leaderboard.getString("taunt.expired"); + GLOW_ACTIVE = leaderboard.getString("glow.active"); + GLOW_INACTIVE = leaderboard.getString("glow.inactive"); + BORDER_COUNTING = leaderboard.getString("border.counting"); + BORDER_DECREASING = leaderboard.getString("border.decreasing"); + + leaderboard.saveConfig(); + + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 9418414..72ab366 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -31,7 +31,7 @@ public class Localization { public static final Map DEFAULT_LOCAL = new HashMap<>(); private static final Map CHANGES = new HashMap() {{ - put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"}}); + put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"},{"GAME_SETUP"}}); put("de-DE", new String[][]{{},{"TAUNTED"}}); }}; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 18cad40..83fc2a6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -33,6 +33,7 @@ import java.util.*; import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Leaderboard.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Board { @@ -218,7 +219,9 @@ public class Board { } else if (line.contains("{SEEKER%}")) { board.setLine(String.valueOf(i), line.replace("{SEEKER%}", getSeekerPercent()+"")); } else if (line.contains("{HIDER%}")) { - board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent()+"")); + board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent() + "")); + } else if (line.contains("{MAP}")) { + board.setLine(String.valueOf(i), line.replace("{MAP}", getMapName() + "")); } else { board.setLine(String.valueOf(i), line); } @@ -228,6 +231,12 @@ public class Board { customBoards.put(player.getUniqueId().toString(), board); } + public String getMapName() { + net.tylermurphy.hideAndSeek.configuration.Map map = Main.getInstance().getGame().getCurrentMap(); + if(map == null) return "Invalid"; + else return map.getName(); + } + public void createGameBoard(Player player) { createGameBoard(player, true); } @@ -288,6 +297,8 @@ public class Board { board.setLine(String.valueOf(i), line.replace("{#SEEKER}", getSeekers().size()+"")); } else if (line.contains("{#HIDER}")) { board.setLine(String.valueOf(i), line.replace("{#HIDER}", getHiders().size()+"")); + } else if (line.contains("{MAP}")) { + board.setLine(String.valueOf(i), line.replace("{MAP}", getMapName() + "")); } else { board.setLine(String.valueOf(i), line); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java index dabb735..5fce7d3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java @@ -1,6 +1,7 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.game.util.Disguise; @@ -49,7 +50,7 @@ public class Disguiser { public void disguise(Player player, Material material, Map map){ if(!map.isBlockHuntEnabled()){ - player.sendMessage(errorPrefix + "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8"); + player.sendMessage(errorPrefix + message("BLOCKHUNT_DISABLED")); return; } if(disguises.containsKey(player)){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java index 27a6235..27347c2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java @@ -11,7 +11,7 @@ public class ChatHandler implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onChat(AsyncPlayerChatEvent event) { - if (Main.getInstance().getBoard().isSeeker(event.getPlayer())) { + if (Main.getInstance().getBoard().isSpectator(event.getPlayer())) { event.setCancelled(true); Main.getInstance().getBoard().getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage())); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java index cb8ad04..c80e83f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java @@ -1,7 +1,6 @@ package net.tylermurphy.hideAndSeek.game.listener; import static com.comphenix.protocol.PacketType.Play.Client.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.solidifyTime; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; @@ -42,7 +41,7 @@ public class DisguiseHandler implements Listener { if(lastLocation.getWorld() != currentLocation.getWorld()) return; double distance = lastLocation.distance(currentLocation); disguise.setSolidify(distance < .1); - }, solidifyTime); + }, 20 * 3); if(event.getFrom().distance(event.getTo()) > .1) disguise.setSolidify(false); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java index 2439b2b..af915e2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java @@ -19,11 +19,9 @@ package net.tylermurphy.hideAndSeek.game.listener; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.Debug; +import net.tylermurphy.hideAndSeek.command.map.Debug; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 322519a..d4deafe 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -75,7 +75,7 @@ public class WorldLoader { public String save() { World world = Bukkit.getServer().getWorld(map.getSpawnName()); if(world == null){ - return errorPrefix + "Invalid world to save: " + map.getSpawnName(); + return errorPrefix + message("MAPSAVE_INVALID").addAmount(map.getSpawnName()); } File current = new File(Main.getInstance().getWorldContainer()+File.separator+ map.getSpawnName()); if (current.exists()) { @@ -94,7 +94,7 @@ public class WorldLoader { } if (!temp_destination.renameTo(destination)) { - return errorPrefix + "Failed to rename directory: " + temp_destination.getPath(); + return errorPrefix + message("MAPSAVE_FAIL_DIR").addAmount(temp_destination.getPath()); } } catch(IOException e) { e.printStackTrace(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6463898..389352a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -15,23 +15,23 @@ gameLength: 1200 announceMessagesToNonPlayers: true # When the game is starting, the plugin will state there is x seconds left to hide. -# You change where countdown messages to be displayed: in the chat, action bar, or a title. +# You change where countdown messages are to be displayed: in the chat, action bar, or a title. # Below you can set CHAT, ACTIONBAR, or TITLE. Any invalid option will revert to CHAT. # -# CHAT - Messages will be displayed in the chat +# CHAT - Staring messages will be displayed in the chat # -# ACTIONBAR - Messages will be displayed in the action bar (area above the hotbar) +# ACTIONBAR - Staring messages will be displayed in the action bar (area above the hotbar) # -# TITLE - Messages will be displayed as a title +# TITLE - Staring messages will be displayed as a title # # default: CHAT -hideCountdownDisplay: CHAT +hideCountdownDisplay: "CHAT" # Allow Hiders to see their own teams nametags as well as seekers. Seekers can never see nametags regardless. # default: false nametagsVisible: false -# Require bukkit permissions though a plugin to run commands, recommended on large servers +# Require bukkit permissions though a permissions plugin to run commands, or require op, recommended on most servers # default: true permissionsRequired: true @@ -80,11 +80,11 @@ leaveOnEnd: false # PROXY - Send the player to a specified server in a bungee-cord / velocity setup. # # default: EXIT -leaveType: EXIT +leaveType: "EXIT" # Ignore this setting if you aren't using the PROXY leave type method above. If you are, set this to the server you want to send # players too. -leaveServer: hub +leaveServer: "hub" # By default, the plugin forces you to use a map save to protect from changes to a map thought a game play though. It copies your # hide-and-seek world to a separate world, and loads the game there to contain the game in an isolated and backed up map This allows you to @@ -117,40 +117,16 @@ delayedRespawn: # MYSQL - Uses a mysql server to store data, good for multi-server setups or large servers. # # default: SQLITE -databaseType: SQLITE +databaseType: "SQLITE" # The following settings are used for MYSQL databases ONLY. If you are running SQLITE, these # will be ignored. If you are running MYSQL, you need to provide the database host url, database # host port (usually 3306), database username, and database password. -databaseHost: localhost +databaseHost: "localhost" databasePort: 3306 -databaseUser: root -databasePass: -databaseName: hideandseek - -# The world border closes every interval, which is evey [delay] in minutes. -# Thw world border starts at [size], and decreases 100 blocks every interval. -# x & z are the center location. [enabled] is whenever the border is enabled. -# You can choose if Hiders are warned 30 seconds before the border moves. - -# You want block hunt? We have block hunt! Just enable it below, and set the -# available blocks to pick from, and you're all set! It's that easy! -# Items are displayed in the order that they are listed below. -# The solidifyTime is the time in server ticks that it takes players to solidify. -# Every 20 ticks is a second. Minimum solidifyTime is 20 ticks. -blockhunt: - enabled: false - solidifyTime: 60 - blocks: [CRAFTING_TABLE, GRASS_BLOCK, DIRT, BEACON, BOOKSHELF] - -worldBorder: - x: 0 - z: 0 - delay: 10 - size: 500 - moveAmount: 100 - warn: true - enabled: false +databaseUser: "root" +databasePass: "pass" +databaseName: "hideandseek" # The taunt will activate every delay set in seconds. It will spawn a firework # on a random Hider to alert a Seeker where someone may be. You can choose @@ -173,8 +149,12 @@ glow: stackable: true enabled: true name: "Glow Powerup" - lore: [ "Throw to make all seekers glow", "Last 30s, all hiders can see it", "Time stacks on multi use" ] - material: SNOWBALL + lore: [ + "Throw to make all seekers glow", + "Last 30s, all hiders can see it", + "Time stacks on multi use" + ] + material: "SNOWBALL" model-data: 0 # This has the same glow effect as the glow powerup in that all seekers positions get @@ -221,14 +201,16 @@ lobby: # If you set adminOnly to false, only the item will become non admin only, not the command. lobbyItems: leave: - material: BED + material: "BED" name: "&cLeave Lobby" - lore: ["Go back to server hub"] + lore: [ + "Go back to server hub" + ] position: 8 model-data: 0 enabled: true start: - material: CLOCK + material: "CLOCK" name: "&bStart Game" lore: [] position: 0 @@ -241,15 +223,19 @@ lobbyItems: # and position of the item. You can also change the model data if your server is running 1.14 or above. spectatorItems: flight: - material: FEATHER + material: "FEATHER" name: "&bToggle Flight" - lore: [ "Turns flying on and off" ] + lore: [ + "Turns flying on and off" + ] position: 3 model-data: 0 teleport: - material: COMPASS + material: "COMPASS" name: "&bTeleport to Others" - lore: [ "Allows you to teleport to all other players in game" ] + lore: [ + "Allows you to teleport to all other players in game" + ] position: 5 model-data: 0 @@ -265,8 +251,8 @@ seekerPing: leadingVolume: 0.5 volume: 0.3 pitch: 1 - heartbeatNoise: BLOCK_NOTE_BLOCK_BASEDRUM - ringingNoise: BLOCK_NOTE_BLOCK_PLING + heartbeatNoise: "BLOCK_NOTE_BLOCK_BASEDRUM" + ringingNoise: "BLOCK_NOTE_BLOCK_PLING" enabled: true # Changes the default plugin language. Currently, Supported localizations are: @@ -275,26 +261,37 @@ seekerPing: locale: "en-US" # Stop commands being run by any user while playing the game. -# Can be usefull If you aren't using a permission plugin and want +# Can be usefull If you aren't using a permission plugin and don't want # to op people, but still want to block certain commands. # Not really usefully if using permission plugins. # You can add /kill for any use, but it's already blocked on those # playing the game. -blockedCommands: [msg, tp, gamemode, kill, give, effect] +blockedCommands: [ + "msg", + "tp", + "gamemode", + "kill", + "give", + "effect" +] # Stop interactions with any block by any user while playing the game. # If your map has things such as chests for aesthetic only, you can # block the use of clicking them. It shouldn't matter what version of # the block ID you enter, as the plugin will automatically switch to the # block ID of your current Minecraft server version. -blockedInteracts: [FURNACE, CRAFTING_TABLE, ANVIL, CHEST, BARREL] -# ---------------------------------------------------------- # -# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # -# ---------------------------------------------------------- # +blockedInteracts: [ + "FURNACE", + "CRAFTING_TABLE", + "ANVIL", + "CHEST", + "BARREL" +] # Location where players are teleported when they exit (/hs leave) +# Auto filled by /hs setexit, so you don't need to touch this here exit: x: 0 y: 0 z: 0 - world: world \ No newline at end of file + world: "world" \ No newline at end of file diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 91d7abe..53f86be 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -10,6 +10,7 @@ Localization: COMMAND_PLAYER_ONLY: "This command can only be run as a player." COMMAND_NOT_ALLOWED: "You are not allowed to run this command." COMMAND_ERROR: "An internal error has occurred." + COMMAND_INVALID_ARG: "Invalid argument: {AMOUNT}" GAME_PLAYER_DEATH: "&c{PLAYER}&f was killed." GAME_PLAYER_FOUND: "&e{PLAYER}&f was found and became a seeker." GAME_PLAYER_FOUND_BY: "&e{PLAYER}&f was found by &c{PLAYER}&f and became a seeker." @@ -17,7 +18,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: "There are no setup maps! Run /hs setup on a map to see what you need to do." + GAME_SETUP: "There are no setup maps! Run /hs map status 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." @@ -32,6 +33,9 @@ Localization: MAPSAVE_END: "Map save complete." MAPSAVE_ERROR: "Couldn't find current map." MAPSAVE_DISABLED: "Mapsave is disabled in config.yml." + MAPSAVE_FAIL_WORLD: "Mapsave failed. Failed to load current world." + MAPSAVE_INVALID: "Invalid world to save: {AMOUNT}" + MAPSAVE_FAIL_DIR: "Failed to rename directory: {AMOUNT}" WORLDBORDER_DISABLE: "Disabled world border." WORLDBORDER_INVALID_INPUT: "Invalid integer {AMOUNT}." WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks." @@ -58,6 +62,7 @@ Localization: SEEKER_SPAWN: "Set seeker lobby position to current location" START_MIN_PLAYERS: "You must have at least {AMOUNT} players to start." START_INVALID_NAME: "Invalid player: {PLAYER}." + START_FAILED_SEEKER: "Failed to select random seeker." START_COUNTDOWN: "Hiders have {AMOUNT} seconds to hide!" START_COUNTDOWN_LAST: "Hiders have {AMOUNT} second to hide!" START: "Attention SEEKERS, its time to find the hiders!" @@ -77,9 +82,9 @@ 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!!" + 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" + 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}" @@ -88,9 +93,11 @@ Localization: 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" + 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." + CONFIG_ERROR: "Error reloading config. Check server logs." + BLOCKHUNT_DISABLED: "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE -version: 3 +version: 4 type: "en-US" \ No newline at end of file diff --git a/src/main/resources/leaderboard.yml b/src/main/resources/leaderboard.yml index 9c7a777..cd958a3 100644 --- a/src/main/resources/leaderboard.yml +++ b/src/main/resources/leaderboard.yml @@ -16,6 +16,7 @@ # {COUNT} - The amount of player currently in the lobby. # {SEEKER%} - The chance that a player will be selected to be a seeker. # {HIDER%} - The chance that a player will be selected to be a hider. +# {MAP} - The current map the player is on # # GAME BOARD PLACEHOLDERS # @@ -38,6 +39,7 @@ # only Hiders will be able to see its effects though. # {#SEEKER} - Number of current seekers. # {#HIDER} - Number of current hiders. +# {MAP} - The current map the player is on # # YOU CANNOT USE TWO PLACEHOLDERS ON THE SAME LINE. ONLY THE FIRST ONE WILL # BE CHANGED, AND THE SECOND ONE WILL SAY A PLACEHOLDER MARKER! @@ -50,12 +52,15 @@ lobby: "Players: {COUNT}", "", "&cSEEKER % &f{SEEKER%}", - "&6HIDER % &f{HIDER%}" + "&6HIDER % &f{HIDER%}", + "", + "Map: {MAP}", ] game: title: "&eHIDE AND SEEK" content: [ + "Map: {MAP}", "Team: {TEAM}", "", "Time Left: &a{TIME}", -- cgit v1.2.3-freya From 37b3840ca163a1824d3799bcf14bb62173157ece Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 2 Nov 2022 13:38:22 -0400 Subject: 1.7.0 beta 3 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 12 +++- .../tylermurphy/hideAndSeek/command/map/Debug.java | 20 ++----- .../tylermurphy/hideAndSeek/command/map/Save.java | 4 ++ .../hideAndSeek/command/map/Status.java | 16 ++--- .../hideAndSeek/command/map/blockhunt/Enabled.java | 29 +++++++-- .../command/map/blockhunt/blocks/Add.java | 68 ++++++++++++++++++++++ .../command/map/blockhunt/blocks/List.java | 54 +++++++++++++++++ .../command/map/blockhunt/blocks/Remove.java | 68 ++++++++++++++++++++++ .../hideAndSeek/command/util/CommandGroup.java | 2 +- .../hideAndSeek/configuration/Config.java | 24 ++++---- .../hideAndSeek/configuration/ConfigManager.java | 2 + .../hideAndSeek/configuration/Localization.java | 11 +++- .../tylermurphy/hideAndSeek/configuration/Map.java | 38 +++++++++--- .../hideAndSeek/configuration/Maps.java | 9 ++- .../net/tylermurphy/hideAndSeek/game/Game.java | 2 +- .../game/listener/InventoryHandler.java | 6 +- src/main/resources/lang/localization_en-US.yml | 23 +++++--- 17 files changed, 324 insertions(+), 64 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index b1e2a83..4646e57 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -21,6 +21,7 @@ package net.tylermurphy.hideAndSeek; import net.tylermurphy.hideAndSeek.command.*; import net.tylermurphy.hideAndSeek.command.map.*; +import net.tylermurphy.hideAndSeek.command.map.blockhunt.Enabled; import net.tylermurphy.hideAndSeek.command.map.set.*; import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.database.Database; @@ -87,6 +88,14 @@ public class Main extends JavaPlugin implements Listener { new Start(), new Stop(), new CommandGroup("map", + new CommandGroup("blockhunt", + new CommandGroup("blocks", + new net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks.Add(), + new net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks.Remove(), + new net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks.List() + ), + new Enabled() + ), new CommandGroup("set", new Lobby(), new Spawn(), @@ -99,7 +108,8 @@ public class Main extends JavaPlugin implements Listener { new List(), new Status(), new Save(), - new Debug() + new Debug(), + new GoTo() ), new SetExitLocation(), new Top(), diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java index 2ec0525..4adb806 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -74,20 +74,12 @@ public class Debug extends Command { player.setHealth(0.1); } })); - debugMenu.setItem(6, createOption(functions, 6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - player.teleport(map.getGameSpawn()); - })); - debugMenu.setItem(7, createOption(functions, 7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { - player.teleport(map.getLobby()); - })); - 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(functions, 10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + if(map.isBlockHuntEnabled()) { + debugMenu.setItem(9, createOption(functions, 7, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { + PlayerLoader.openBlockHuntPicker(player, map); + })); + debugMenu.setItem(10, createOption(functions, 8, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + } debugMenuFunctions.put(sender, functions); return debugMenu; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java index b93250f..1f95df3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -56,6 +56,10 @@ public class Save extends Command { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } + if (map.isBoundsNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_MAP_BOUNDS")); + return; + } sender.sendMessage(messagePrefix + message("MAPSAVE_START")); sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); World world = map.getSpawn().getWorld(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java index 29442c1..d9dd8fb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -41,31 +41,33 @@ public class Status extends Command { sender.sendMessage(errorPrefix + message("INVALID_MAP")); return; } - if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || Map.worldDoesntExist(map.getLobbyName())) { msg = msg + "\n" + message("SETUP_GAME"); count++; } - if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || Map.worldDoesntExist(map.getLobbyName())) { msg = msg + "\n" + message("SETUP_LOBBY"); count++; } - if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !Map.worldExists(map.getSeekerLobbyName())) { + if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || Map.worldDoesntExist(map.getSeekerLobbyName())) { msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); count++; } - if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld)) { + if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || Map.worldDoesntExist(exitWorld)) { msg = msg + "\n" + message("SETUP_EXIT"); count++; } - if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || - map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { + if (map.isBoundsNotSetup()) { msg = msg + "\n" + message("SETUP_BOUNDS"); count++; } - if (mapSaveEnabled && !Map.worldExists(map.getGameSpawnName())) { + if (mapSaveEnabled && Map.worldDoesntExist(map.getGameSpawnName())) { msg = msg + "\n" + message("SETUP_SAVEMAP"); count++; } + if (map.isBlockHuntEnabled() && map.getBlockHunt().isEmpty()) { + msg = msg + "\n" + message("SETUP_BLOCKHUNT"); + } if (count < 1) { sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); } else { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java index 9d47390..b8d2e15 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -1,21 +1,38 @@ package net.tylermurphy.hideAndSeek.command.map.blockhunt; -import net.tylermurphy.hideAndSeek.command.location.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.util.Arrays; 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 Enabled extends Command { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { - map.setLobby(sender.getLocation()); - }); + 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; + } + boolean bool = Boolean.parseBoolean(args[1]); + map.setBlockhunt(bool, map.getBlockHunt()); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BLOCKHUNT_SET_TO") + .addAmount(bool ? ChatColor.GREEN + "true" : ChatColor.RED + "false") + ChatColor.WHITE); } public String getLabel() { @@ -27,7 +44,7 @@ public class Enabled extends Command { } public String getDescription() { - return "Sets hide and seeks lobby location to current position"; + return "Sets blockhunt enabled or disabled in a current map"; } public List autoComplete(String parameter) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java new file mode 100644 index 0000000..021dae0 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java @@ -0,0 +1,68 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Arrays; +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 Add extends Command { + + 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; + } + Material block; + try { block = Material.valueOf(args[1]); } + catch (IllegalArgumentException e) { + sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1])); + return; + } + List blocks = map.getBlockHunt(); + if(blocks.contains(block)) { + sender.sendMessage(errorPrefix + message("BLOCKHUNT_BLOCK_EXISTS").addAmount(args[1])); + } + blocks.add(block); + map.setBlockhunt(map.isBlockHuntEnabled(), blocks); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BLOCKHUNT_BLOCK_ADDED").addAmount(args[1])); + } + + public String getLabel() { + return "add"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Add a blockhunt block to a map!"; + } + + 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()); + } else if(parameter != null && parameter.equals("block")) { + return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList()); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java new file mode 100644 index 0000000..ecb626f --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java @@ -0,0 +1,54 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; + +import org.bukkit.Material; +import org.bukkit.entity.Player; + +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 List extends Command { + + public void execute(Player sender, String[] args) { + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + java.util.List blocks = map.getBlockHunt(); + if(blocks.isEmpty()) { + sender.sendMessage(errorPrefix + message("NO_BLOCKS")); + return; + } + StringBuilder response = new StringBuilder(messagePrefix + message("BLOCKHUNT_LIST_BLOCKS")); + for(int i = 0; i < blocks.size(); i++) { + response.append(String.format("\n%s. %s", i, blocks.get(i).toString())); + } + sender.sendMessage(response.toString()); + } + + public String getLabel() { + return "list"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "List all blockhunt blocks in a map"; + } + + public java.util.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/map/blockhunt/blocks/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java new file mode 100644 index 0000000..7bbd5d3 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java @@ -0,0 +1,68 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Arrays; +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 Remove extends Command { + + 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; + } + Material block; + try { block = Material.valueOf(args[1]); } + catch (IllegalArgumentException e) { + sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1])); + return; + } + java.util.List blocks = map.getBlockHunt(); + if(!blocks.contains(block)) { + sender.sendMessage(errorPrefix + message("BLOCKHUNT_BLOCK_DOESNT_EXIT").addAmount(args[1])); + } + blocks.remove(block); + map.setBlockhunt(map.isBlockHuntEnabled(), blocks); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BLOCKHUNT_BLOCK_REMOVED").addAmount(args[1])); + } + + public String getLabel() { + return "remove"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Remove a blockhunt block from a map!"; + } + + 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()); + } else if(parameter != null && parameter.equals("block")) { + return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index e7f43eb..32f4081 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -67,7 +67,7 @@ public class CommandGroup { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { player.sendMessage( - 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("%s%sHide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 0000c30..ee7aa18 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -137,16 +137,16 @@ public class Config { announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers"); //Prefix - char SYMBOLE = '\u00A7'; - String SYMBOLE_STRING = String.valueOf(SYMBOLE); + char SYMBOL = '\u00A7'; + String SYMBOL_STRING = String.valueOf(SYMBOL); - messagePrefix = config.getString("prefix.default").replace("&", SYMBOLE_STRING); - errorPrefix = config.getString("prefix.error").replace("&", SYMBOLE_STRING); - tauntPrefix = config.getString("prefix.taunt").replace("&", SYMBOLE_STRING); - worldBorderPrefix = config.getString("prefix.border").replace("&", SYMBOLE_STRING); - abortPrefix = config.getString("prefix.abort").replace("&", SYMBOLE_STRING); - gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOLE_STRING); - warningPrefix = config.getString("prefix.warning").replace("&", SYMBOLE_STRING); + messagePrefix = config.getString("prefix.default").replace("&", SYMBOL_STRING); + errorPrefix = config.getString("prefix.error").replace("&", SYMBOL_STRING); + tauntPrefix = config.getString("prefix.taunt").replace("&", SYMBOL_STRING); + worldBorderPrefix = config.getString("prefix.border").replace("&", SYMBOL_STRING); + abortPrefix = config.getString("prefix.abort").replace("&", SYMBOL_STRING); + gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOL_STRING); + warningPrefix = config.getString("prefix.warning").replace("&", SYMBOL_STRING); // Locations exitPosition = new Location( @@ -211,8 +211,7 @@ public class Config { try { countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay")); } catch (IllegalArgumentException e) { - countdownDisplay = CountdownDisplay.CHAT; - Main.getInstance().getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!"); + throw new RuntimeException("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+", is not a valid configuration option!"); } blockedInteracts = new ArrayList<>(); List tempInteracts = config.getStringList("blockedInteracts"); @@ -255,8 +254,7 @@ public class Config { databaseType = config.getString("databaseType").toUpperCase(); if(!databaseType.equals("SQLITE") && !databaseType.equals("MYSQL")){ - Main.getInstance().getLogger().warning("databaseType: "+databaseType+" is not a valid configuration option!"); - databaseType = "SQLITE"; + throw new RuntimeException("databaseType: "+databaseType+" is not a valid configuration option!"); } delayedRespawn = config.getBoolean("delayedRespawn.enabled"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index b7671c2..eda8470 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -344,6 +344,8 @@ public class ConfigManager { private String convert(Object o) { if(o instanceof String) { return "\"" + o + "\""; + } else if (o instanceof Boolean) { + return (boolean)o ? "true" : "false"; } return o.toString(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 72ab366..6f3f88b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -31,8 +31,15 @@ public class Localization { public static final Map DEFAULT_LOCAL = new HashMap<>(); private static final Map CHANGES = new HashMap() {{ - put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"},{"GAME_SETUP"}}); - put("de-DE", new String[][]{{},{"TAUNTED"}}); + put("en-US", new String[][]{ + {"WORLDBORDER_DECREASING"}, + {"START","TAUNTED"}, + {"GAME_SETUP", "SETUP_GAME", "SETUP_LOBBY", "SETUP_SEEKER_LOBBY", "SETUP_EXIT", "SETUP_SAVEMAP", "SETUP_BOUNDS"} + }); + put("de-DE", new String[][]{ + {}, + {"TAUNTED"} + }); }}; public static void loadLocalization() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java index 5e9b6ae..406f161 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -6,10 +6,10 @@ import java.util.List; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.events.Border; -import net.tylermurphy.hideAndSeek.world.VoidGenerator; import net.tylermurphy.hideAndSeek.world.WorldLoader; import org.bukkit.*; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -118,6 +118,7 @@ public class Map { this.zBoundMax = z; } + @NotNull public Location getGameSpawn() { if(mapSaveEnabled) { return new Location( @@ -131,6 +132,7 @@ public class Map { } } + @NotNull public String getGameSpawnName() { if(mapSaveEnabled) return "hs_"+ spawnWorldName; @@ -138,30 +140,37 @@ public class Map { return spawnWorldName; } + @NotNull public Location getSpawn() { return spawnPosition; } + @NotNull public String getSpawnName() { return spawnWorldName; } + @NotNull public Location getLobby() { return lobbyPosition; } + @NotNull public String getLobbyName() { return lobbyWorldName; } + @NotNull public Location getSeekerLobby() { return seekerLobbyPosition; } + @NotNull public String getSeekerLobbyName() { return seekerLobbyWorldName; } + @NotNull public Location getGameSeekerLobby() { if(mapSaveEnabled) { return new Location( @@ -179,6 +188,7 @@ public class Map { return worldBorderSize > 0; } + @NotNull public Vector getWorldBorderPos() { return new Vector( xWorldBorder, @@ -187,6 +197,7 @@ public class Map { ); } + @NotNull public Vector getWorldBorderData() { return new Vector( worldBorderSize, @@ -195,6 +206,7 @@ public class Map { ); } + @NotNull public Border getWorldBorder() { return worldBorder; } @@ -203,10 +215,12 @@ public class Map { return blockhunt; } + @NotNull public List getBlockHunt() { return blockhuntBlocks; } + @NotNull public Vector getBoundsMin() { return new Vector( xBoundMin, @@ -215,6 +229,7 @@ public class Map { ); } + @NotNull public Vector getBoundsMax() { return new Vector( xBoundMax, @@ -223,20 +238,23 @@ public class Map { ); } + @NotNull public String getName() { return name; } + @NotNull public WorldLoader getWorldLoader() { return worldLoader; } public boolean isNotSetup() { - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !Map.worldExists(spawnWorldName)) return true; - if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !Map.worldExists(lobbyWorldName)) return true; - if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld) ) return true; - if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !Map.worldExists(seekerLobbyWorldName)) return true; - if (mapSaveEnabled && !Map.worldExists(getGameSpawnName())) return true; + if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || Map.worldDoesntExist(spawnWorldName)) return true; + if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || Map.worldDoesntExist(lobbyWorldName)) return true; + if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || Map.worldDoesntExist(exitWorld)) return true; + if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || Map.worldDoesntExist(seekerLobbyWorldName)) return true; + if (mapSaveEnabled && Map.worldDoesntExist(getGameSpawnName())) return true; + if (blockhunt && blockhuntBlocks.isEmpty()) return true; if(isWorldBorderEnabled() && new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true; return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; @@ -246,9 +264,13 @@ public class Map { return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0; } - public static boolean worldExists(String worldName) { + public boolean isBoundsNotSetup() { + return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; + } + + public static boolean worldDoesntExist(String worldName) { File destination = new File(Main.getInstance().getWorldContainer()+File.separator+worldName); - return destination.isDirectory(); + return !destination.isDirectory(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java index ff1b396..a27a542 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -11,15 +11,19 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import com.cryptomorin.xseries.XMaterial; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class Maps { private static final HashMap MAPS = new HashMap<>(); + @Nullable public static Map getMap(String name) { return MAPS.get(name); } + @Nullable public static Map getRandomMap() { Optional map; if(MAPS.values().size() > 0) { @@ -45,6 +49,7 @@ public class Maps { return status; } + @NotNull public static Collection getAllMaps() { return MAPS.values(); } @@ -102,7 +107,7 @@ public class Maps { private static Location setSpawn(ConfigurationSection data, String spawn) { String worldName = data.getString("spawns."+spawn+".world"); if(worldName == null) return new Location(null, 0, 0, 0); - if(!Map.worldExists(worldName)) return new Location(null, 0, 0, 0); + if(Map.worldDoesntExist(worldName)) return new Location(null, 0, 0, 0); World world = Bukkit.getWorld(worldName); double x = data.getDouble("spawns."+spawn+".x"); double y = data.getDouble("spawns."+spawn+".y"); @@ -141,7 +146,7 @@ public class Maps { private static void saveSpawn(ConfigurationSection data, Location spawn, String name, Map map) { String worldName = getWorldName(name, map); - if(worldName == null || !Map.worldExists(worldName)) { + if(worldName == null || Map.worldDoesntExist(worldName)) { data.set("spawns." + name + ".world", "world"); } else { data.set("spawns." + name + ".world", worldName); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 4dd5fa9..0e54184 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -330,7 +330,7 @@ public class Game { } public boolean checkCurrentMap() { - if(currentMap != null) return false; + if(currentMap != null && !currentMap.isNotSetup()) return false; this.currentMap = Maps.getRandomMap(); return this.currentMap == null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java index af915e2..0f306b1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java @@ -82,12 +82,13 @@ public class InventoryHandler implements Listener { String mapName; if(Main.getInstance().supports(14)){ test = event.getView().getTitle().startsWith("Select a Block: "); + if(!test) return; mapName = event.getView().getTitle().substring("Select a Block: ".length()); } else { test = event.getInventory().getName().startsWith("Select a Block: "); + if(!test) return; mapName = event.getInventory().getName().substring("Select a Block: ".length()); } - if(!test) return; event.setCancelled(true); Map map = Maps.getMap(mapName); if(map == null) return; @@ -105,12 +106,13 @@ public class InventoryHandler implements Listener { String mapName; if(Main.getInstance().supports(14)){ test = event.getView().getTitle().startsWith("Select a Block: "); + if(!test) return; mapName = event.getView().getTitle().substring("Select a Block: ".length()); } else { test = event.getInventory().getName().startsWith("Select a Block: "); + if(!test) return; mapName = event.getInventory().getName().substring("Select a Block: ".length()); } - if(!test) return; Map map = Maps.getMap(mapName); if(map == null) return; Material mat = map.getBlockHunt().get(0); diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 53f86be..a78a421 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -48,13 +48,15 @@ Localization: TAUNT: "A random hider will be taunted in the next 30s." TAUNT_ACTIVATE: "Taunt has been activated." ERROR_GAME_SPAWN: "Please set game spawn location first" + ERROR_MAP_BOUNDS: "Please set map bounds before saving" SETUP: "&f&lThe following is needed for setup..." - SETUP_GAME: "&c&l- &fGame spawn isn't set, /hs setspawn" - SETUP_LOBBY: "&c&l- &fLobby spawn isn't set, /hs setlobby" - SETUP_SEEKER_LOBBY: "&c&l- &fSeeker Lobby spawn isn't set, /hs setseekerlobby" + SETUP_GAME: "&c&l- &fGame spawn isn't set, /hs map set spawn " + SETUP_LOBBY: "&c&l- &fLobby spawn isn't set, /hs map set lobby " + SETUP_SEEKER_LOBBY: "&c&l- &fSeeker Lobby spawn isn't set, /hs map set seekerlobby " SETUP_EXIT: "&c&l- &fQuit/exit teleport location isn't set, /hs setexit" - SETUP_SAVEMAP: "&c&l- &fHide and seek map isn't saved, /hs savemap (after /hs setspawn)" - SETUP_BOUNDS: "&c&l- &fPlease set game bounds in 2 opposite corners of the game map, /hs setbounds" + SETUP_SAVEMAP: "&c&l- &fHide and seek map isn't saved, /hs map save " + SETUP_BOUNDS: "&c&l- &fPlease set game bounds in 2 opposite corners of the game map, /hs map set bounds " + SETUP_BLOCKHUNT: "&c&l - &fIf blockhunt is enabled, there needs to be at least 1 block set, /hs map blockhunt block add block " SETUP_COMPLETE: "Everything is setup and ready to go!" GAME_SPAWN: "Set game spawn position to current location" LOBBY_SPAWN: "Set lobby position to current location" @@ -88,8 +90,8 @@ Localization: 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 )" + NO_MAPS: "There are no maps in the plugin rn (/hs map add )" + MAP_NOT_SETUP: "Map {AMOUNT} is not setup (/hs map status )" 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." @@ -97,6 +99,13 @@ Localization: SEEKER_LOBBY_INVALID: "Seeker lobby must be in the same world as game spawn." CONFIG_ERROR: "Error reloading config. Check server logs." BLOCKHUNT_DISABLED: "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8" + BLOCKHUNT_SET_TO: "Blockhunt set to {AMOUNT}." + BLOCKHUNT_BLOCK_EXISTS: "{AMOUNT} is already set in the blockhunt config." + BLOCKHUNT_BLOCK_DOESNT_EXIT: "{AMOUNT} is already not set in the blochunt config." + BLOCKHUNT_BLOCK_ADDED: "Added {AMOUNT} to blockhunt config." + BLOCKHUNT_BLOCK_REMOVED: "Removed {AMOUNT} from blockhunt config." + BLOCKHUNT_LIST_BLOCKS: "The following blockhunt blocks are:" + NO_BLOCKS: "There are no blockhunt blocks in this map." # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 4 -- cgit v1.2.3-freya From 0f1d49ba80a7658ebd6aa780bbbdfc8f3d930a2e Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Thu, 3 Nov 2022 21:03:59 -0400 Subject: 1.7.0 beta 4 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 2 + .../net/tylermurphy/hideAndSeek/command/Help.java | 72 +++++++++-- .../net/tylermurphy/hideAndSeek/command/Join.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Leave.java | 3 +- .../tylermurphy/hideAndSeek/command/Reload.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Send.java | 5 +- .../hideAndSeek/command/SetExitLocation.java | 5 +- .../net/tylermurphy/hideAndSeek/command/Start.java | 5 +- .../net/tylermurphy/hideAndSeek/command/Stop.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Top.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Wins.java | 3 +- .../tylermurphy/hideAndSeek/command/map/Add.java | 5 +- .../tylermurphy/hideAndSeek/command/map/Debug.java | 11 +- .../tylermurphy/hideAndSeek/command/map/GoTo.java | 9 +- .../tylermurphy/hideAndSeek/command/map/List.java | 3 +- .../hideAndSeek/command/map/Remove.java | 5 +- .../tylermurphy/hideAndSeek/command/map/Save.java | 7 +- .../hideAndSeek/command/map/Status.java | 7 +- .../hideAndSeek/command/map/blockhunt/Enabled.java | 7 +- .../command/map/blockhunt/blocks/Add.java | 13 +- .../command/map/blockhunt/blocks/List.java | 5 +- .../command/map/blockhunt/blocks/Remove.java | 13 +- .../hideAndSeek/command/map/set/Border.java | 7 +- .../hideAndSeek/command/map/set/Bounds.java | 5 +- .../hideAndSeek/command/map/set/Lobby.java | 7 +- .../hideAndSeek/command/map/set/SeekerLobby.java | 7 +- .../hideAndSeek/command/map/set/Spawn.java | 7 +- .../hideAndSeek/command/util/Command.java | 8 +- .../hideAndSeek/command/util/CommandGroup.java | 131 ++++++++++++--------- .../net/tylermurphy/hideAndSeek/util/Pair.java | 21 ++++ 30 files changed, 252 insertions(+), 133 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Pair.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 4646e57..631447e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -212,6 +212,8 @@ public class Main extends JavaPlugin implements Listener { public EntityHider getEntityHider() { return entityHider; } + public CommandGroup getCommandGroup() { return commandGroup; } + public boolean supports(int v){ return version >= v; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 4297f3d..d94b48a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -19,22 +19,72 @@ package net.tylermurphy.hideAndSeek.command; -import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.util.CommandGroup; +import net.tylermurphy.hideAndSeek.util.Pair; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Help extends Command { public void execute(Player sender, String[] args) { -// StringBuilder message = new StringBuilder(); -// for(Command command : CommandGroup.COMMAND_REGISTER.values()) { -// message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n")); -// } -// message = new StringBuilder(message.substring(0, message.length() - 1)); -// sender.sendMessage(message.toString()); + final int pageSize = 4; + List> commands = Main.getInstance().getCommandGroup().getCommands(); + int pages = (commands.size() - 1) / pageSize + 1; + int page; + try { + if(args.length < 1) { + page = 1; + } else { + page = Integer.parseInt(args[0]); + if (page < 1) { + throw new IllegalArgumentException("Inavlid Input"); + } + } + } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + String spacer = ChatColor.GRAY + "?" + ChatColor.WHITE; + StringBuilder message = new StringBuilder(); + message.append(String.format("%s================ %sHelp: Page (%s/%s) %s================", + ChatColor.AQUA, ChatColor.WHITE, page, pages, ChatColor.AQUA)); + int lines = 0; + for(Pair pair : commands.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList())) { + Command command = pair.getRight(); + String label = pair.getLeft(); + String start = label.substring(0, label.indexOf(" ")); + String invoke = label.substring(label.indexOf(" ")+1); + message.append(String.format("\n%s %s/%s %s%s %s%s\n%s %s%s%s", + spacer, + ChatColor.AQUA, + start, + ChatColor.WHITE, + invoke, + ChatColor.BLUE, + command.getUsage(), + spacer, + ChatColor.GRAY, + ChatColor.ITALIC, + command.getDescription() + )); + lines += 2; + } + if(lines / 2 < pageSize) { + for(int i = 0; i < pageSize * 2 - lines; i++) { + message.append("\n").append(spacer); + } + } + message.append("\n").append(ChatColor.AQUA).append("==============================================="); + sender.sendMessage(message.toString()); } public String getLabel() { @@ -42,15 +92,15 @@ public class Help extends Command { } public String getUsage() { - return ""; + return "<*page>"; } public String getDescription() { return "Get the commands for the plugin"; } - public List autoComplete(String parameter) { - return null; + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + return Collections.singletonList(parameter); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index ca2a77f..7b219a7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -61,7 +62,7 @@ public class Join extends Command { return "Joins the lobby if game is set to manual join/leave"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index d22aad9..ebfd7ee 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -60,7 +61,7 @@ public class Leave extends Command { return "Leaves the lobby if game is set to manual join/leave"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 9f8392f..1fc2c95 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -66,7 +67,7 @@ public class Reload extends Command { return "Reloads the config"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java index 9978c3c..87cc9a6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java @@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -57,8 +58,8 @@ public class Send extends Command { return "Set the current lobby to another map"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index 874909b..e8adf24 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -51,10 +52,10 @@ public class SetExitLocation extends Command { } public String getDescription() { - return "Sets hide and seeks exit location to current position and world"; + return "Sets the plugins exit location"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 674edd6..0a73591 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; @@ -89,8 +90,8 @@ public class Start extends Command { return "Starts the game either with a random seeker or chosen one"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("player")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("player")) { return Main.getInstance().getBoard().getPlayers().stream().map(Player::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 7c8cabf..9fd9aab 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -57,7 +58,7 @@ public class Stop extends Command { return "Stops the game"; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 0a5358d..e795d77 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; @@ -83,7 +84,7 @@ public class Top extends Command { return "Gets the top players in the server."; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return Collections.singletonList(parameter); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index c5917c2..f1feb33 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; @@ -80,7 +81,7 @@ public class Wins extends Command { return "Get the win information for yourself or another player."; } - public List autoComplete(String parameter) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { return Collections.singletonList(parameter); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java index 03c2a95..89a5b79 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java @@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; @@ -44,8 +45,8 @@ public class Add extends Command { return "Add a map to the plugin!"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("name")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("name")) { return Collections.singletonList("name"); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java index 4adb806..c5d0352 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.List; @@ -38,7 +39,7 @@ public class Debug extends Command { private Inventory createMenu(net.tylermurphy.hideAndSeek.configuration.Map map, Player sender){ Map> functions = new HashMap<>(); - Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu"); + Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 9, "Debug Menu"); debugMenu.setItem(0, createOption(functions, 0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> { if(mapSaveEnabled) { if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); @@ -75,10 +76,10 @@ public class Debug extends Command { } })); if(map.isBlockHuntEnabled()) { - debugMenu.setItem(9, createOption(functions, 7, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { + debugMenu.setItem(7, createOption(functions, 7, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { PlayerLoader.openBlockHuntPicker(player, map); })); - debugMenu.setItem(10, createOption(functions, 8, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + debugMenu.setItem(8, createOption(functions, 8, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); } debugMenuFunctions.put(sender, functions); return debugMenu; @@ -112,8 +113,8 @@ public class Debug extends Command { return "Run debug commands"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java index 8e74922..34ca8f9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java @@ -4,6 +4,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -48,13 +49,13 @@ public class GoTo extends Command { } public String getDescription() { - return "Get the commands for the plugin"; + return "Teleport to a map spawn zone"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } else if(parameter != null && parameter.equals("spawn")) { + } else if(parameter.equals("spawn")) { return Arrays.asList("spawn","lobby","seekerlobby","exit"); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java index 635c011..65b33d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java @@ -5,6 +5,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -39,7 +40,7 @@ public class List extends Command { return "List all maps in the plugin"; } - public java.util.List autoComplete(String parameter) { + public java.util.List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java index 45dec99..4f708b6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java @@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -43,8 +44,8 @@ public class Remove extends Command { return "Remove a map from the plugin!"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java index 1f95df3..c28d2e9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -27,6 +27,7 @@ import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -89,11 +90,11 @@ public class Save extends Command { } public String getDescription() { - return "Saves current map for the game. May lag server."; + return "Saves the map to its own separate playable map"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java index d9dd8fb..053603b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -84,11 +85,11 @@ public class Status extends Command { } public String getDescription() { - return "Shows what needs to be setup"; + return "Shows what needs to be setup on a map"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java index b8d2e15..ed14380 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -47,11 +48,11 @@ public class Enabled extends Command { return "Sets blockhunt enabled or disabled in a current map"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } - if(parameter != null && parameter.equals("bool")) { + if(parameter.equals("bool")) { return Arrays.asList("true", "false"); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java index 021dae0..bd4cf9f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java @@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -56,11 +57,15 @@ public class Add extends Command { return "Add a blockhunt block to a map!"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } else if(parameter != null && parameter.equals("block")) { - return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList()); + } else if(parameter.equals("block")) { + return Arrays.stream(Material.values()) + .filter(Material::isBlock) + .map(Material::toString) + .filter(s -> s.toUpperCase().startsWith(typed.toUpperCase())) + .collect(Collectors.toList()); } return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java index ecb626f..396f2dd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java @@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.stream.Collectors; @@ -45,8 +46,8 @@ public class List extends Command { return "List all blockhunt blocks in a map"; } - public java.util.List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public java.util.List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java index 7bbd5d3..fed9dfa 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java @@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; @@ -56,11 +57,15 @@ public class Remove extends Command { return "Remove a blockhunt block from a map!"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } else if(parameter != null && parameter.equals("block")) { - return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList()); + } else if(parameter.equals("block")) { + return Arrays.stream(Material.values()) + .filter(Material::isBlock) + .map(Material::toString) + .filter(s -> s.toUpperCase().startsWith(typed.toUpperCase())) + .collect(Collectors.toList()); } return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java index 92339b4..1b59abc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java @@ -25,6 +25,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; @@ -99,11 +100,11 @@ public class Border extends Command { } public String getDescription() { - return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; + return "Sets a maps world border information"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return Collections.singletonList(parameter); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java index 9896389..1adfc59 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java @@ -25,6 +25,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -102,8 +103,8 @@ public class Bounds extends Command { return "Sets the map bounds for the game."; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java index c691787..f2395f1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -45,11 +46,11 @@ public class Lobby extends Command { } public String getDescription() { - return "Sets hide and seeks lobby location to current position"; + return "Sets the maps lobby location"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java index 2521f19..ebbef1c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java @@ -5,6 +5,7 @@ import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -34,11 +35,11 @@ public class SeekerLobby extends Command { } public String getDescription() { - return "Sets hide and seeks seeker lobby location to current position"; + return "Sets the maps seeker lobby location"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java index 3e8f77e..c954876 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java @@ -26,6 +26,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -66,11 +67,11 @@ public class Spawn extends Command { } public String getDescription() { - return "Sets hide and seeks spawn location to current position"; + return "Sets the maps game spawn location"; } - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); } return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java index d03274d..41fd4d5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command.util; import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -34,10 +34,6 @@ public abstract class Command { public abstract String getDescription(); - public abstract List autoComplete(@Nullable String parameter); + public abstract List autoComplete(@NotNull String parameter, @NotNull String typed); - public boolean hasPermission(Player sender, String permission) { - return sender.hasPermission(permission+"."+getLabel()); - } - } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index 32f4081..5c47860 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -19,8 +19,8 @@ package net.tylermurphy.hideAndSeek.command.util; -import net.tylermurphy.hideAndSeek.command.*; import net.tylermurphy.hideAndSeek.command.map.Save; +import net.tylermurphy.hideAndSeek.util.Pair; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -62,12 +62,12 @@ public class CommandGroup { } public boolean handleCommand(Player player, String permission, String[] args) { - if (args.length < 1 && permission.equals("hs") || !commandRegister.containsKey(args[0].toLowerCase()) ) { + if (args.length < 1 || !commandRegister.containsKey(args[0].toLowerCase()) ) { if (permissionsRequired && !player.hasPermission("hs.about")) { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { player.sendMessage( - String.format("%s%sHide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); @@ -76,20 +76,29 @@ public class CommandGroup { String invoke = args[0].toLowerCase(); if (!invoke.equals("about") && !invoke.equals("help") && Save.runningBackup) { player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); - } else if (permissionsRequired && !player.hasPermission(permission+"."+invoke)) { - player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { try { Object object = commandRegister.get(invoke); - if(object instanceof CommandGroup) return ((CommandGroup) object).handleCommand(player, permission+"."+this.label, Arrays.copyOfRange(args, 1, args.length)); - Command command = (Command) object; - int parameters = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); - if(args.length - 1 < parameters) { - player.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); - return true; + if(object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + return group.handleCommand(player, permission+"."+group.getLabel(), Arrays.copyOfRange(args, 1, args.length)); + } else if(object instanceof Command) { + Command command = (Command) object; + + if (permissionsRequired && !player.hasPermission(permission+"."+command.getLabel())) { + player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); + return true; + } + + int parameterCount = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); + if(args.length - 1 < parameterCount) { + player.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); + return true; + } + + command.execute(player,Arrays.copyOfRange(args, 1, args.length)); } - command.execute(player,Arrays.copyOfRange(args, 1, args.length)); } catch (Exception e) { player.sendMessage(errorPrefix + "An error has occurred."); e.printStackTrace(); @@ -109,67 +118,75 @@ public class CommandGroup { .filter(handle -> handle.toLowerCase().startsWith(invoke)) .filter(handle -> { Object object = commandRegister.get(handle); - if (object instanceof Command) return ((Command) object).hasPermission(player, this.label); - if (object instanceof CommandGroup) - return ((CommandGroup) object).hasPermission(player, this.label); + if (object instanceof Command) { + Command command = (Command) object; + return player.hasPermission(command.getLabel()); + } else if (object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + return group.hasPermission(player, group.getLabel()); + } return false; }) .collect(Collectors.toList()); + } else { + return commandRegister.keySet() + .stream() + .filter(handle -> handle.toLowerCase().startsWith(invoke)) + .collect(Collectors.toList()); } - return commandRegister.keySet().stream().filter(handle -> handle.toLowerCase().startsWith(invoke)).collect(Collectors.toList()); } else { - if (!commandRegister.containsKey(invoke)) { - return new ArrayList<>(); - } else { + if (commandRegister.containsKey(invoke)) { Object object = commandRegister.get(invoke); - if(object instanceof CommandGroup) return ((CommandGroup) object).handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length)); - Command command = (Command) object; - String[] usage = command.getUsage().split(" "); - List complete; - if (args.length - 2 < usage.length) { - String parameter = usage[args.length-2]; - String name = parameter.replace("<", "").replace(">", ""); - complete = command.autoComplete(name); - } else { - complete = command.autoComplete(null); + if (object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + return group.handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length)); + } else if (object instanceof Command) { + Command command = (Command) object; + String[] usage = command.getUsage().split(" "); + if (args.length - 2 < usage.length) { + String parameter = usage[args.length - 2]; + String name = parameter.replace("<", "").replace(">", ""); + List list = command.autoComplete(name, args[args.length - 1]); + if (list != null) { + return list; + } + } } - if(complete == null) return new ArrayList<>(); - else return complete; } + return new ArrayList<>(); } } private boolean hasPermission(Player player, String permission) { for(Object object : commandRegister.values()) { - if(object instanceof Command) if(((Command) object).hasPermission(player, this.label)) return true; - if(object instanceof CommandGroup) if (((CommandGroup) object).hasPermission(player, permission+"."+this.label)) return true; + if(object instanceof Command) { + Command command = (Command) object; + if(player.hasPermission(permission+"."+command.getLabel())) return true; + } else if(object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + if (group.hasPermission(player, permission+"."+group.getLabel())) return true; + } } return false; } - // public static void registerCommands() { -// registerCommand(new About()); -// registerCommand(new Help()); -// registerCommand(new Setup()); -// registerCommand(new Start()); -// registerCommand(new Stop()); -// registerCommand(new SetSpawnLocation()); -// registerCommand(new SetLobbyLocation()); -// registerCommand(new SetSeekerLobbyLocation()); -// registerCommand(new SetExitLocation()); -// registerCommand(new SetBorder()); -// registerCommand(new Reload()); -// registerCommand(new SaveMap()); -// registerCommand(new SetBounds()); -// registerCommand(new Join()); -// registerCommand(new Leave()); -// registerCommand(new Top()); -// registerCommand(new Wins()); -// registerCommand(new Debug()); -// registerCommand(new AddMap()); -// registerCommand(new RemoveMap()); -// registerCommand(new ListMaps()); -// registerCommand(new SetMap()); -// } + public List> getCommands() { + return getCommands(this.getLabel()); + } + + private List> getCommands(String prefix) { + List> commands = new LinkedList<>(); + for(Object object : commandRegister.values()) { + if(object instanceof Command) { + Command command = (Command) object; + commands.add(new Pair<>(prefix+" "+command.getLabel(), command)); + } else if(object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + commands.addAll(group.getCommands(prefix+" "+group.getLabel())); + } + } + return commands; + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Pair.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Pair.java new file mode 100644 index 0000000..0aad195 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Pair.java @@ -0,0 +1,21 @@ +package net.tylermurphy.hideAndSeek.util; + +public class Pair { + + private final L left; + private final R right; + + public Pair(L left, R right) { + this.left = left; + this.right = right; + } + + public L getLeft() { + return left; + } + + public R getRight() { + return right; + } + +} -- cgit v1.2.3-freya From 5615fa7f325bb45762d13a704a9ffddda3efbfbb Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 20 Nov 2022 23:39:55 -0500 Subject: 1.7.0 beta 5 --- lib/ProtocolLib.jar | Bin 0 -> 4977063 bytes pom.xml | 20 +-- .../java/net/tylermurphy/hideAndSeek/Main.java | 15 +- .../net/tylermurphy/hideAndSeek/command/Help.java | 10 +- .../net/tylermurphy/hideAndSeek/command/Join.java | 24 ++- .../net/tylermurphy/hideAndSeek/command/Leave.java | 4 +- .../tylermurphy/hideAndSeek/command/Reload.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Send.java | 6 +- .../hideAndSeek/command/SetExitLocation.java | 8 +- .../net/tylermurphy/hideAndSeek/command/Start.java | 14 +- .../net/tylermurphy/hideAndSeek/command/Stop.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Top.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Wins.java | 4 +- .../tylermurphy/hideAndSeek/command/map/Add.java | 4 +- .../tylermurphy/hideAndSeek/command/map/Debug.java | 6 +- .../tylermurphy/hideAndSeek/command/map/GoTo.java | 15 +- .../tylermurphy/hideAndSeek/command/map/List.java | 4 +- .../hideAndSeek/command/map/Remove.java | 4 +- .../tylermurphy/hideAndSeek/command/map/Save.java | 6 +- .../hideAndSeek/command/map/Status.java | 14 +- .../hideAndSeek/command/map/blockhunt/Enabled.java | 4 +- .../command/map/blockhunt/blocks/Add.java | 4 +- .../command/map/blockhunt/blocks/List.java | 4 +- .../command/map/blockhunt/blocks/Remove.java | 4 +- .../hideAndSeek/command/map/set/Border.java | 4 +- .../hideAndSeek/command/map/set/Bounds.java | 4 +- .../hideAndSeek/command/map/set/Lobby.java | 7 +- .../hideAndSeek/command/map/set/SeekerLobby.java | 7 +- .../hideAndSeek/command/map/set/Spawn.java | 12 +- .../hideAndSeek/command/util/Command.java | 39 ----- .../hideAndSeek/command/util/CommandGroup.java | 177 +++++++++++---------- .../hideAndSeek/command/util/ICommand.java | 39 +++++ .../hideAndSeek/configuration/Config.java | 10 +- .../tylermurphy/hideAndSeek/configuration/Map.java | 71 ++------- .../hideAndSeek/configuration/Maps.java | 26 +-- .../net/tylermurphy/hideAndSeek/game/Game.java | 19 ++- .../tylermurphy/hideAndSeek/game/PlayerLoader.java | 8 +- .../hideAndSeek/game/events/Border.java | 7 +- .../hideAndSeek/game/listener/DamageHandler.java | 12 +- .../game/listener/JoinLeaveHandler.java | 17 +- .../hideAndSeek/game/listener/MovementHandler.java | 4 +- .../net/tylermurphy/hideAndSeek/util/Location.java | 111 +++++++++++++ .../net/tylermurphy/hideAndSeek/util/Tuple.java | 27 ++++ .../tylermurphy/hideAndSeek/world/WorldLoader.java | 2 +- src/main/resources/lang/localization_en-US.yml | 1 + src/main/resources/plugin.yml | 108 ++++--------- 46 files changed, 490 insertions(+), 408 deletions(-) create mode 100644 lib/ProtocolLib.jar delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Location.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Tuple.java diff --git a/lib/ProtocolLib.jar b/lib/ProtocolLib.jar new file mode 100644 index 0000000..daa31c7 Binary files /dev/null and b/lib/ProtocolLib.jar differ diff --git a/pom.xml b/pom.xml index bf41e70..974cdc8 100644 --- a/pom.xml +++ b/pom.xml @@ -82,10 +82,10 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/public/ - - dmulloy2-repo - https://repo.dmulloy2.net/repository/public/ - + + + + placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -108,12 +108,14 @@ com.comphenix.protocol ProtocolLib - 4.7.0 + 4.4.0 + system + ${project.basedir}/lib/ProtocolLib.jar org.xerial sqlite-jdbc - 3.7.2 + 3.39.3.0 org.jetbrains @@ -123,7 +125,7 @@ com.github.cryptomorin XSeries - 9.0.0 + 9.1.0 me.clip @@ -134,12 +136,12 @@ com.zaxxer HikariCP - 4.0.3 + 5.0.1 org.mariadb.jdbc mariadb-java-client - 2.7.2 + 3.0.6 \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 631447e..12e4bf4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -38,7 +38,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import java.io.File; -import java.util.Objects; +import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -125,6 +125,7 @@ public class Main extends JavaPlugin implements Listener { if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) { new PAPIExpansion().register(); } + } public void onDisable() { @@ -135,8 +136,7 @@ public class Main extends JavaPlugin implements Listener { board.getPlayers().forEach(player -> { board.removeBoard(player); PlayerLoader.unloadPlayer(player); - if (!Objects.equals(exitWorld, "")) - player.teleport(exitPosition); + exitPosition.teleport(player); }); board.cleanup(); } @@ -181,11 +181,16 @@ public class Main extends JavaPlugin implements Listener { sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); return true; } - return commandGroup.handleCommand((Player)sender, "", args); + commandGroup.handleCommand((Player)sender, args); + return true; } public java.util.List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { - return commandGroup.handleTabComplete(sender, args); + if (!(sender instanceof Player)) { + sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); + return new ArrayList<>(); + } + return commandGroup.handleTabComplete((Player)sender, args); } public static Main getInstance() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index d94b48a..3efddcd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.util.Pair; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -33,11 +33,11 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Help extends Command { +public class Help implements ICommand { public void execute(Player sender, String[] args) { final int pageSize = 4; - List> commands = Main.getInstance().getCommandGroup().getCommands(); + List> commands = Main.getInstance().getCommandGroup().getCommands(); int pages = (commands.size() - 1) / pageSize + 1; int page; try { @@ -58,8 +58,8 @@ public class Help extends Command { message.append(String.format("%s================ %sHelp: Page (%s/%s) %s================", ChatColor.AQUA, ChatColor.WHITE, page, pages, ChatColor.AQUA)); int lines = 0; - for(Pair pair : commands.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList())) { - Command command = pair.getRight(); + for(Pair pair : commands.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList())) { + ICommand command = pair.getRight(); String label = pair.getLeft(); String start = label.substring(0, label.indexOf(" ")); String invoke = label.substring(label.indexOf(" ")+1); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 7b219a7..69387cd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -20,17 +20,19 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; +import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; 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 Join extends Command { +public class Join implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { @@ -46,7 +48,18 @@ public class Join extends Command { sender.sendMessage(errorPrefix + message("GAME_INGAME")); return; } - + if(args.length > 0) { + if(Main.getInstance().getBoard().size() > 0) { + sender.sendMessage(errorPrefix + message("LOBBY_IN_USE")); + return; + } + net.tylermurphy.hideAndSeek.configuration.Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + Main.getInstance().getGame().setCurrentMap(map); + } Main.getInstance().getGame().join(player); } @@ -55,7 +68,7 @@ public class Join extends Command { } public String getUsage() { - return ""; + return "<*map>"; } public String getDescription() { @@ -63,6 +76,9 @@ public class Join extends Command { } public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("*map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index ebfd7ee..cb0c745 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -30,7 +30,7 @@ import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Leave extends Command { +public class Leave implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 1fc2c95..df2944b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; @@ -32,7 +32,7 @@ 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 Reload extends Command { +public class Reload implements ICommand { public void execute(Player sender, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java index 87cc9a6..95c0dd9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java @@ -1,7 +1,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -14,7 +14,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Send extends Command { +public class Send implements ICommand { public void execute(Player sender, String[] args) { @@ -41,7 +41,7 @@ public class Send extends Command { Main.getInstance().getGame().setCurrentMap(map); for(Player player : Main.getInstance().getBoard().getPlayers()) { - player.teleport(map.getLobby()); + map.getLobby().teleport(player); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index e8adf24..0a57cfc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -19,9 +19,10 @@ package net.tylermurphy.hideAndSeek.command; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -29,7 +30,7 @@ import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -public class SetExitLocation extends Command { +public class SetExitLocation implements ICommand { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.EXIT, null, map -> { @@ -37,8 +38,7 @@ public class SetExitLocation extends Command { addToConfig("exit.y", sender.getLocation().getBlockY()); addToConfig("exit.z", sender.getLocation().getBlockZ()); addToConfig("exit.world", sender.getLocation().getWorld().getName()); - exitPosition = sender.getLocation(); - exitWorld = sender.getLocation().getWorld().getName(); + exitPosition = Location.from(sender); saveConfig(); }); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 0a73591..74b8490 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -20,22 +20,20 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.Optional; -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; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Start extends Command { +public class Start implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { @@ -56,12 +54,8 @@ public class Start extends Command { } String seekerName; if (args.length < 1) { - Optional rand = Main.getInstance().getBoard().getPlayers().stream().skip(new Random().nextInt(Main.getInstance().getBoard().size())).findFirst(); - if (!rand.isPresent()) { - sender.sendMessage(errorPrefix + message("START_FAILED_SEEKER")); - return; - } - seekerName = rand.get().getName(); + Main.getInstance().getGame().start(); + return; } else { seekerName = args[0]; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 9fd9aab..4bc23fe 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -31,7 +31,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.abortPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Stop extends Command { +public class Stop implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index e795d77..4ac4aa7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -32,7 +32,7 @@ import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Top extends Command { +public class Top implements ICommand { public void execute(Player sender, String[] args) { int page; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index f1feb33..1ba44ac 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -33,7 +33,7 @@ import java.util.UUID; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Wins extends Command { +public class Wins implements ICommand { public void execute(Player sender, String[] args) { Main.getInstance().getServer().getScheduler().runTaskAsynchronously(Main.getInstance(), () -> { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java index 89a5b79..72f0740 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java @@ -1,7 +1,7 @@ package net.tylermurphy.hideAndSeek.command.map; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -15,7 +15,7 @@ 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 Add extends Command { +public class Add implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java index c5d0352..209d0d6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -2,7 +2,7 @@ package net.tylermurphy.hideAndSeek.command.map; import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.PlayerLoader; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -23,7 +23,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Debug extends Command { +public class Debug implements ICommand { private static final Map>> debugMenuFunctions = new HashMap<>(); @@ -68,7 +68,7 @@ public class Debug extends Command { 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); + exitPosition.teleport(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){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java index 34ca8f9..7d27642 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command.map; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; @@ -10,11 +10,10 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; +import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class GoTo extends Command { +public class GoTo implements ICommand { public void execute(Player sender, String[] args) { Map map = Maps.getMap(args[0]); @@ -28,13 +27,13 @@ public class GoTo extends Command { } switch (args[1].toLowerCase()) { case "spawn": - sender.teleport(map.getSpawn()); break; + map.getSpawn().teleport(sender); break; case "lobby": - sender.teleport(map.getLobby()); break; + map.getLobby().teleport(sender); break; case "seekerlobby": - sender.teleport(map.getSeekerLobby()); break; + map.getSeekerLobby().teleport(sender); break; case "exit": - sender.teleport(exitPosition); break; + exitPosition.teleport(sender); break; default: sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1].toLowerCase())); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java index 65b33d1..ac2badf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command.map; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.ChatColor; @@ -13,7 +13,7 @@ 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 List extends Command { +public class List implements ICommand { public void execute(Player sender, String[] args) { Collection maps = Maps.getAllMaps(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java index 4f708b6..d681848 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java @@ -1,7 +1,7 @@ package net.tylermurphy.hideAndSeek.command.map; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -15,7 +15,7 @@ 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 Remove extends Command { +public class Remove implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java index c28d2e9..a612026 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command.map; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -35,7 +35,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Save extends Command { +public class Save implements ICommand { public static boolean runningBackup = false; @@ -63,7 +63,7 @@ public class Save extends Command { } sender.sendMessage(messagePrefix + message("MAPSAVE_START")); sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); - World world = map.getSpawn().getWorld(); + World world = map.getSpawn().load(); if (world == null) { sender.sendMessage(warningPrefix + message("MAPSAVE_FAIL_WORLD")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java index 053603b..c7da88a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -19,7 +19,7 @@ package net.tylermurphy.hideAndSeek.command.map; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; @@ -31,7 +31,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Status extends Command { +public class Status implements ICommand { public void execute(Player sender, String[] args) { @@ -42,19 +42,19 @@ public class Status extends Command { sender.sendMessage(errorPrefix + message("INVALID_MAP")); return; } - if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || Map.worldDoesntExist(map.getLobbyName())) { + if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !map.getSpawn().exists()) { msg = msg + "\n" + message("SETUP_GAME"); count++; } - if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || Map.worldDoesntExist(map.getLobbyName())) { + if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !map.getLobby().exists()) { msg = msg + "\n" + message("SETUP_LOBBY"); count++; } - if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || Map.worldDoesntExist(map.getSeekerLobbyName())) { + if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !map.getSeekerLobby().exists()) { msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); count++; } - if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || Map.worldDoesntExist(exitWorld)) { + if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !exitPosition.exists()) { msg = msg + "\n" + message("SETUP_EXIT"); count++; } @@ -62,7 +62,7 @@ public class Status extends Command { msg = msg + "\n" + message("SETUP_BOUNDS"); count++; } - if (mapSaveEnabled && Map.worldDoesntExist(map.getGameSpawnName())) { + if (mapSaveEnabled && !map.getGameSpawn().exists()) { msg = msg + "\n" + message("SETUP_SAVEMAP"); count++; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java index ed14380..14ae8e0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -1,7 +1,7 @@ package net.tylermurphy.hideAndSeek.command.map.blockhunt; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -17,7 +17,7 @@ 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 Enabled extends Command { +public class Enabled implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java index bd4cf9f..fbdeecb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java @@ -1,7 +1,7 @@ package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -17,7 +17,7 @@ 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 Add extends Command { +public class Add implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java index 396f2dd..18f1b3c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; @@ -14,7 +14,7 @@ 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 List extends Command { +public class List implements ICommand { public void execute(Player sender, String[] args) { Map map = Maps.getMap(args[0]); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java index fed9dfa..d2afdc1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java @@ -1,7 +1,7 @@ package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -17,7 +17,7 @@ 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 Remove extends Command { +public class Remove implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java index 1b59abc..f9e14f8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -34,7 +34,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Border extends Command { +public class Border implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java index 1adfc59..960863b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -33,7 +33,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Bounds extends Command { +public class Bounds implements ICommand { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java index f2395f1..ada76e2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java @@ -19,21 +19,22 @@ package net.tylermurphy.hideAndSeek.command.map.set; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; -public class Lobby extends Command { +public class Lobby implements ICommand { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { - map.setLobby(sender.getLocation()); + map.setLobby(Location.from(sender)); }); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java index ebbef1c..9bc0249 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java @@ -1,9 +1,10 @@ package net.tylermurphy.hideAndSeek.command.map.set; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -12,7 +13,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SeekerLobby extends Command { +public class SeekerLobby implements ICommand { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { @@ -22,7 +23,7 @@ public class SeekerLobby extends Command { if(!map.getSpawnName().equals(sender.getLocation().getWorld().getName())) { throw new RuntimeException(message("SEEKER_LOBBY_INVALID").toString()); } - map.setSeekerLobby(sender.getLocation()); + map.setSeekerLobby(Location.from(sender)); }); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java index c954876..b983404 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java @@ -19,11 +19,11 @@ package net.tylermurphy.hideAndSeek.command.map.set; -import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.command.location.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.Location; +import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; @@ -34,7 +34,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Spawn extends Command { +public class Spawn implements ICommand { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { @@ -45,11 +45,11 @@ public class Spawn extends Command { throw new RuntimeException("World border not enabled or not in valid position!"); } - map.setSpawn(sender.getLocation()); + map.setSpawn(Location.from(sender)); - if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().getName().equals(sender.getLocation().getWorld().getName())) { + if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().equals(sender.getLocation().getWorld().getName())) { sender.sendMessage(message("SEEKER_LOBBY_SPAWN_RESET").toString()); - map.setSeekerLobby(new Location(null, 0, 0, 0)); + map.setSeekerLobby(Location.getDefault()); } if (!sender.getLocation().getWorld().getName().equals(map.getSpawnName()) && mapSaveEnabled) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java deleted file mode 100644 index 41fd4d5..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.util; - -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public abstract class Command { - - public abstract void execute(Player sender, String[] args); - - public abstract String getLabel(); - - public abstract String getUsage(); - - public abstract String getDescription(); - - public abstract List autoComplete(@NotNull String parameter, @NotNull String typed); - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index 5c47860..e9ed90c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -21,9 +21,10 @@ package net.tylermurphy.hideAndSeek.command.util; import net.tylermurphy.hideAndSeek.command.map.Save; import net.tylermurphy.hideAndSeek.util.Pair; +import net.tylermurphy.hideAndSeek.util.Tuple; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.stream.Collectors; @@ -40,7 +41,9 @@ public class CommandGroup { public CommandGroup(String label, Object... data) { this.label = label; this.commandRegister = new LinkedHashMap<>(); - for(Object o : data) registerCommand(o); + for(Object o : data) { + registerCommand(o); + } } public String getLabel() { @@ -48,8 +51,8 @@ public class CommandGroup { } private void registerCommand(Object object) { - if(object instanceof Command) { - Command command = (Command) object; + if (object instanceof ICommand) { + ICommand command = (ICommand) object; if (!commandRegister.containsKey(command.getLabel())) { commandRegister.put(command.getLabel().toLowerCase(), command); } @@ -61,87 +64,99 @@ public class CommandGroup { } } - public boolean handleCommand(Player player, String permission, String[] args) { - if (args.length < 1 || !commandRegister.containsKey(args[0].toLowerCase()) ) { - if (permissionsRequired && !player.hasPermission("hs.about")) { - player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); - } else { - player.sendMessage( - String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + - String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + - String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) - ); - } - } else { - String invoke = args[0].toLowerCase(); - if (!invoke.equals("about") && !invoke.equals("help") && Save.runningBackup) { - player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); - } else { - try { - Object object = commandRegister.get(invoke); - - if(object instanceof CommandGroup) { - CommandGroup group = (CommandGroup) object; - return group.handleCommand(player, permission+"."+group.getLabel(), Arrays.copyOfRange(args, 1, args.length)); - } else if(object instanceof Command) { - Command command = (Command) object; - - if (permissionsRequired && !player.hasPermission(permission+"."+command.getLabel())) { - player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); - return true; - } + public void handleCommand(Player player, String[] args) { - int parameterCount = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); - if(args.length - 1 < parameterCount) { - player.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); - return true; - } + Tuple data = getCommand(args, this.getLabel()); - command.execute(player,Arrays.copyOfRange(args, 1, args.length)); - } - } catch (Exception e) { - player.sendMessage(errorPrefix + "An error has occurred."); - e.printStackTrace(); - } + if (data == null) { + player.sendMessage( + String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY, ChatColor.WHITE, ChatColor.GRAY) + + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) + ); + return; + } + + ICommand command = data.getLeft(); + String permission = data.getCenter(); + String[] parameters = data.getRight(); + + if (Save.runningBackup) { + player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); + return; + } + + if (permissionsRequired && !player.hasPermission(permission)) { + player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); + return; + } + + int parameterCount = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); + if(parameters.length < parameterCount) { + player.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); + return; + } + + try { + command.execute(player, parameters); + } catch (Exception e) { + player.sendMessage(errorPrefix + "An error has occurred."); + e.printStackTrace(); + } + } + + @Nullable + private Tuple getCommand(String[] args, String permission) { + if(args.length < 1) { + return null; + } + String invoke = args[0]; + if(commandRegister.containsKey(invoke)) { + Object o = commandRegister.get(invoke); + if (o instanceof CommandGroup) { + CommandGroup group = (CommandGroup) o; + return group.getCommand( + Arrays.copyOfRange(args, 1, args.length), + permission + "." + group.getLabel() + ); + } else if(o instanceof ICommand) { + ICommand command = (ICommand) o; + return new Tuple<>(command, permission + "." + command.getLabel(), Arrays.copyOfRange(args, 1, args.length)); } } - return true; + return null; + } + + public List handleTabComplete(Player player, String[] args) { + return handleTabComplete(player, this.getLabel(), args); } - public List handleTabComplete(CommandSender sender, String[] args) { + private List handleTabComplete(Player player, String permission, String[] args) { String invoke = args[0].toLowerCase(); if (args.length == 1) { - if(sender instanceof Player) { - Player player = (Player) sender; - return new ArrayList<>(commandRegister.keySet()) - .stream() - .filter(handle -> handle.toLowerCase().startsWith(invoke)) - .filter(handle -> { - Object object = commandRegister.get(handle); - if (object instanceof Command) { - Command command = (Command) object; - return player.hasPermission(command.getLabel()); - } else if (object instanceof CommandGroup) { - CommandGroup group = (CommandGroup) object; - return group.hasPermission(player, group.getLabel()); - } - return false; - }) - .collect(Collectors.toList()); - } else { - return commandRegister.keySet() - .stream() - .filter(handle -> handle.toLowerCase().startsWith(invoke)) - .collect(Collectors.toList()); - } + return new ArrayList<>(commandRegister.keySet()) + .stream() + .filter(handle -> handle.toLowerCase().startsWith(invoke)) + .filter(handle -> { + Object object = commandRegister.get(handle); + if (object instanceof ICommand) { + ICommand command = (ICommand) object; + return !permissionsRequired || player.hasPermission(permission + "." + command.getLabel()); + } else if (object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + return !permissionsRequired || group.hasPermission(player, permission + "." + group.getLabel()); + } + return false; + }) + .collect(Collectors.toList()); } else { if (commandRegister.containsKey(invoke)) { Object object = commandRegister.get(invoke); if (object instanceof CommandGroup) { CommandGroup group = (CommandGroup) object; - return group.handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length)); - } else if (object instanceof Command) { - Command command = (Command) object; + return group.handleTabComplete(player, permission + "." + group.getLabel(), Arrays.copyOfRange(args, 1, args.length)); + } else if (object instanceof ICommand) { + ICommand command = (ICommand) object; String[] usage = command.getUsage().split(" "); if (args.length - 2 < usage.length) { String parameter = usage[args.length - 2]; @@ -159,26 +174,26 @@ public class CommandGroup { private boolean hasPermission(Player player, String permission) { for(Object object : commandRegister.values()) { - if(object instanceof Command) { - Command command = (Command) object; - if(player.hasPermission(permission+"."+command.getLabel())) return true; + if(object instanceof ICommand) { + ICommand command = (ICommand) object; + if(player.hasPermission(permission + command.getLabel())) return true; } else if(object instanceof CommandGroup) { CommandGroup group = (CommandGroup) object; - if (group.hasPermission(player, permission+"."+group.getLabel())) return true; + if (group.hasPermission(player, permission + this.label + ".")) return true; } } return false; } - public List> getCommands() { + public List> getCommands() { return getCommands(this.getLabel()); } - private List> getCommands(String prefix) { - List> commands = new LinkedList<>(); + private List> getCommands(String prefix) { + List> commands = new LinkedList<>(); for(Object object : commandRegister.values()) { - if(object instanceof Command) { - Command command = (Command) object; + if(object instanceof ICommand) { + ICommand command = (ICommand) object; commands.add(new Pair<>(prefix+" "+command.getLabel(), command)); } else if(object instanceof CommandGroup) { CommandGroup group = (CommandGroup) object; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java new file mode 100644 index 0000000..3aa0ca4 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java @@ -0,0 +1,39 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.util; + +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface ICommand { + + void execute(Player sender, String[] args); + + String getLabel(); + + String getUsage(); + + String getDescription(); + + List autoComplete(@NotNull String parameter, @NotNull String typed); + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index ee7aa18..dbc9e37 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -24,9 +24,8 @@ import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XSound; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.CountdownDisplay; -import org.bukkit.Bukkit; +import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.ChatColor; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -34,7 +33,6 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; @@ -59,8 +57,7 @@ public class Config { databasePort, databaseUser, databasePass, - databaseName, - exitWorld; + databaseName; public static boolean nameTagsVisible, @@ -150,12 +147,11 @@ public class Config { // Locations exitPosition = new Location( - Bukkit.getWorld(config.getString("exit.world")), + config.getString("exit.world"), config.getInt("exit.x"), config.getInt("exit.y"), config.getInt("exit.z") ); - exitWorld = config.getString("exit.world"); mapSaveEnabled = config.getBoolean("mapSaveEnabled"); //Taunt diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java index 406f161..8c3f8a7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -1,12 +1,11 @@ package net.tylermurphy.hideAndSeek.configuration; -import java.io.File; import java.util.ArrayList; import java.util.List; -import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.events.Border; import net.tylermurphy.hideAndSeek.world.WorldLoader; +import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.*; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; @@ -18,14 +17,9 @@ public class Map { private final String name; private Location - spawnPosition = new Location(null, 0, 0, 0), - lobbyPosition = new Location(null, 0, 0, 0), - seekerLobbyPosition = new Location(null, 0, 0, 0); - - private String - spawnWorldName = "world", - lobbyWorldName = "world", - seekerLobbyWorldName = "world"; + spawnPosition = Location.getDefault(), + lobbyPosition = Location.getDefault(), + seekerLobbyPosition = Location.getDefault(); private int xBoundMin = 0, @@ -58,32 +52,14 @@ public class Map { public void setSpawn(Location pos) { this.spawnPosition = pos; - if(pos.getWorld() != null) - this.spawnWorldName = pos.getWorld().getName(); } public void setLobby(Location pos) { this.lobbyPosition = pos; - if(pos.getWorld() != null) - this.lobbyWorldName = pos.getWorld().getName(); } public void setSeekerLobby(Location pos) { this.seekerLobbyPosition = pos; - if(pos.getWorld() != null) - this.seekerLobbyWorldName = pos.getWorld().getName(); - } - - public void setSpawnName(String name) { - this.spawnWorldName = name; - } - - public void setLobbyName(String name) { - this.lobbyWorldName = name; - } - - public void setSeekerLobbyName(String name) { - this.seekerLobbyWorldName = name; } public void setWorldBorderData(int x, int z, int size, int delay, int move) { @@ -121,12 +97,7 @@ public class Map { @NotNull public Location getGameSpawn() { if(mapSaveEnabled) { - return new Location( - Bukkit.getWorld("hs_" + spawnWorldName), - spawnPosition.getX(), - spawnPosition.getY(), - spawnPosition.getZ() - ); + return spawnPosition.changeWorld("hs_"+name); } else { return spawnPosition; } @@ -135,9 +106,9 @@ public class Map { @NotNull public String getGameSpawnName() { if(mapSaveEnabled) - return "hs_"+ spawnWorldName; + return getGameSpawn().getWorld(); else - return spawnWorldName; + return getSpawn().getWorld(); } @NotNull @@ -147,7 +118,7 @@ public class Map { @NotNull public String getSpawnName() { - return spawnWorldName; + return getSpawn().getWorld(); } @NotNull @@ -157,7 +128,7 @@ public class Map { @NotNull public String getLobbyName() { - return lobbyWorldName; + return getLobby().getWorld(); } @NotNull @@ -167,18 +138,13 @@ public class Map { @NotNull public String getSeekerLobbyName() { - return seekerLobbyWorldName; + return getSeekerLobby().getWorld(); } @NotNull public Location getGameSeekerLobby() { if(mapSaveEnabled) { - return new Location( - Bukkit.getWorld("hs_" + getSeekerLobbyName()), - seekerLobbyPosition.getX(), - seekerLobbyPosition.getY(), - seekerLobbyPosition.getZ() - ); + return seekerLobbyPosition.changeWorld("hs_"+name); } else { return seekerLobbyPosition; } @@ -249,11 +215,11 @@ public class Map { } public boolean isNotSetup() { - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || Map.worldDoesntExist(spawnWorldName)) return true; - if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || Map.worldDoesntExist(lobbyWorldName)) return true; - if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || Map.worldDoesntExist(exitWorld)) return true; - if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || Map.worldDoesntExist(seekerLobbyWorldName)) return true; - if (mapSaveEnabled && Map.worldDoesntExist(getGameSpawnName())) return true; + if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !spawnPosition.exists()) return true; + if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !lobbyPosition.exists()) return true; + if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !exitPosition.exists()) return true; + if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !seekerLobbyPosition.exists()) return true; + if (mapSaveEnabled && !getGameSpawn().exists()) return true; if (blockhunt && blockhuntBlocks.isEmpty()) return true; if(isWorldBorderEnabled() && new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true; @@ -268,9 +234,4 @@ public class Map { return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; } - public static boolean worldDoesntExist(String worldName) { - File destination = new File(Main.getInstance().getWorldContainer()+File.separator+worldName); - return !destination.isDirectory(); - } - } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java index a27a542..98ba4a0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -3,10 +3,8 @@ package net.tylermurphy.hideAndSeek.configuration; import java.util.*; import java.util.stream.Collectors; -import org.bukkit.Bukkit; -import org.bukkit.Location; +import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -74,12 +72,9 @@ public class Maps { ConfigurationSection data = maps.getConfigurationSection(name); if(data == null) return null; Map map = new Map(name); - map.setSpawn(setSpawn(data, "game")); - map.setSpawnName(data.getString("spawns.game.world")); - map.setLobby(setSpawn(data, "lobby")); - map.setLobbyName(data.getString("spawns.lobby.world")); - map.setSeekerLobby(setSpawn(data, "seeker")); - map.setSeekerLobbyName(data.getString("spawns.seeker.world")); + map.setSpawn(getSpawn(data, "game")); + map.setLobby(getSpawn(data, "lobby")); + map.setSeekerLobby(getSpawn(data, "seeker")); map.setBoundMin(data.getInt("bounds.min.x"), data.getInt("bounds.min.z")); map.setBoundMax(data.getInt("bounds.max.x"), data.getInt("bounds.max.z")); map.setWorldBorderData( @@ -104,11 +99,8 @@ public class Maps { return map; } - private static Location setSpawn(ConfigurationSection data, String spawn) { - String worldName = data.getString("spawns."+spawn+".world"); - if(worldName == null) return new Location(null, 0, 0, 0); - if(Map.worldDoesntExist(worldName)) return new Location(null, 0, 0, 0); - World world = Bukkit.getWorld(worldName); + private static Location getSpawn(ConfigurationSection data, String spawn) { + String world = data.getString("spawns."+spawn+".world"); double x = data.getDouble("spawns."+spawn+".x"); double y = data.getDouble("spawns."+spawn+".y"); double z = data.getDouble("spawns."+spawn+".z"); @@ -146,11 +138,7 @@ public class Maps { private static void saveSpawn(ConfigurationSection data, Location spawn, String name, Map map) { String worldName = getWorldName(name, map); - if(worldName == null || Map.worldDoesntExist(worldName)) { - data.set("spawns." + name + ".world", "world"); - } else { - data.set("spawns." + name + ".world", worldName); - } + data.set("spawns." + name + ".world", worldName); 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 0e54184..e238caf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -98,8 +98,8 @@ public class Game { public void start() { try { - Optional rand = board.getPlayers().stream().skip(new Random().nextInt(board.size())).findFirst(); - Player seeker = rand.orElse(board.getPlayers().get(0)); + int rand = (int) (Math.random() * board.getPlayers().size()); + Player seeker = board.getPlayers().get(rand); start(seeker); } catch (Exception e){ Main.getInstance().getLogger().warning("Failed to select random seeker."); @@ -148,7 +148,7 @@ public class Game { board.remove(player); handleBungeeLeave(player); } else { - player.teleport(currentMap.getLobby()); + currentMap.getLobby().teleport(player); board.createLobbyBoard(player); board.addHider(player); PlayerLoader.joinPlayer(player, currentMap); @@ -210,7 +210,7 @@ public class Game { out.writeUTF(leaveServer); player.sendPluginMessage(Main.getInstance(), "BungeeCord", out.toByteArray()); } else { - player.teleport(exitPosition); + exitPosition.teleport(player); } } @@ -251,7 +251,7 @@ public class Game { board.getPlayers().forEach(player -> { PlayerLoader.resetPlayer(player, board); if(board.isSeeker(player)){ - player.teleport(currentMap.getGameSpawn()); + currentMap.getGameSpawn().teleport(player); } }); } else if (startingTimer == 1){ @@ -325,8 +325,8 @@ public class Game { } } - public Map getCurrentMap() { - return currentMap; + public boolean isCurrentMapValid() { + return currentMap != null && !currentMap.isNotSetup(); } public boolean checkCurrentMap() { @@ -339,9 +339,8 @@ public class Game { this.currentMap = map; } - public String getGameWorld() { - if(currentMap == null) return null; - else return currentMap.getGameSpawnName(); + public Map getCurrentMap() { + return currentMap; } 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 d830972..10157cd 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.getGameSpawn()); + map.getGameSpawn().teleport(player); 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.getGameSeekerLobby()); + map.getGameSeekerLobby().teleport(player); 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.getGameSpawn()); + map.getGameSpawn().teleport(player); loadPlayer(player); player.setAllowFlight(true); player.setFlying(true); @@ -114,7 +114,7 @@ public class PlayerLoader { } public static void joinPlayer(Player player, Map map){ - player.teleport(map.getLobby()); + map.getLobby().teleport(player); loadPlayer(player); if (lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start"))) player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem); 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 f7ab581..9f7b5bf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/events/Border.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/events/Border.java @@ -34,6 +34,7 @@ public class Border { private void decreaseWorldBorder() { if (currentSize == 100) return; + if(map.getGameSpawn().load() == null) return; int change = (int) map.getWorldBorderData().getZ(); if (currentSize-change < 100) { change = currentSize-100; @@ -41,14 +42,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.getGameSpawn().getWorld().getWorldBorder(); + org.bukkit.WorldBorder border = map.getGameSpawn().load().getWorldBorder(); border.setSize(border.getSize()-change,30); delay = 30; } public void resetWorldBorder() { - if(map.getGameSpawn().getWorld() == null) return; - org.bukkit.WorldBorder border = map.getGameSpawn().getWorld().getWorldBorder(); + if(map.getGameSpawn().load() == null) return; + org.bukkit.WorldBorder border = map.getGameSpawn().load().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 d6eceb2..37537d6 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() == null || game.getCurrentMap().isNotSetup()) { return; } + if (!game.isCurrentMapValid()) { return; } // If there is an attacker, find them if (event instanceof EntityDamageByEntityEvent) { if (((EntityDamageByEntityEvent) event).getDamager() instanceof Player) @@ -70,9 +70,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().getGameSpawn()); + game.getCurrentMap().getGameSpawn().teleport(player); } else if (!Main.getInstance().supports(18) && player.getLocation().getY() < 0) { - player.teleport(game.getCurrentMap().getGameSpawn()); + game.getCurrentMap().getGameSpawn().teleport(player); } return; } @@ -95,15 +95,15 @@ public class DamageHandler implements Listener { Main.getInstance().getDisguiser().reveal(player); // Teleport player to seeker spawn if(delayedRespawn){ - player.teleport(game.getCurrentMap().getGameSeekerLobby()); + game.getCurrentMap().getGameSeekerLobby().teleport(player); player.sendMessage(messagePrefix + message("RESPAWN_NOTICE").addAmount(delayedRespawnDelay)); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { if(game.getStatus() == Status.PLAYING){ - player.teleport(game.getCurrentMap().getGameSpawn()); + game.getCurrentMap().getGameSpawn().teleport(player); } }, delayedRespawnDelay * 20L); } else { - player.teleport(game.getCurrentMap().getGameSpawn()); + game.getCurrentMap().getGameSpawn().teleport(player); } // Add leaderboard stats board.addDeath(player.getUniqueId()); 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 9af8629..d8534a3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/JoinLeaveHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/JoinLeaveHandler.java @@ -15,6 +15,8 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + public class JoinLeaveHandler implements Listener { @EventHandler(priority = EventPriority.HIGHEST) @@ -26,18 +28,25 @@ public class JoinLeaveHandler implements Listener { removeItems(event.getPlayer()); if (Main.getInstance().getGame().checkCurrentMap()) return; if (autoJoin) { + if (Main.getInstance().getGame().checkCurrentMap()) { + event.getPlayer().sendMessage(errorPrefix + message("GAME_SETUP")); + return; + } Main.getInstance().getGame().join(event.getPlayer()); } else if (teleportToExit) { - 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); + if ( + event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getLobbyName()) || + event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getGameSpawnName()) + ) { + exitPosition.teleport(event.getPlayer()); event.getPlayer().setGameMode(GameMode.ADVENTURE); } } else { - if (mapSaveEnabled && event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld())) { + if (mapSaveEnabled && event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getGameSpawnName())) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY && Main.getInstance().getGame().getStatus() != Status.ENDING) { Main.getInstance().getGame().join(event.getPlayer()); } else { - event.getPlayer().teleport(exitPosition); + exitPosition.teleport(event.getPlayer()); event.getPlayer().setGameMode(GameMode.ADVENTURE); } } 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 2558763..1dd6cfc 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())) return; - if (!event.getTo().getWorld().getName().equals(Main.getInstance().getGame().getGameWorld())) return; + if (!event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getGameSpawnName())) return; + if (!event.getTo().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getGameSpawnName())) 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/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java new file mode 100644 index 0000000..2abdb9b --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -0,0 +1,111 @@ +package net.tylermurphy.hideAndSeek.util; + +import net.tylermurphy.hideAndSeek.Main; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public class Location { + + private final String world; + private final double x; + private final double y; + private final double z; + + public static Location getDefault() { + return new Location( + "", + 0.0, + 0.0, + 0.0 + ); + } + + public static Location from(Player player) { + org.bukkit.Location location = player.getLocation(); + return new Location( + player.getWorld().getName(), + location.getX(), + location.getY(), + location.getZ() + ); + } + + public Location(@NotNull String world, double x, double y, double z) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + } + + public World load() { + World bukkitWorld = Bukkit.getWorld(world); + if(bukkitWorld != null) return bukkitWorld; + Bukkit.getServer().createWorld(new WorldCreator(world)); + return Bukkit.getWorld(world); + } + + private org.bukkit.Location toBukkit() { + return new org.bukkit.Location( + Bukkit.getWorld(world), + x, + y, + z + ); + } + + public void teleport(Player player) { + if(!exists()) return; + if(load() == null) return; + player.teleport(toBukkit()); + } + + public Location changeWorld(String world) { + return new Location( + world, + x, + y, + z + ); + } + + public String getWorld() { + return world; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public int getBlockX() { + return (int)x; + } + + public int getBlockY() { + return (int)y; + } + + public int getBlockZ() { + return (int)z; + } + + public boolean exists() { + if(world.equals("")) return false; + String path = Main.getInstance().getWorldContainer()+File.separator+world; + File destination = new File(path); + return destination.isDirectory(); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Tuple.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Tuple.java new file mode 100644 index 0000000..5a40ff8 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Tuple.java @@ -0,0 +1,27 @@ +package net.tylermurphy.hideAndSeek.util; + +public class Tuple { + + private final L left; + private final C center; + private final R right; + + public Tuple(L left, C center, R right) { + this.left = left; + this.center = center; + this.right = right; + } + + public L getLeft() { + return left; + } + + public C getCenter() { + return center; + } + + public R getRight() { + return right; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index d4deafe..b3be907 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -49,7 +49,7 @@ public class WorldLoader { Main.getInstance().getLogger().warning(map.getGameSpawnName() + " already unloaded."); return; } - world.getPlayers().forEach(player -> player.teleport(exitPosition)); + world.getPlayers().forEach(player -> exitPosition.teleport(player)); if (Bukkit.getServer().unloadWorld(world, false)) { Main.getInstance().getLogger().info("Successfully unloaded " + map.getGameSpawnName()); }else{ diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index a78a421..d62153d 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -26,6 +26,7 @@ Localization: GAME_JOIN: "{PLAYER} has joined the HideAndSeek lobby." GAME_JOIN_SPECTATOR: "You have joined mid game and are now a spectator." GAME_LEAVE: "{PLAYER} has left the HideAndSeek lobby." + LOBBY_IN_USE: "Cant modify the lobby while the lobby isn't empty." CONFIG_RELOAD: "Reloaded the config." MAPSAVE_INPROGRESS: "Map save is currently in progress. Try again later." MAPSAVE_START: "Starting map save." diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 49655c7..92c6483 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -12,98 +12,54 @@ commands: usage: /hideandseek [command] aliases: hs permissions: - hideandseek.*: - description: Gives access to all hideandseek commands - children: - hideandseek.about: true - hideandseek.help: true - hideandseek.reload: true - hideandseek.setborder: true - hideandseek.setspawn: true - hideandseek.setlobby: true - hideandseek.setseekerlobby: true - hideandseek.setexit: true - hideadnseek.setbounds: true - hideandseek.setup: true - hideandseek.start: true - hideandseek.stop: true - hideandseek.savemap: true - hideandseek.join: true - hideandseek.leave: true - hideandseek.leavebounds: true - 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 + hs.help: default: true - hideandseek.help: - description: Allows you to run the help command + hs.join: default: true - hideandseek.reload: - description: Allows you to reload the config + hs.leave: + default: true + hs.top: + default: true + hs.wins: + default: true + hs.reload: default: op - hideandseek.setborder: - description: Allows you to set the game world border + hs.send: default: op - hideandseek.setspawn: - description: Allows you to set the game spawn point + hs.setexit: default: op - hideandseek.setlobby: - description: Allows you to set the game lobby point + hs.start: default: op - hideandseek.setseekerlobby: - description: Allows you to set the game seeker lobby point + hs.stop: default: op - hideandseek.setexit: - description: Allows you to set the game exit point + hs.map.add: default: op - hideandseek.setbounds: - description: Allows you to set bounds for the game map + hs.map.remove: default: op - hideandseek.setup: - description: Allows you to see what needs to be setup for the plugin to function + hs.map.list: default: op - hideandseek.start: - description: Allows you to start the game + hs.map.status: default: op - hideandseek.stop: - description: Allows you to stop the game + hs.map.save: default: op - hideandseek.savemap: - description: Allows you to set the current game map + hs.map.debug: default: op - hideandseek.join: - description: Allows you to join the game manual lobby - default: true - hideandseek.leave: - description: Allows you to leave the game manual lobby - default: true - hideandseek.leavebounds: - description: Allows players to leave specified game bounderies + hs.map.goto: default: op - hideandseek.wins: - description: Allows players to see a players amount of wins - default: true - hideandseek.top: - description: Allows players to see the global wins leaderboard - default: true - hideandseek.debug: - description: Opens the debug menu + hs.map.set.lobby: + default: op + hs.map.set.spawn: + default: op + hs.map.set.seekerlobby: + default: op + hs.map.set.border: default: op - hideandseek.addmap: - description: Adds a map to the plugin + hs.map.set.bounds: default: op - hideandseek.removemap: - description: Removes a map from the plugin + hs.map.blockhunt.add: default: op - hideandseek.listmaps: - description: Lists all maps in the plugin + hs.map.blockhunt.remove: default: op - hideandseek.setmap: - description: Sets the current lobby to a new map + hs.map.blockhunt.list: default: op + -- cgit v1.2.3-freya From 1815b63bc94382a36b610be8082a423364e51b21 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 21 Nov 2022 13:33:55 -0500 Subject: 1.7.0 beta 6 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 62 +++++++++++++++++- .../tylermurphy/hideAndSeek/command/Confirm.java | 62 ++++++++++++++++++ .../hideAndSeek/command/world/Create.java | 66 +++++++++++++++++++ .../hideAndSeek/command/world/Delete.java | 74 ++++++++++++++++++++++ .../hideAndSeek/command/world/List.java | 46 ++++++++++++++ .../tylermurphy/hideAndSeek/command/world/Tp.java | 49 ++++++++++++++ .../hideAndSeek/configuration/ConfigManager.java | 4 +- .../hideAndSeek/configuration/Maps.java | 2 + .../tylermurphy/hideAndSeek/database/Database.java | 2 + .../database/connections/MySQLConnection.java | 8 +++ .../net/tylermurphy/hideAndSeek/util/Location.java | 22 ++++++- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 2 +- src/main/resources/lang/localization_en-US.yml | 14 ++++ src/main/resources/plugin.yml | 10 +++ 14 files changed, 416 insertions(+), 7 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Confirm.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/world/Tp.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 12e4bf4..656f60d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -23,6 +23,9 @@ import net.tylermurphy.hideAndSeek.command.*; import net.tylermurphy.hideAndSeek.command.map.*; import net.tylermurphy.hideAndSeek.command.map.blockhunt.Enabled; import net.tylermurphy.hideAndSeek.command.map.set.*; +import net.tylermurphy.hideAndSeek.command.world.Create; +import net.tylermurphy.hideAndSeek.command.world.Delete; +import net.tylermurphy.hideAndSeek.command.world.Tp; import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.game.*; @@ -39,6 +42,7 @@ import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,16 +60,28 @@ public class Main extends JavaPlugin implements Listener { private EntityHider entityHider; private Game game; private CommandGroup commandGroup; + private boolean loaded; public void onEnable() { + + long start = System.currentTimeMillis(); + + getLogger().info("Loading Kenshin's Hide and Seek"); Main.instance = this; - this.updateVersion(); + + getLogger().info("Getting minecraft version..."); + this.updateVersion();; try { + getLogger().info("Loading config.yml..."); Config.loadConfig(); + getLogger().info("Loading maps.yml..."); Maps.loadMaps(); + getLogger().info("Loading localization.yml..."); Localization.loadLocalization(); + getLogger().info("Loading items.yml..."); Items.loadItems(); + getLogger().info("Loading leaderboard.yml..."); Leaderboard.loadLeaderboard(); } catch (Exception e) { getLogger().severe(e.getMessage()); @@ -73,12 +89,18 @@ public class Main extends JavaPlugin implements Listener { return; } + getLogger().info("Creating internal scoreboard..."); this.board = new Board(); + getLogger().info("Connecting to database..."); this.database = new Database(); + getLogger().info("Loading disguises..."); this.disguiser = new Disguiser(); + getLogger().info("Loading entity hider..."); this.entityHider = new EntityHider(this, EntityHider.Policy.BLACKLIST); + getLogger().info("Registering listeners..."); this.registerListeners(); + getLogger().info("Registering commands..."); this.commandGroup = new CommandGroup("hs", new Help(), new Reload(), @@ -111,21 +133,38 @@ public class Main extends JavaPlugin implements Listener { new Debug(), new GoTo() ), + new CommandGroup("world", + new Create(), + new Delete(), + new net.tylermurphy.hideAndSeek.command.world.List(), + new Tp() + ), new SetExitLocation(), new Top(), - new Wins() + new Wins(), + new Confirm() ); + getLogger().info("Loading game..."); game = new Game(null, board); + getLogger().info("Scheduling tick tasks..."); getServer().getScheduler().runTaskTimer(this, this::onTick,0,1).getTaskId(); + getLogger().info("Registering outgoing bungeecord plugin channel..."); Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + getLogger().info("Checking for PlaceholderAPI..."); if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) { + getLogger().info("PlaceholderAPI found..."); + getLogger().info("Registering PlaceholderAPI expansion..."); new PAPIExpansion().register(); } + long end = System.currentTimeMillis(); + getLogger().info("Finished loading plugin ("+(end-start)+"ms)"); + loaded = true; + } public void onDisable() { @@ -222,5 +261,24 @@ public class Main extends JavaPlugin implements Listener { public boolean supports(int v){ return version >= v; } + + public java.util.List getWorlds() { + java.util.List worlds = new ArrayList<>(); + File[] containers = getWorldContainer().listFiles(); + if(containers != null) { + Arrays.stream(containers).forEach(file -> { + if (!file.isDirectory()) return; + String[] files = file.list(); + if (files == null) return; + if (!Arrays.asList(files).contains("session.lock") && !Arrays.asList(files).contains("level.dat")) return; + worlds.add(file.getName()); + }); + } + return worlds; + } + + public boolean isLoaded() { + return loaded; + } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Confirm.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Confirm.java new file mode 100644 index 0000000..a25185d --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Confirm.java @@ -0,0 +1,62 @@ +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.command.util.ICommand; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.*; +import java.util.function.Consumer; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Confirm implements ICommand { + + public static final Map confirmations = new HashMap<>(); + + public void execute(Player sender, String[] args) { + Confirmation confirmation = confirmations.get(sender.getUniqueId()); + confirmations.remove(sender.getUniqueId()); + if(confirmation == null) { + sender.sendMessage(errorPrefix + message("NO_CONFIRMATION")); + } else { + long now = System.currentTimeMillis(); + float secs = (now - confirmation.start) / 1000F; + if(secs > 10) { + sender.sendMessage(errorPrefix + message("CONFIRMATION_TIMED_OUT")); + return; + } + confirmation.callback.accept(confirmation.data); + } + } + + public String getLabel() { + return "confirm"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Confirm another command if required"; + } + + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + return null; + } + + public static class Confirmation { + public final Consumer callback; + public final String data; + public final long start; + + public Confirmation(String data, Consumer callback) { + this.callback = callback; + this.data = data; + this.start = System.currentTimeMillis(); + } + + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java new file mode 100644 index 0000000..5ab9039 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java @@ -0,0 +1,66 @@ +package net.tylermurphy.hideAndSeek.command.world; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.ICommand; +import net.tylermurphy.hideAndSeek.util.Location; +import org.bukkit.WorldType; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +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 Create implements ICommand { + + public void execute(Player sender, String[] args) { + List worlds = Main.getInstance().getWorlds(); + if(worlds.contains(args[0])) { + sender.sendMessage(errorPrefix + message("WORLD_EXISTS").addAmount(args[0])); + } + WorldType type; + if(args[1].equals("normal")) { + type = WorldType.NORMAL; + } else if(args[1].equals("flat")) { + type = WorldType.FLAT; + } else { + sender.sendMessage(errorPrefix + message("INVALID_WORLD_TYPE").addAmount(args[1])); + return; + } + + Location temp = new Location(args[0], 0, 0, 0); + + if (temp.load(type) == null) { + sender.sendMessage(errorPrefix + message("WORLD_ADDED_FAILED")); + } else { + sender.sendMessage(messagePrefix + message("WORLD_ADDED").addAmount(args[0])); + } + + } + + public String getLabel() { + return "create"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Create a new world"; + } + + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("name")) { + return Collections.singletonList("name"); + } + if(parameter.equals("type")) { + return Arrays.asList("normal", "flat"); + } + return null; + } +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java new file mode 100644 index 0000000..4800e08 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java @@ -0,0 +1,74 @@ +package net.tylermurphy.hideAndSeek.command.world; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.Confirm; +import net.tylermurphy.hideAndSeek.command.util.ICommand; +import net.tylermurphy.hideAndSeek.world.WorldLoader; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +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 Delete implements ICommand { + + public void execute(Player sender, String[] args) { + java.util.List worlds = Main.getInstance().getWorlds(); + if(!worlds.contains(args[0])) { + sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIST").addAmount(args[0])); + } + + Confirm.Confirmation confirmation = new Confirm.Confirmation(args[0], world -> { + java.util.List worlds_now = Main.getInstance().getWorlds(); + if(!worlds_now.contains(world)) { + sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIST").addAmount(world)); + } + World bukkit_world = Bukkit.getWorld(world); + if(bukkit_world != null && bukkit_world.getPlayers().size() > 0) { + sender.sendMessage(errorPrefix + message("WORLD_NOT_EMPTY")); + return; + } + String path = Main.getInstance().getWorldContainer().getPath() + File.separator + world; + if (!Bukkit.getServer().unloadWorld(world, false)) { + sender.sendMessage(errorPrefix + message("WORLD_REMOVED_FAILED")); + return; + } + try { + WorldLoader.deleteDirectory(new File(path)); + } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLD_REMOVED_FAILED")); + return; + } + sender.sendMessage(messagePrefix + message("WORLD_REMOVED").addAmount(world)); + }); + + Confirm.confirmations.put(sender.getUniqueId(), confirmation); + sender.sendMessage(messagePrefix + message("CONFIRMATION")); + + } + + public String getLabel() { + return "delete"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Delete a world"; + } + + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("name")) { + return Main.getInstance().getWorlds(); + } + return null; + } +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java new file mode 100644 index 0000000..2c0f745 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java @@ -0,0 +1,46 @@ +package net.tylermurphy.hideAndSeek.command.world; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.ICommand; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +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 List implements ICommand { + + public void execute(Player sender, String[] args) { + java.util.List worlds = Main.getInstance().getWorlds(); + if(worlds.isEmpty()) { + sender.sendMessage(errorPrefix + message("NO_WORLDS")); + } else { + StringBuilder response = new StringBuilder(messagePrefix + message("LIST_WORLDS")); + for (String world : worlds) { + boolean loaded = Bukkit.getWorld(world) != null; + response.append("\n ").append(world).append(": ").append(loaded ? ChatColor.GREEN + "LOADED" : ChatColor.YELLOW + "NOT LOADED").append(ChatColor.WHITE); + } + sender.sendMessage(response.toString()); + } + } + + public String getLabel() { + return "list"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "List all worlds in the server"; + } + + public java.util.List autoComplete(@NotNull String parameter, @NotNull String typed) { + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Tp.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Tp.java new file mode 100644 index 0000000..b166297 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Tp.java @@ -0,0 +1,49 @@ +package net.tylermurphy.hideAndSeek.command.world; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.ICommand; +import net.tylermurphy.hideAndSeek.util.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Tp implements ICommand { + public void execute(Player sender, String[] args) { + Location test = new Location(args[0], 0, 0,0); + if(!test.exists()) { + sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIT")); + return; + } + World world = test.load(); + if(world == null) { + sender.sendMessage(errorPrefix + message("WORLD_LOAD_FAILED")); + return; + } + Location loc = new Location(world.getName(), world.getSpawnLocation()); + loc.teleport(sender); + } + + public String getLabel() { + return "tp"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Teleport to another world"; + } + + public List autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("world")) { + return Main.getInstance().getWorlds(); + } + return null; + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index eda8470..be699ec 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -318,11 +318,11 @@ public class ConfigManager { int index = 0; for(String part : parts) { if (index == 0) { - index = yaml.indexOf(part + ":", index); + index = yaml.indexOf("\n" + part + ":", index) + 1; } else { index = yaml.indexOf(" " + part + ":", index) + 1; } - if (index == -1) break; + if (index == 0) break; } return index; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java index 98ba4a0..d691fa9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -3,6 +3,7 @@ package net.tylermurphy.hideAndSeek.configuration; import java.util.*; import java.util.stream.Collectors; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -72,6 +73,7 @@ public class Maps { ConfigurationSection data = maps.getConfigurationSection(name); if(data == null) return null; Map map = new Map(name); + Main.getInstance().getLogger().info("Loading map: " + name + "..."); map.setSpawn(getSpawn(data, "game")); map.setLobby(getSpawn(data, "lobby")); map.setSeekerLobby(getSpawn(data, "seeker")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java index e7bfb26..d2fb40d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -45,8 +45,10 @@ public class Database { public Database(){ if(databaseType.equals("SQLITE")) { + Main.getInstance().getLogger().info("SQLITE database chosen"); connection = new SQLiteConnection(); } else { + Main.getInstance().getLogger().info("MYSQL database chosen"); connection = new MySQLConnection(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/connections/MySQLConnection.java b/src/main/java/net/tylermurphy/hideAndSeek/database/connections/MySQLConnection.java index b7c1b1d..56f53f6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/connections/MySQLConnection.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/connections/MySQLConnection.java @@ -21,6 +21,7 @@ package net.tylermurphy.hideAndSeek.database.connections; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; +import net.tylermurphy.hideAndSeek.Main; import java.sql.Connection; import java.sql.SQLException; @@ -35,6 +36,13 @@ public class MySQLConnection implements DatabaseConnection { HikariConfig config = new HikariConfig(); + Main.getInstance().getLogger().info("Database host: " + databaseHost); + Main.getInstance().getLogger().info("Database port: " + databasePort); + Main.getInstance().getLogger().info("Database user: " + databaseUser); + Main.getInstance().getLogger().info("Database pass: xxxxxxxxxxx"); + Main.getInstance().getLogger().info("Database name: " + databaseName); + + config.setJdbcUrl("jdbc:mariadb://"+databaseHost+":"+databasePort+"/"+databaseName); config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java index 2abdb9b..efc4329 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -4,6 +4,7 @@ import net.tylermurphy.hideAndSeek.Main; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; +import org.bukkit.WorldType; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -42,13 +43,30 @@ public class Location { this.z = z; } - public World load() { + public Location(@NotNull String world, @NotNull org.bukkit.Location location) { + this.world = world; + this.x = location.getX(); + this.y = location.getY(); + this.z = location.getZ(); + } + + public World load(WorldType type) { World bukkitWorld = Bukkit.getWorld(world); if(bukkitWorld != null) return bukkitWorld; - Bukkit.getServer().createWorld(new WorldCreator(world)); + if (type == null) { + Bukkit.getServer().createWorld(new WorldCreator(world)); + } else { + Bukkit.getServer().createWorld(new WorldCreator(world).type(type)); + } return Bukkit.getWorld(world); } + public World load() { + if(!exists()) return null; + if(!Main.getInstance().isLoaded()) return null; + return load(null); + } + private org.bukkit.Location toBukkit() { return new org.bukkit.Location( Bukkit.getWorld(world), diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index b3be907..6ea1773 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -155,7 +155,7 @@ public class WorldLoader { out.close(); } - private void deleteDirectory(File directoryToBeDeleted) { + public static void deleteDirectory(File directoryToBeDeleted) { File[] allContents = directoryToBeDeleted.listFiles(); if (allContents != null) { for (File file : allContents) { diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index d62153d..61d562b 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -107,6 +107,20 @@ Localization: BLOCKHUNT_BLOCK_REMOVED: "Removed {AMOUNT} from blockhunt config." BLOCKHUNT_LIST_BLOCKS: "The following blockhunt blocks are:" NO_BLOCKS: "There are no blockhunt blocks in this map." + WORLD_EXISTS: "A world named {AMOUNT} already exists." + WORLD_DOESNT_EXIST: "There is no world named {AMOUNT} that exists." + WORLD_ADDED: "Created a world named {AMOUNT}." + WORLD_ADDED_FAILED: "Failed to create new world." + WORLD_REMOVED: "Deleted a world named {AMOUNT}." + WORLD_REMOVED_FAILED: "Failed to delete world." + WORLD_NOT_EMPTY: "World must be empty to be deleted." + LIST_WORLDS: "The following worlds are:" + NO_WORLDS: "Failed to fetch any worlds." + WORLD_LOAD_FAILED: "Failed to load world." + INVALID_WORLD_TYPE: "Invalid world type: {AMOUNT}." + NO_CONFIRMATION: "You have nothing to confirm." + CONFIRMATION_TIMED_OUT: "The confirmation has timed out." + CONFIRMATION: "Run /hs confirm within 10s to confirm." # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 4 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 92c6483..c6ce455 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -62,4 +62,14 @@ permissions: default: op hs.map.blockhunt.list: default: op + hs.world.create: + default: op + hs.world.delete: + default: op + hs.world.list: + default: op + hs.world.tp: + default: op + hs.confirm: + default: op -- cgit v1.2.3-freya From efb2cf40e82e1b00d3d97e6986d8aed83d8a26dc Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 21 Nov 2022 15:04:10 -0500 Subject: 1.7.0 beta 7 --- .../java/net/tylermurphy/hideAndSeek/util/Location.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java index efc4329..b75eb95 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -1,6 +1,7 @@ package net.tylermurphy.hideAndSeek.util; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.world.VoidGenerator; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -51,13 +52,17 @@ public class Location { } public World load(WorldType type) { + boolean mapSave = world.startsWith("hs_"); World bukkitWorld = Bukkit.getWorld(world); if(bukkitWorld != null) return bukkitWorld; - if (type == null) { - Bukkit.getServer().createWorld(new WorldCreator(world)); - } else { - Bukkit.getServer().createWorld(new WorldCreator(world).type(type)); + WorldCreator creator = new WorldCreator(world); + if(type != null) { + creator.type(type); } + if(mapSave) { + creator.generator(new VoidGenerator()); + } + Bukkit.getServer().createWorld(creator).setAutoSave(!mapSave); return Bukkit.getWorld(world); } -- cgit v1.2.3-freya From 934c04388ddfade47ea0ce78335d98fc49fc457c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 21 Nov 2022 16:54:32 -0500 Subject: 1.7.0 beta 8 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 5 +++ .../hideAndSeek/command/world/Create.java | 2 + .../net/tylermurphy/hideAndSeek/util/Location.java | 2 +- .../hideAndSeek/world/VoidGenerator.java | 46 ++++++++-------------- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 12 +++--- 5 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 656f60d..ad49273 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -280,5 +280,10 @@ public class Main extends JavaPlugin implements Listener { public boolean isLoaded() { return loaded; } + + public void scheduleTask(Runnable task) { + if(!isEnabled()) return; + Bukkit.getServer().getScheduler().runTask(this, task); + } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java index 5ab9039..20ffd5a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java @@ -3,8 +3,10 @@ package net.tylermurphy.hideAndSeek.command.world; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.util.Location; +import org.bukkit.Bukkit; import org.bukkit.WorldType; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import java.util.Arrays; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java index b75eb95..e769b05 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -84,7 +84,7 @@ public class Location { public void teleport(Player player) { if(!exists()) return; if(load() == null) return; - player.teleport(toBukkit()); + Main.getInstance().scheduleTask(() -> player.teleport(toBukkit())); } public Location changeWorld(String world) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java index b0ce824..15ff45f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java @@ -19,7 +19,9 @@ package net.tylermurphy.hideAndSeek.world; +import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; @@ -36,41 +38,27 @@ public class VoidGenerator extends ChunkGenerator { return Collections.emptyList(); } - public boolean shouldGenerateNoise() { - return false; - } - - public boolean shouldGenerateSurface() { - return false; - } - - public boolean shouldGenerateBedrock() { - return false; - } - - public boolean shouldGenerateCaves() { - return false; - } - - public boolean shouldGenerateDecorations() { - return false; + @Override + public boolean canSpawn(World world, int x, int z) { + return true; } - public boolean shouldGenerateMobs() { - return false; + @Override + public Location getFixedSpawnLocation(World world, Random random) { + return new Location(world, 0, 100, 0); } - public boolean shouldGenerateStructures() { - return false; - } + // 1.13 And Prev + public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biome) { + ChunkData chunkData = super.createChunkData(world); - public boolean canSpawn(@NotNull World world, int x, int z) { - return true; - } + for(int x = 0; x < 16; x++) { + for(int z = 0; z < 16; z++) { + biome.setBiome(x, z, Biome.PLAINS); + } + } - // 1.13 And Prev - public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { - return createChunkData(world); + return chunkData; } // 1.8 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 6ea1773..864397e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -50,11 +50,13 @@ public class WorldLoader { return; } world.getPlayers().forEach(player -> exitPosition.teleport(player)); - if (Bukkit.getServer().unloadWorld(world, false)) { - Main.getInstance().getLogger().info("Successfully unloaded " + map.getGameSpawnName()); - }else{ - Main.getInstance().getLogger().severe("COULD NOT UNLOAD " + map.getGameSpawnName()); - } + Main.getInstance().scheduleTask(() -> { + if (Bukkit.getServer().unloadWorld(world, false)) { + Main.getInstance().getLogger().info("Successfully unloaded " + map.getGameSpawnName()); + } else { + Main.getInstance().getLogger().severe("COULD NOT UNLOAD " + map.getGameSpawnName()); + } + }); } public void loadMap() { -- cgit v1.2.3-freya From fcc3764a14d76fa24cddb75fe338a3ee36dec3fa Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 21 Nov 2022 23:47:04 -0500 Subject: 1.7.0 beta 9 --- lib/ProtocolLib.jar | Bin 4977063 -> 0 bytes pom.xml | 22 ++++++------- .../hideAndSeek/command/location/Locations.java | 17 +++------- .../hideAndSeek/command/util/CommandGroup.java | 2 +- .../hideAndSeek/command/world/Create.java | 36 ++++++++++++++------- .../hideAndSeek/command/world/Delete.java | 2 ++ .../hideAndSeek/command/world/List.java | 15 +++++++-- .../hideAndSeek/configuration/ConfigManager.java | 5 +-- .../net/tylermurphy/hideAndSeek/game/Board.java | 2 +- .../net/tylermurphy/hideAndSeek/game/Game.java | 6 ++-- .../hideAndSeek/game/listener/PlayerHandler.java | 1 - .../net/tylermurphy/hideAndSeek/util/Location.java | 7 ++-- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 16 +++++---- 13 files changed, 75 insertions(+), 56 deletions(-) delete mode 100644 lib/ProtocolLib.jar diff --git a/lib/ProtocolLib.jar b/lib/ProtocolLib.jar deleted file mode 100644 index daa31c7..0000000 Binary files a/lib/ProtocolLib.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index 974cdc8..8b2a39d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,10 +4,13 @@ 1.7.0 Hide and Seek Plugin + + UTF-8 + + clean install src/main/java - org.apache.maven.plugins @@ -30,10 +33,6 @@ com.zaxxer.hikari net.tylermurphy.dependencies.hikari - - org.ibex.nestedvm - net.tylermurphy.dependencies.nestedvm - @@ -58,7 +57,6 @@ META-INF/services/java.sql.Driver - true @@ -82,10 +80,10 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/public/ - - - - + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -109,8 +107,8 @@ com.comphenix.protocol ProtocolLib 4.4.0 - system - ${project.basedir}/lib/ProtocolLib.jar + + org.xerial diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java index dd73dac..c1316f8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java @@ -5,22 +5,13 @@ package net.tylermurphy.hideAndSeek.command.location; */ public enum Locations { - GAME("spawns.game"), - LOBBY("spawns.lobby"), - EXIT("spawns.exit"), - SEEKER("spawns.seeker"); - - private final String path; - Locations(String path) { - this.path = path; - } + GAME, + LOBBY, + EXIT, + SEEKER; public String message() { return this + "_SPAWN"; } - public String path(String additive) { - return path + "." + additive; - } - } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index e9ed90c..b366b9a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -70,7 +70,7 @@ public class CommandGroup { if (data == null) { player.sendMessage( - String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY, ChatColor.WHITE, ChatColor.GRAY) + + String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0%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) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java index 20ffd5a..e399993 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java @@ -3,10 +3,9 @@ package net.tylermurphy.hideAndSeek.command.world; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.util.Location; -import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.WorldType; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -23,20 +22,35 @@ public class Create implements ICommand { List worlds = Main.getInstance().getWorlds(); if(worlds.contains(args[0])) { sender.sendMessage(errorPrefix + message("WORLD_EXISTS").addAmount(args[0])); + return; } WorldType type; - if(args[1].equals("normal")) { - type = WorldType.NORMAL; - } else if(args[1].equals("flat")) { - type = WorldType.FLAT; - } else { - sender.sendMessage(errorPrefix + message("INVALID_WORLD_TYPE").addAmount(args[1])); - return; + World.Environment environment; + switch (args[1]) { + case "normal": + type = WorldType.NORMAL; + environment = World.Environment.NORMAL; + break; + case "flat": + type = WorldType.FLAT; + environment = World.Environment.NORMAL; + break; + case "nether": + type = WorldType.NORMAL; + environment = World.Environment.NETHER; + break; + case "end": + type = WorldType.NORMAL; + environment = World.Environment.THE_END; + break; + default: + sender.sendMessage(errorPrefix + message("INVALID_WORLD_TYPE").addAmount(args[1])); + return; } Location temp = new Location(args[0], 0, 0, 0); - if (temp.load(type) == null) { + if (temp.load(type, environment) == null) { sender.sendMessage(errorPrefix + message("WORLD_ADDED_FAILED")); } else { sender.sendMessage(messagePrefix + message("WORLD_ADDED").addAmount(args[0])); @@ -61,7 +75,7 @@ public class Create implements ICommand { return Collections.singletonList("name"); } if(parameter.equals("type")) { - return Arrays.asList("normal", "flat"); + return Arrays.asList("normal", "flat", "nether", "end"); } return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java index 4800e08..985ccdc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java @@ -22,12 +22,14 @@ public class Delete implements ICommand { java.util.List worlds = Main.getInstance().getWorlds(); if(!worlds.contains(args[0])) { sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIST").addAmount(args[0])); + return; } Confirm.Confirmation confirmation = new Confirm.Confirmation(args[0], world -> { java.util.List worlds_now = Main.getInstance().getWorlds(); if(!worlds_now.contains(world)) { sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIST").addAmount(world)); + return; } World bukkit_world = Bukkit.getWorld(world); if(bukkit_world != null && bukkit_world.getPlayers().size() > 0) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java index 2c0f745..bdb98e5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java @@ -4,6 +4,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.ICommand; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.World; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -20,8 +21,18 @@ public class List implements ICommand { } else { StringBuilder response = new StringBuilder(messagePrefix + message("LIST_WORLDS")); for (String world : worlds) { - boolean loaded = Bukkit.getWorld(world) != null; - response.append("\n ").append(world).append(": ").append(loaded ? ChatColor.GREEN + "LOADED" : ChatColor.YELLOW + "NOT LOADED").append(ChatColor.WHITE); + String status = ChatColor.GRAY + "NOT LOADED"; + World bukkit_world = Bukkit.getWorld(world); + if(bukkit_world != null) { + if(bukkit_world.getEnvironment() == World.Environment.NETHER) { + status = ChatColor.RED + "NETHER"; + } else if(bukkit_world.getEnvironment() == World.Environment.THE_END) { + status = ChatColor.YELLOW + "THE END"; + } else { + status = ChatColor.GREEN + bukkit_world.getWorldType().toString(); + } + } + response.append("\n ").append(world).append(": ").append(status).append(ChatColor.WHITE); } sender.sendMessage(response.toString()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index be699ec..958d1ca 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -126,6 +126,7 @@ public class ConfigManager { return config.contains(path); } + @SuppressWarnings("unused") public double getDouble(String path) { if (!config.contains(path)) { return defaultConfig.getDouble(path); @@ -190,10 +191,6 @@ public class ConfigManager { config.set(path, defaultConfig.get(path)); } - public void resetAll() { - config = new YamlConfiguration(); - } - public void resetFile(String newDefaultFilename) { this.defaultFilename = newDefaultFilename; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 83fc2a6..1873fd4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -268,7 +268,7 @@ public class Board { board.setLine(String.valueOf(i), line.replace("{TEAM}", value)); } else if (line.contains("{BORDER}")) { if (!Main.getInstance().getGame().getCurrentMap().isWorldBorderEnabled()) continue; - if (worldBorder == null || status == Status.STARTING) { + if (status == Status.STARTING) { board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replace("{AMOUNT}", "0"))); } else if (!worldBorder.isRunning()) { board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replaceFirst("\\{AMOUNT}", worldBorder.getDelay()/60+"").replaceFirst("\\{AMOUNT}", worldBorder.getDelay()%60+""))); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index e238caf..e18a309 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -97,13 +97,15 @@ public class Game { } public void start() { + Player seeker; try { int rand = (int) (Math.random() * board.getPlayers().size()); - Player seeker = board.getPlayers().get(rand); - start(seeker); + seeker = board.getPlayers().get(rand); } catch (Exception e){ Main.getInstance().getLogger().warning("Failed to select random seeker."); + return; } + start(seeker); } public void start(Player seeker) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java index 1e7ba69..d34cb11 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java @@ -2,7 +2,6 @@ package net.tylermurphy.hideAndSeek.game.listener; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.game.Game; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java index e769b05..10fa783 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -51,7 +51,7 @@ public class Location { this.z = location.getZ(); } - public World load(WorldType type) { + public World load(WorldType type, World.Environment environment) { boolean mapSave = world.startsWith("hs_"); World bukkitWorld = Bukkit.getWorld(world); if(bukkitWorld != null) return bukkitWorld; @@ -59,6 +59,9 @@ public class Location { if(type != null) { creator.type(type); } + if(environment != null) { + creator.environment(environment); + } if(mapSave) { creator.generator(new VoidGenerator()); } @@ -69,7 +72,7 @@ public class Location { public World load() { if(!exists()) return null; if(!Main.getInstance().isLoaded()) return null; - return load(null); + return load(null, null); } private org.bukkit.Location toBukkit() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 864397e..d14f617 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -60,13 +60,15 @@ public class WorldLoader { } public void loadMap() { - 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 " + map.getGameSpawnName()); - return; - } - world.setAutoSave(false); + Main.getInstance().scheduleTask(() -> { + 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 " + map.getGameSpawnName()); + return; + } + world.setAutoSave(false); + }); } public void rollback() { -- cgit v1.2.3-freya From 3ec241766def153204aa995de43279176847e929 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 22 Nov 2022 15:29:39 -0500 Subject: fix seeker/hider returning null --- src/main/java/net/tylermurphy/hideAndSeek/game/Board.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 1873fd4..8c26bc8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -80,11 +80,11 @@ public class Board { } public List getHiders() { - return Hider.stream().filter(Objects::nonNull).map(playerList::get).collect(Collectors.toList()); + return Hider.stream().filter(Objects::nonNull).map(playerList::get).filter(Objects::nonNull).collect(Collectors.toList()); } public List getSeekers() { - return Seeker.stream().filter(Objects::nonNull).map(playerList::get).collect(Collectors.toList()); + return Seeker.stream().filter(Objects::nonNull).map(playerList::get).filter(Objects::nonNull).collect(Collectors.toList()); } public Player getFirstSeeker() { @@ -92,7 +92,7 @@ public class Board { } public List getSpectators() { - return Spectator.stream().filter(Objects::nonNull).map(playerList::get).collect(Collectors.toList()); + return Spectator.stream().filter(Objects::nonNull).map(playerList::get).filter(Objects::nonNull).collect(Collectors.toList()); } public List getPlayers() { -- cgit v1.2.3-freya From 6b453dde9758bc6d4d399528209addc2b817ce1a Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 26 Nov 2022 14:23:39 -0500 Subject: 1.7.0RC1 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 20 +- .../net/tylermurphy/hideAndSeek/command/Help.java | 19 -- .../net/tylermurphy/hideAndSeek/command/Join.java | 19 -- .../net/tylermurphy/hideAndSeek/command/Leave.java | 19 -- .../tylermurphy/hideAndSeek/command/Reload.java | 19 -- .../hideAndSeek/command/SetExitLocation.java | 19 -- .../net/tylermurphy/hideAndSeek/command/Start.java | 28 +-- .../net/tylermurphy/hideAndSeek/command/Stop.java | 19 -- .../net/tylermurphy/hideAndSeek/command/Top.java | 19 -- .../net/tylermurphy/hideAndSeek/command/Wins.java | 19 -- .../tylermurphy/hideAndSeek/command/map/Save.java | 21 +-- .../hideAndSeek/command/map/Status.java | 19 -- .../hideAndSeek/command/map/blockhunt/Enabled.java | 4 + .../command/map/blockhunt/blocks/Add.java | 4 + .../command/map/blockhunt/blocks/List.java | 5 + .../command/map/blockhunt/blocks/Remove.java | 4 + .../hideAndSeek/command/map/set/Border.java | 21 +-- .../hideAndSeek/command/map/set/Bounds.java | 40 ++-- .../hideAndSeek/command/map/set/Lobby.java | 19 -- .../hideAndSeek/command/map/set/SeekerLobby.java | 13 +- .../hideAndSeek/command/map/set/Spawn.java | 29 +-- .../hideAndSeek/command/util/CommandGroup.java | 19 -- .../hideAndSeek/command/util/ICommand.java | 19 -- .../hideAndSeek/configuration/Config.java | 19 -- .../hideAndSeek/configuration/ConfigManager.java | 19 -- .../hideAndSeek/configuration/Items.java | 19 -- .../hideAndSeek/configuration/Localization.java | 22 +-- .../configuration/LocalizationString.java | 19 -- .../tylermurphy/hideAndSeek/configuration/Map.java | 11 +- .../tylermurphy/hideAndSeek/database/Database.java | 19 -- .../hideAndSeek/database/GameDataTable.java | 16 +- .../net/tylermurphy/hideAndSeek/game/Board.java | 205 ++++++++++----------- .../game/listener/WorldInteractHandler.java | 48 +++++ .../tylermurphy/hideAndSeek/game/util/Status.java | 19 -- .../tylermurphy/hideAndSeek/game/util/WinType.java | 19 -- .../net/tylermurphy/hideAndSeek/util/Location.java | 8 + .../hideAndSeek/world/VoidGenerator.java | 19 -- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 19 -- src/main/resources/config.yml | 7 +- src/main/resources/lang/localization_de-DE.yml | 66 ++++++- src/main/resources/lang/localization_en-US.yml | 5 + 41 files changed, 297 insertions(+), 679 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/game/listener/WorldInteractHandler.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index ad49273..36d92ee 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek; import net.tylermurphy.hideAndSeek.command.*; @@ -204,6 +185,7 @@ public class Main extends JavaPlugin implements Listener { getServer().getPluginManager().registerEvents(new MovementHandler(), this); getServer().getPluginManager().registerEvents(new PlayerHandler(), this); getServer().getPluginManager().registerEvents(new RespawnHandler(), this); + getServer().getPluginManager().registerEvents(new WorldInteractHandler(), this); } private void updateVersion(){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 3efddcd..41db5a9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 69387cd..0c01265 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index cb0c745..109930b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index df2944b..0c2b6b1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index 0a57cfc..7da404f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.command.util.ICommand; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 74b8490..5184933 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; @@ -59,13 +40,8 @@ public class Start implements ICommand { } else { seekerName = args[0]; } - Player temp = Bukkit.getPlayer(seekerName); - if (temp == null) { - sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); - return; - } - Player seeker = Main.getInstance().getBoard().getPlayer(temp.getUniqueId()); - if (seeker == null) { + Player seeker = Bukkit.getPlayer(seekerName); + if (seeker == null || !Main.getInstance().getBoard().contains(seeker)) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 4bc23fe..498e30d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 4ac4aa7..13f3069 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index 1ba44ac..fb61fb2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java index a612026..03e23a8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command.map; import net.tylermurphy.hideAndSeek.Main; @@ -53,7 +34,7 @@ public class Save implements ICommand { sender.sendMessage(errorPrefix + message("INVALID_MAP")); return; } - if (map.isSpawnNotSetup()) { + if (map.getSpawn().isNotSetup()) { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java index c7da88a..90615e5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command.map; import net.tylermurphy.hideAndSeek.command.util.ICommand; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java index 14ae8e0..2567427 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -20,6 +20,10 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Enabled implements ICommand { public void execute(Player sender, String[] args) { + if (!Main.getInstance().supports(9)) { + sender.sendMessage(errorPrefix + message("BLOCKHUNT_UNSUPPORTED")); + return; + } if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java index fbdeecb..fea08ef 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java @@ -20,6 +20,10 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Add implements ICommand { public void execute(Player sender, String[] args) { + if (!Main.getInstance().supports(9)) { + sender.sendMessage(errorPrefix + message("BLOCKHUNT_UNSUPPORTED")); + return; + } if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java index 18f1b3c..de783ce 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java @@ -1,5 +1,6 @@ package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; @@ -17,6 +18,10 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class List implements ICommand { public void execute(Player sender, String[] args) { + if (!Main.getInstance().supports(9)) { + sender.sendMessage(errorPrefix + message("BLOCKHUNT_UNSUPPORTED")); + return; + } Map map = Maps.getMap(args[0]); if(map == null) { sender.sendMessage(errorPrefix + message("INVALID_MAP")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java index d2afdc1..1c16fdc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java @@ -20,6 +20,10 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Remove implements ICommand { public void execute(Player sender, String[] args) { + if (!Main.getInstance().supports(9)) { + sender.sendMessage(errorPrefix + message("BLOCKHUNT_UNSUPPORTED")); + return; + } if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java index f9e14f8..64bf5d4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.Main; @@ -46,7 +27,7 @@ public class Border implements ICommand { sender.sendMessage(errorPrefix + message("INVALID_MAP")); return; } - if (map.isSpawnNotSetup()) { + if (map.getSpawn().isNotSetup()) { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java index 960863b..3d1f036 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.Main; @@ -24,6 +5,7 @@ import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; +import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -45,10 +27,14 @@ public class Bounds implements ICommand { sender.sendMessage(errorPrefix + message("INVALID_MAP")); return; } - if (map.isSpawnNotSetup()) { + if (map.getSpawn().isNotSetup()) { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } + if (map.getSeekerLobby().isNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SEEKER_SPAWN")); + return; + } if (!sender.getWorld().getName().equals(map.getSpawnName())) { sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); return; @@ -87,6 +73,20 @@ public class Bounds implements ICommand { } map.setBoundMin(bxs, bzs); map.setBoundMax(bxl, bzl); + if(!map.isBoundsNotSetup()) { + if(!map.getSpawn().isNotSetup()) { + if(map.getSpawn().isNotInBounds(bxs, bxl, bzs, bzl)) { + map.setSpawn(Location.getDefault()); + sender.sendMessage(warningPrefix + message("WARN_SPAWN_RESET")); + } + } + if(!map.getSeekerLobby().isNotSetup()) { + if(map.getSeekerLobby().isNotInBounds(bxs, bxl, bzs, bzl)) { + map.setSeekerLobby(Location.getDefault()); + sender.sendMessage(warningPrefix + message("WARN_SEEKER_SPAWN_RESET")); + } + } + } Maps.setMap(map.getName(), map); sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java index ada76e2..6690ae9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.command.util.ICommand; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java index 9bc0249..b6c5cf0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java @@ -6,24 +6,33 @@ import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.util.Location; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.List;; import java.util.stream.Collectors; +import static net.tylermurphy.hideAndSeek.configuration.Config.warningPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SeekerLobby implements ICommand { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { - if(map.isSpawnNotSetup()) { + if(map.getSpawn().isNotSetup()) { 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(Location.from(sender)); + if(!map.isBoundsNotSetup()) { + Vector boundsMin = map.getBoundsMin(); + Vector boundsMax = map.getBoundsMax(); + if(map.getSeekerLobby().isNotInBounds(boundsMin.getBlockX(), boundsMax.getBlockX(), boundsMin.getBlockZ(), boundsMax.getBlockZ())) { + sender.sendMessage(warningPrefix + message("WARN_MAP_BOUNDS")); + } + } }); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java index b983404..0baf55e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.command.util.ICommand; @@ -47,8 +28,16 @@ public class Spawn implements ICommand { map.setSpawn(Location.from(sender)); + if(!map.isBoundsNotSetup()) { + Vector boundsMin = map.getBoundsMin(); + Vector boundsMax = map.getBoundsMax(); + if(map.getSpawn().isNotInBounds(boundsMin.getBlockX(), boundsMax.getBlockX(), boundsMin.getBlockZ(), boundsMax.getBlockZ())) { + sender.sendMessage(warningPrefix + message("WARN_MAP_BOUNDS")); + } + } + if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().equals(sender.getLocation().getWorld().getName())) { - sender.sendMessage(message("SEEKER_LOBBY_SPAWN_RESET").toString()); + sender.sendMessage(warningPrefix + message("SEEKER_LOBBY_SPAWN_RESET")); map.setSeekerLobby(Location.getDefault()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index b366b9a..0cb307b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command.util; import net.tylermurphy.hideAndSeek.command.map.Save; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java index 3aa0ca4..1be678c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.command.util; import org.bukkit.entity.Player; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index dbc9e37..5881d19 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.configuration; import com.cryptomorin.xseries.XItemStack; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 958d1ca..92fa4ce 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.configuration; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index 06dbb99..e5f970b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.configuration; import com.cryptomorin.xseries.XItemStack; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 6f3f88b..b9f9b69 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.configuration; import net.md_5.bungee.api.ChatColor; @@ -38,7 +19,8 @@ public class Localization { }); put("de-DE", new String[][]{ {}, - {"TAUNTED"} + {"TAUNTED"}, + {"GAME_SETUP", "SETUP_GAME", "SETUP_LOBBY", "SETUP_SEEKER_LOBBY", "SETUP_EXIT", "SETUP_SAVEMAP", "SETUP_BOUNDS"} }); }}; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java index 3d8bc0f..b457622 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.configuration; import org.bukkit.entity.Entity; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java index 8c3f8a7..a23a1f7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -3,6 +3,7 @@ package net.tylermurphy.hideAndSeek.configuration; import java.util.ArrayList; import java.util.List; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.events.Border; import net.tylermurphy.hideAndSeek.world.WorldLoader; import net.tylermurphy.hideAndSeek.util.Location; @@ -80,7 +81,11 @@ public class Map { } public void setBlockhunt(boolean enabled, List blocks) { - this.blockhunt = enabled; + if (Main.getInstance().supports(9)) { + this.blockhunt = enabled; + } else { + this.blockhunt = false; + } this.blockhuntBlocks = blocks; } @@ -226,10 +231,6 @@ public class Map { return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; } - public boolean isSpawnNotSetup() { - return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0; - } - public boolean isBoundsNotSetup() { return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java index d2fb40d..dca2de0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.database; import com.google.common.io.ByteStreams; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/GameDataTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/GameDataTable.java index 8f0ddde..c01f615 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/GameDataTable.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/GameDataTable.java @@ -175,10 +175,10 @@ public class GameDataTable { @NotNull Board board, @NotNull List uuids, @NotNull List winners, - @NotNull Map hider_kills, - @NotNull Map hider_deaths, - @NotNull Map seeker_kills, - @NotNull Map seeker_deaths, + @NotNull Map hider_kills, + @NotNull Map hider_deaths, + @NotNull Map seeker_kills, + @NotNull Map seeker_deaths, @NotNull WinType type ) { for(UUID uuid : uuids) { @@ -192,10 +192,10 @@ public class GameDataTable { info.getSeekerWins() + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0), info.getHiderGames() + (board.isHider(uuid) || (board.isSeeker(uuid) && !board.getFirstSeeker().getUniqueId().equals(uuid)) ? 1 : 0), info.getSeekerGames() + (board.getFirstSeeker().getUniqueId().equals(uuid) ? 1 : 0), - info.getHiderKills() + hider_kills.getOrDefault(uuid.toString(), 0), - info.getSeekerKills() + seeker_kills.getOrDefault(uuid.toString(), 0), - info.getHiderDeaths() + hider_deaths.getOrDefault(uuid.toString(), 0), - info.getSeekerDeaths() + seeker_deaths.getOrDefault(uuid.toString(), 0) + info.getHiderKills() + hider_kills.getOrDefault(uuid, 0), + info.getSeekerKills() + seeker_kills.getOrDefault(uuid, 0), + info.getHiderDeaths() + hider_deaths.getOrDefault(uuid, 0), + info.getSeekerDeaths() + seeker_deaths.getOrDefault(uuid, 0) ); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 8c26bc8..2050f33 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.game; import net.tylermurphy.hideAndSeek.Main; @@ -38,109 +19,128 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Board { - private final List Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); - private final Map playerList = new HashMap<>(); - private final Map customBoards = new HashMap<>(); - private final Map hider_kills = new HashMap<>(), seeker_kills = new HashMap<>(), hider_deaths = new HashMap<>(), seeker_deaths = new HashMap<>(); + private enum Type { + HIDER, + SEEKER, + SPECTATOR, + } + + private UUID initialSeeker = null; + private final Map Players = new HashMap<>(); + private final Map customBoards = new HashMap<>(); + private final Map hider_kills = new HashMap<>(), seeker_kills = new HashMap<>(), hider_deaths = new HashMap<>(), seeker_deaths = new HashMap<>(); public boolean contains(Player player) { - return playerList.containsKey(player.getUniqueId().toString()); + return Players.containsKey(player.getUniqueId()); } public boolean isHider(Player player) { - return Hider.contains(player.getUniqueId().toString()); + return isHider(player.getUniqueId()); } public boolean isHider(UUID uuid) { - return Hider.contains(uuid.toString()); + if(!Players.containsKey(uuid)) return false; + return Players.get(uuid) == Type.HIDER; } public boolean isSeeker(Player player) { - return Seeker.contains(player.getUniqueId().toString()); + return isSeeker(player.getUniqueId()); } public boolean isSeeker(UUID uuid) { - return Seeker.contains(uuid.toString()); + if(!Players.containsKey(uuid)) return false; + return Players.get(uuid) == Type.SEEKER; } public boolean isSpectator(Player player) { - return Spectator.contains(player.getUniqueId().toString()); + return isSpectator(player.getUniqueId()); + } + + public boolean isSpectator(UUID uuid) { + if(!Players.containsKey(uuid)) return false; + return Players.get(uuid) == Type.SPECTATOR; } public int sizeHider() { - return Hider.size(); + return getHiders().size(); } public int sizeSeeker() { - return Seeker.size(); + return getSeekers().size(); } public int size() { - return playerList.values().size(); + return getPlayers().size(); } public List getHiders() { - return Hider.stream().filter(Objects::nonNull).map(playerList::get).filter(Objects::nonNull).collect(Collectors.toList()); + return Players.keySet().stream() + .filter(s -> Players.get(s) == Type.HIDER) + .map(Bukkit::getPlayer) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } public List getSeekers() { - return Seeker.stream().filter(Objects::nonNull).map(playerList::get).filter(Objects::nonNull).collect(Collectors.toList()); - } - - public Player getFirstSeeker() { - return playerList.get(Seeker.get(0)); + return Players.keySet().stream() + .filter(s -> Players.get(s) == Type.SEEKER) + .map(Bukkit::getPlayer) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } public List getSpectators() { - return Spectator.stream().filter(Objects::nonNull).map(playerList::get).filter(Objects::nonNull).collect(Collectors.toList()); + return Players.keySet().stream() + .filter(s -> Players.get(s) == Type.SPECTATOR) + .map(Bukkit::getPlayer) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } public List getPlayers() { - return playerList.values().stream().filter(Objects::nonNull).collect(Collectors.toList()); + return Players.keySet().stream() + .map(Bukkit::getPlayer) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + public Player getFirstSeeker() { + if(initialSeeker == null) return null; + return Bukkit.getPlayer(initialSeeker); } public Player getPlayer(UUID uuid) { - return playerList.get(uuid.toString()); + if(!Players.containsKey(uuid)) { + return null; + } + return Bukkit.getPlayer(uuid); } public void addHider(Player player) { - Hider.add(player.getUniqueId().toString()); - Seeker.remove(player.getUniqueId().toString()); - Spectator.remove(player.getUniqueId().toString()); - playerList.put(player.getUniqueId().toString(), player); + Players.put(player.getUniqueId(), Type.HIDER); } public void addSeeker(Player player) { - Hider.remove(player.getUniqueId().toString()); - Seeker.add(player.getUniqueId().toString()); - Spectator.remove(player.getUniqueId().toString()); - playerList.put(player.getUniqueId().toString(), player); + if(initialSeeker == null) { + initialSeeker = player.getUniqueId(); + } + Players.put(player.getUniqueId(), Type.SEEKER); } public void addSpectator(Player player) { - Hider.remove(player.getUniqueId().toString()); - Seeker.remove(player.getUniqueId().toString()); - Spectator.add(player.getUniqueId().toString()); - playerList.put(player.getUniqueId().toString(), player); + Players.put(player.getUniqueId(), Type.SPECTATOR); } public void remove(Player player) { - Hider.remove(player.getUniqueId().toString()); - Seeker.remove(player.getUniqueId().toString()); - Spectator.remove(player.getUniqueId().toString()); - playerList.remove(player.getUniqueId().toString()); + Players.remove(player.getUniqueId()); } public boolean onSameTeam(Player player1, Player player2) { - if (Hider.contains(player1.getUniqueId().toString()) && Hider.contains(player2.getUniqueId().toString())) return true; - else if (Seeker.contains(player1.getUniqueId().toString()) && Seeker.contains(player2.getUniqueId().toString())) return true; - else return Spectator.contains(player1.getUniqueId().toString()) && Spectator.contains(player2.getUniqueId().toString()); + return Players.get(player1.getUniqueId()) == Players.get(player2.getUniqueId()); } public void reload() { - Hider.clear(); - Seeker.clear(); - Spectator.clear(); + Players.replaceAll((u, v) -> Type.HIDER); hider_kills.clear(); seeker_kills.clear(); hider_deaths.clear(); @@ -148,47 +148,38 @@ public class Board { } public void addKill(UUID uuid) { - if (Hider.contains(uuid.toString())) { - if (hider_kills.containsKey(uuid.toString())) { - hider_kills.put(uuid.toString(), hider_kills.get(uuid.toString())+1); - } else { - hider_kills.put(uuid.toString(), 1); - } - } else if (Seeker.contains(uuid.toString())) { - if (seeker_kills.containsKey(uuid.toString())) { - seeker_kills.put(uuid.toString(), seeker_kills.get(uuid.toString())+1); - } else { - seeker_kills.put(uuid.toString(), 1); - } + if(Players.get(uuid) == Type.HIDER) { + int kills = hider_kills.getOrDefault(uuid, 0); + hider_kills.put(uuid, kills + 1); + } else if(Players.get(uuid) == Type.SEEKER) { + int kills = seeker_kills.getOrDefault(uuid, 0); + seeker_kills.put(uuid, kills + 1); } } public void addDeath(UUID uuid) { - if (Hider.contains(uuid.toString())) { - if (hider_deaths.containsKey(uuid.toString())) { - hider_deaths.put(uuid.toString(), hider_deaths.get(uuid.toString())+1); - } else { - hider_deaths.put(uuid.toString(), 1); - } - } else if (Seeker.contains(uuid.toString())) { - if (seeker_deaths.containsKey(uuid.toString())) { - seeker_deaths.put(uuid.toString(), seeker_deaths.get(uuid.toString())+1); - } else { - seeker_deaths.put(uuid.toString(), 1); - } + if(Players.get(uuid) == Type.HIDER) { + int kills = hider_deaths.getOrDefault(uuid, 0); + hider_deaths.put(uuid, kills + 1); + } else if(Players.get(uuid) == Type.SEEKER) { + int kills = seeker_deaths.getOrDefault(uuid, 0); + seeker_deaths.put(uuid, kills + 1); } } - public Map getHiderKills() { + public Map getHiderKills() { return new HashMap<>(hider_kills); } - public Map getSeekerKills() { + + public Map getSeekerKills() { return new HashMap<>(seeker_kills); } - public Map getHiderDeaths() { + + public Map getHiderDeaths() { return new HashMap<>(hider_deaths); } - public Map getSeekerDeaths() { + + public Map getSeekerDeaths() { return new HashMap<>(seeker_deaths); } @@ -197,7 +188,7 @@ public class Board { } private void createLobbyBoard(Player player, boolean recreate) { - CustomBoard board = customBoards.get(player.getUniqueId().toString()); + CustomBoard board = customBoards.get(player.getUniqueId()); if (recreate || board == null) { board = new CustomBoard(player, LOBBY_TITLE); board.updateTeams(); @@ -228,7 +219,7 @@ public class Board { i++; } board.display(); - customBoards.put(player.getUniqueId().toString(), board); + customBoards.put(player.getUniqueId(), board); } public String getMapName() { @@ -242,7 +233,7 @@ public class Board { } private void createGameBoard(Player player, boolean recreate) { - CustomBoard board = customBoards.get(player.getUniqueId().toString()); + CustomBoard board = customBoards.get(player.getUniqueId()); if (recreate || board == null) { board = new CustomBoard(player, GAME_TITLE); board.updateTeams(); @@ -279,7 +270,7 @@ public class Board { if (!tauntEnabled) continue; if (taunt == null || status == Status.STARTING) { board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replace("{AMOUNT}", "0"))); - } else if (!tauntLast && Hider.size() == 1) { + } else if (!tauntLast && sizeHider() == 1) { board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_EXPIRED)); } else if (!taunt.isRunning()) { board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replaceFirst("\\{AMOUNT}", taunt.getDelay() / 60 + "").replaceFirst("\\{AMOUNT}", taunt.getDelay() % 60 + ""))); @@ -306,23 +297,23 @@ public class Board { i++; } board.display(); - customBoards.put(player.getUniqueId().toString(), board); + customBoards.put(player.getUniqueId(), board); } public void removeBoard(Player player) { ScoreboardManager manager = Bukkit.getScoreboardManager(); assert manager != null; player.setScoreboard(manager.getMainScoreboard()); - customBoards.remove(player.getUniqueId().toString()); + customBoards.remove(player.getUniqueId()); } public void reloadLobbyBoards() { - for(Player player : playerList.values()) + for(Player player : getPlayers()) createLobbyBoard(player, false); } public void reloadGameBoards() { - for(Player player : playerList.values()) + for(Player player : getPlayers()) createGameBoard(player, false); } @@ -332,17 +323,19 @@ public class Board { } private String getSeekerPercent() { - if (playerList.values().size() < 2) + int size = size(); + if (size < 2) return " --"; else - return " "+(int)(100*(1.0/playerList.size())); + return " "+(int)(100*(1.0/size)); } private String getHiderPercent() { - if (playerList.size() < 2) + int size = size(); + if (size < 2) return " --"; else - return " "+(int)(100-100*(1.0/playerList.size())); + return " "+(int)(100-100*(1.0/size)); } private String getTeam(Player player) { @@ -353,10 +346,8 @@ public class Board { } public void cleanup() { - playerList.clear(); - Hider.clear(); - Seeker.clear(); - Spectator.clear(); + Players.clear();; + initialSeeker = null; customBoards.clear(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/WorldInteractHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/WorldInteractHandler.java new file mode 100644 index 0000000..10b8e3e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/WorldInteractHandler.java @@ -0,0 +1,48 @@ +package net.tylermurphy.hideAndSeek.game.listener; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.Board; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityBreakDoorEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; + +public class WorldInteractHandler implements Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + public void onBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + Board board = Main.getInstance().getBoard(); + if(board.contains(player)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onHangingEntityBreakByEntity(HangingBreakByEntityEvent event) { + if (!(event.getRemover() instanceof Player)) { + return; + } + Player player = (Player) event.getRemover(); + Board board = Main.getInstance().getBoard(); + if(board.contains(player)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onBreakDoor(EntityBreakDoorEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + Player player = (Player) event.getEntity(); + Board board = Main.getInstance().getBoard(); + if(board.contains(player)) { + event.setCancelled(true); + } + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Status.java index e630070..44f19b2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/util/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Status.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.game.util; public enum Status { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/WinType.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/WinType.java index f584d80..24544ba 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/util/WinType.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/WinType.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.game.util; public enum WinType { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java index 10fa783..a5060c6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -134,4 +134,12 @@ public class Location { return destination.isDirectory(); } + public boolean isNotSetup() { + return getBlockX() == 0 && getBlockY() == 0 && getBlockZ() == 0; + } + + public boolean isNotInBounds(int xmin, int xmax, int zmin, int zmax) { + return getBlockX() < xmin || getBlockX() > xmax || getBlockZ() < zmin || getBlockZ() > zmax; + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java index 15ff45f..4f9ad0d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.world; import org.bukkit.Location; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index d14f617..e5913aa 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -1,22 +1,3 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - package net.tylermurphy.hideAndSeek.world; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 389352a..82b9379 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -268,11 +268,8 @@ locale: "en-US" # playing the game. blockedCommands: [ "msg", - "tp", - "gamemode", - "kill", - "give", - "effect" + "reply", + "me" ] # Stop interactions with any block by any user while playing the game. diff --git a/src/main/resources/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index 9789a75..92309ee 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -10,6 +10,7 @@ Localization: COMMAND_PLAYER_ONLY: "Dieser Befehl kann nur als Spieler ausgeführt werden." COMMAND_NOT_ALLOWED: "Es ist dir nicht gestattet diesen Befehl auszuführen." COMMAND_ERROR: "Ein unbekannter Fehler ist aufgetreten." + COMMAND_INVALID_ARG: "Ungültiges Argument: {AMOUNT}" GAME_PLAYER_DEATH: "&c{PLAYER}&f ist gestorben." GAME_PLAYER_FOUND: "&e{PLAYER}&f wurde gefunden und ist nun ein Seeker." GAME_PLAYER_FOUND_BY: "&e{PLAYER}&f wurde von &c{PLAYER}&f gefunden und ist nun ein Seeker." @@ -17,7 +18,7 @@ Localization: GAME_GAMEOVER_SEEKERS_QUIT: "All Seeker haben das Spiel verlassen." GAME_GAMEOVER_HIDERS_QUIT: "All Hider haben das Spiel verlassen." GAME_GAMEOVER_TIME: "Seekers haben keine Spielzeit mehr. Die Hiders haben gewonnen!" - GAME_SETUP: "Spiel wurde noch nicht eingerichtet. Führe &c/hs setup&f aus, um die Einrichtungsschritte zu sehen." + GAME_SETUP: "Es gibt keine Setup-Karten! Führen Sie /hs map status auf einer Karte aus, um zu sehen, was Sie tun müssen." GAME_INGAME: "Du bist bereits in der Lobby oder im Spiel." GAME_NOT_INGAME: "Du bist weder in einer Lobby noch in einem Spiel." GAME_INPROGRESS: "Es läuft bereits ein Spiel." @@ -25,6 +26,7 @@ Localization: GAME_JOIN: "{PLAYER} hat die Hide and Seek Lobby betreten." GAME_JOIN_SPECTATOR: "Du bist als Beobachter einem laufenden Spiel beigetreten." GAME_LEAVE: "{PLAYER} hat die Hide and Seek Lobby verlassen." + LOBBY_IN_USE: "Die Lobby kann nicht verändert werden, solange die Lobby nicht leer ist." CONFIG_RELOAD: "Konfiguration neu geladen." MAPSAVE_INPROGRESS: "Weltkarte wird aktuell gespeichert. Versuche es später nochmal." MAPSAVE_START: "Starte Speichervorgang der Weltkarte" @@ -32,6 +34,9 @@ Localization: MAPSAVE_END: "Speichervorgang abgeschlossen." MAPSAVE_ERROR: "Aktuelle Weltkarte konnte nicht gefunden werden." MAPSAVE_DISABLED: "Mapsave ist in config.yml deaktiviert." + MAPSAVE_FAIL_WORLD: "Mapsave fehlgeschlagen. Die aktuelle Welt konnte nicht geladen werden." + MAPSAVE_INVALID: "Ungültige Welt zum Speichern: {AMOUNT}" + MAPSAVE_FAIL_DIR: "Verzeichnis konnte nicht umbenannt werden: {AMOUNT}" WORLDBORDER_DISABLE: "World Border ausgeschaltet." WORLDBORDER_INVALID_INPUT: "Ungültiger Wert: {AMOUNT}" WORLDBORDER_MIN_SIZE: "World Border darf nicht geringer als 100 Blöcke sein." @@ -39,24 +44,32 @@ Localization: WORLDBORDER_ENABLE: "Setze World Border zentriert von dieser Position aus. Größe: {AMOUNT}. Verzögerung: {AMOUNT}." WORLDBORDER_DECREASING: "World Norder schrumpoft 100 Blöcke über die nächsten 30 Sekunden!" WORLDBORDER_WARN: "Die Weltgrenze wird in den nächsten 30er Jahren schrumpfen!" + WORLDBORDER_CHANGE_SIZE: "Die Änderung der Weltgrenze kann nicht 0 oder weniger sein." TAUNTED: "&c&oOh nein! Du wurdest geärgert!" TAUNT: "Ein zufälliger Hider wird in den nächsten 30 Sekunden geärgert." TAUNT_ACTIVATE: "Ärgern wurde aktiviert" ERROR_GAME_SPAWN: "Bitte erst die Spawn-Position für das Spiel festlegen." + ERROR_GAME_SEEKER_SPAWN: "Bitte setze zuerst den Sucher-Spawn-Ort" + ERROR_MAP_BOUNDS: "Bitte setzen Sie die Grenzen der Karte vor dem Speichern" + WARN_MAP_BOUNDS: "Dieser Ort liegt nicht innerhalb der Kartengrenzen, dies könnte Probleme verursachen" + WARN_SPAWN_RESET: "Spiel-Spawn wurde zurückgesetzt, da er nicht innerhalb der Kartengrenzen liegt" + WARN_SEEKER_SPAWN_RESET: "Seeker-Spawn zurückgesetzt, da er nicht innerhalb der Kartengrenzen liegt" SETUP: "&f&lFühre die folgenden Schritte zur Einrichtung aus:" - SETUP_GAME: "&c&l- &fTeleport-Position für den Spielbeginn festlegen mit /hs setspawn" - SETUP_LOBBY: "&c&l- &fTeleport-Position für die Lobby festlegen mit /hs setlobby" - SETUP_SEEKER_LOBBY: "&c&l- &fTeleport-Position für die Lobby Seekern festlegen mit /hs setseekerlobby" - SETUP_EXIT: "&c&l- &fTeleport-Position für das Spielende festlegen mit /hs setexit" - SETUP_SAVEMAP: "&c&l- &fHide and Seek Weltkarte speichern mit /hs savemap (nach /hs setspawn)" + SETUP_GAME: "&c&l- &fSpielspawn ist nicht gesetzt, /hs map set spawn " + SETUP_LOBBY: "&c&l- &fLobby-Spawn ist nicht gesetzt, /hs map set lobby " + SETUP_SEEKER_LOBBY: "&c&l- &fSucherlobby-Spawn ist nicht gesetzt, /hs map set seekerlobby " + SETUP_EXIT: "&c&l- &fBeenden/Verlassen der Teleportposition ist nicht festgelegt, /hs setexit" + SETUP_SAVEMAP: "&c&l- &fVerstecken und Suchen Karte wird nicht gespeichert, /hs map save " SETUP_COMPLETE: "Alles eingerichtet! Hide and Seek ist spielbereit." - SETUP_BOUNDS: "&c&l- &fSpielgrenze in 2 gegenüberliegenden Ecken der Welt festlegen mit /hs setbounds" + SETUP_BLOCKHUNT: "&c&l - &fWenn Blockhunt aktiviert ist, muss mindestens 1 Block gesetzt sein, /hs map blockhunt block add block " + SETUP_BOUNDS: "&c&l- &fBitte setzen Sie Spielgrenzen in 2 gegenüberliegenden Ecken der Spielkarte, /hs map set bounds " GAME_SPAWN: "Teleport-Position für Spielbeginn festgelegt" LOBBY_SPAWN: "Teleport-Position für Lobby festgelegt" EXIT_SPAWN: "Teleport-Position für Spielende festgelegt" SEEKER_SPAWN: "Teleport-Position für Seeker Lobby festgelegt" START_MIN_PLAYERS: "Um das Spiel zu starten benötigst du mindestens {AMOUNT} Spieler." START_INVALID_NAME: "Ungültiger Spieler: {PLAYER}." + START_FAILED_SEEKER: "Zufälliger Sucher konnte nicht ausgewählt werden." START_COUNTDOWN: "Die Hider haben {AMOUNT} Sekunden Zeit sich zu verstecken!" START_COUNTDOWN_LAST: "Die Hider haben {AMOUNT} Sekunde Zeit sich zu verstecken!" START: "Los, Seeker! Es ist Zeit, die Hider zu finden." @@ -76,7 +89,44 @@ Localization: FLYING_ENABLED: "Fliegen aktiviert" FLYING_DISABLED: "Fliegen deaktiviert" RESPAWN_NOTICE: "Du wirst in {AMOUNT} Sekunden respawnen." + INVALID_MAP: "Das ist ein ungültiger Kartenname!" + MAP_ALREADY_EXISTS: "Diese Karte existiert bereits!" + INVALID_MAP_NAME: "Der Name darf nur Zahlen oder Buchstaben enthalten." + MAP_CREATED: "Neue Karte erstellt: {AMOUNT}" + MAP_FAIL_DELETE: "Karte konnte nicht gelöscht werden: {AMOUNT}" + MAP_DELETED: "Gelöschte Landkarte: {AMOUNT}" + NO_MAPS: "Es gibt keine Karten im Plugin (/hs map add )" + MAP_NOT_SETUP: "Die Karte {AMOUNT} ist nicht eingerichtet (/hs map status )" + LIST_MAPS: "Die aktuellen Karten sind:" + ARGUMENT_COUNT: "Dieser Befehl erfordert mehr Argumente zur Ausführung." + GAME_SPAWN_NEEDED: "Der Hauptspawn muss vor dem Sucherspawn gesetzt werden." + SEEKER_LOBBY_SPAWN_RESET: "Der Spawn der Seeker-Lobby wurde zurückgesetzt, da der Spiel-Spawn in eine neue Welt verschoben wurde." + SEEKER_LOBBY_INVALID: "Die Lobby des Suchers muss sich in der gleichen Welt befinden, in der das Spiel startet." + CONFIG_ERROR: "Fehler beim Neuladen der Konfiguration. Prüfen Sie die Serverprotokolle." + BLOCKHUNT_DISABLED: "Bitte aktivieren Sie Blockhunt in dieser Karte in der maps.yml, um Verkleidungen zu ermöglichen. Blockhunt funktioniert nicht auf 1.8" + BLOCKHUNT_UNSUPPORTED: "Blockhunt funktioniert nicht unter 1.8" + BLOCKHUNT_SET_TO: "Blockjagd eingestellt auf {AMOUNT}." + BLOCKHUNT_BLOCK_EXISTS: "{AMOUNT} ist bereits in der Blockhunt-Konfiguration eingestellt." + BLOCKHUNT_BLOCK_DOESNT_EXIT: "{AMOUNT} ist bereits nicht in der blochunt-Konfiguration eingestellt." + BLOCKHUNT_BLOCK_ADDED: "{AMOUNT} zur Blockhunt-Konfiguration hinzugefügt." + BLOCKHUNT_BLOCK_REMOVED: "Entfernt {AMOUNT} aus der Blockhunt-Konfiguration." + BLOCKHUNT_LIST_BLOCKS: "Die folgenden Blockhunt-Blöcke sind:" + NO_BLOCKS: "Auf dieser Karte gibt es keine Blockhunt-Blöcke." + WORLD_EXISTS: "Eine Welt namens {AMOUNT} existiert bereits." + WORLD_DOESNT_EXIST: "Es gibt keine Welt namens {AMOUNT}, die existiert." + WORLD_ADDED: "Eine Welt mit dem Namen {AMOUNT} erstellt." + WORLD_ADDED_FAILED: "Fehlgeschlagen, eine neue Welt zu erschaffen." + WORLD_REMOVED: "Eine Welt namens {AMOUNT} wurde gelöscht." + WORLD_REMOVED_FAILED: "Welt konnte nicht gelöscht werden." + WORLD_NOT_EMPTY: "In einer zu löschenden Welt darf es keine Spieler geben." + LIST_WORLDS: "Die folgenden Welten sind:" + NO_WORLDS: "Failed to fetch any worlds." + WORLD_LOAD_FAILED: "Es konnten keine Welten geholt werden." + INVALID_WORLD_TYPE: "Ungültiger Welttyp: {AMOUNT}." + NO_CONFIRMATION: "Sie haben nichts zu bestätigen." + CONFIRMATION_TIMED_OUT: "Die Zeit für die Bestätigung ist abgelaufen." + CONFIRMATION: "Führen Sie /hs confirm innerhalb von 10s aus, um zu bestätigen." # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE -version: 3 +version: 4 type: "de-DE" diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 61d562b..062f4f2 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -49,7 +49,11 @@ Localization: TAUNT: "A random hider will be taunted in the next 30s." TAUNT_ACTIVATE: "Taunt has been activated." ERROR_GAME_SPAWN: "Please set game spawn location first" + ERROR_GAME_SEEKER_SPAWN: "Please set seeker spawn location first" ERROR_MAP_BOUNDS: "Please set map bounds before saving" + WARN_MAP_BOUNDS: "This location is not inside map bounds, this could cause issues" + WARN_SPAWN_RESET: "Game spawn reset due to not being inside map bounds" + WARN_SEEKER_SPAWN_RESET: "Seeker spawn reset due to not being inside map bounds" SETUP: "&f&lThe following is needed for setup..." SETUP_GAME: "&c&l- &fGame spawn isn't set, /hs map set spawn " SETUP_LOBBY: "&c&l- &fLobby spawn isn't set, /hs map set lobby " @@ -100,6 +104,7 @@ Localization: SEEKER_LOBBY_INVALID: "Seeker lobby must be in the same world as game spawn." CONFIG_ERROR: "Error reloading config. Check server logs." BLOCKHUNT_DISABLED: "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8" + BLOCKHUNT_UNSUPPORTED: "Blockhunt does not work on 1.8" BLOCKHUNT_SET_TO: "Blockhunt set to {AMOUNT}." BLOCKHUNT_BLOCK_EXISTS: "{AMOUNT} is already set in the blockhunt config." BLOCKHUNT_BLOCK_DOESNT_EXIT: "{AMOUNT} is already not set in the blochunt config." -- cgit v1.2.3-freya From 0ea945d84ef519b0676793d60eb4d8b47c788e7c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 24 Jan 2023 11:50:01 -0500 Subject: 1.7.0 rc2 (1.19.3 datawater fix) --- .github/ISSUE_TEMPLATE/bug_report.md | 33 ---------- .github/ISSUE_TEMPLATE/feature_request.md | 20 ------ .github/PULL_REQUEST_TEMPLATE.md | 11 ---- .github/workflows/beta.yml | 37 ----------- .github/workflows/release.yml | 37 ----------- lib/ProtocolLib.jar | Bin 0 -> 4875977 bytes pom.xml | 14 ++--- .../tylermurphy/hideAndSeek/game/Disguiser.java | 1 + .../tylermurphy/hideAndSeek/game/EntityHider.java | 6 +- .../tylermurphy/hideAndSeek/game/events/Glow.java | 24 +++---- .../hideAndSeek/util/packet/AbstractPacket.java | 4 +- .../util/packet/EntityMetadataPacket.java | 70 +++++++++++++++++++++ 12 files changed, 88 insertions(+), 169 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/beta.yml delete mode 100644 .github/workflows/release.yml create mode 100644 lib/ProtocolLib.jar create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/packet/EntityMetadataPacket.java diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index bf64440..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: bug report -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**System Info (please complete the following information):** - - OS: [e.g. Windows/Linux] - - Server Host [e.g. Apex/Custom] - - MC Version [e.g. 1.17/1.18] - - Plugin Version [e.g. 1.3.0/1.3.1 BETA] - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 4aea407..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: new plugin feature -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 977e3be..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,11 +0,0 @@ -**Describe the change** -A clear and concise description of what the changes are. - -**Expected behavior** -A clear and concise description of what your changes are going to do. - -**Screenshots** -If applicable, add screenshots to help explain your changes. - -**Additional context** -Add any other context about the pull request here. diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml deleted file mode 100644 index 7adde3f..0000000 --- a/.github/workflows/beta.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Beta - -on: - push: - branches-ignore: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - - name: Build with Maven - run: | - mvn -B package --file pom.xml - mkdir staging && cp target/*.jar staging - - - name: Set up a cache for maven - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - - name: Upload artifacts - uses: actions/upload-artifact@v2 - with: - name: artifacts-beta - path: staging diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 722d1c6..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Release - -on: - push: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - - name: Build with Maven - run: | - mvn -B package --file pom.xml - mkdir staging && cp target/*.jar staging - - - name: Set up a cache for maven - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - - name: Upload artificats - uses: actions/upload-artifact@v2 - with: - name: artifacts-release - path: staging diff --git a/lib/ProtocolLib.jar b/lib/ProtocolLib.jar new file mode 100644 index 0000000..47b952f Binary files /dev/null and b/lib/ProtocolLib.jar differ diff --git a/pom.xml b/pom.xml index 8b2a39d..df2ab1b 100644 --- a/pom.xml +++ b/pom.xml @@ -80,10 +80,10 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/public/ - - dmulloy2-repo - https://repo.dmulloy2.net/repository/public/ - + + + + placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -106,9 +106,9 @@ com.comphenix.protocol ProtocolLib - 4.4.0 - - + 4.8.0 + system + ${project.basedir}/lib/ProtocolLib.jar org.xerial diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java index 5fce7d3..351ba10 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java @@ -17,6 +17,7 @@ public class Disguiser { public Disguiser(){ this.disguises = new HashMap<>(); + } public Disguise getDisguise(Player player){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java index 8274655..3892f6f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java @@ -235,11 +235,7 @@ public class EntityHider implements Listener { destroyEntity.getIntegerArrays().write(0, new int[]{entity.getEntityId()}); } catch (Exception e){ return false; } // Make the entity disappear - try { - manager.sendServerPacket(observer, destroyEntity); - } catch (InvocationTargetException e) { - throw new RuntimeException("Cannot send server packet.", e); - } + manager.sendServerPacket(observer, destroyEntity); } return visibleBefore; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/game/events/Glow.java index 8631ef5..dec23d7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/events/Glow.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/events/Glow.java @@ -6,6 +6,7 @@ import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedDataWatcher; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.packet.EntityMetadataPacket; import org.bukkit.entity.Player; import java.lang.reflect.InvocationTargetException; @@ -64,22 +65,13 @@ public class Glow { } public void setGlow(Player player, Player target, boolean glowing) { - PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA); - packet.getIntegers().write(0, target.getEntityId()); - WrappedDataWatcher watcher = new WrappedDataWatcher(); - WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class); - watcher.setEntity(target); - if (glowing) { - watcher.setObject(0, serializer, (byte) (0x40)); - } else { - watcher.setObject(0, serializer, (byte) (0x0)); - } - packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); - try { - protocolManager.sendServerPacket(player, packet); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } + + EntityMetadataPacket packet = new EntityMetadataPacket(); + packet.setEntity(target); + packet.setGlow(glowing); + packet.writeMetadata(); + packet.send(player); + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java b/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java index 9293beb..4e3fc3b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java @@ -23,9 +23,7 @@ public class AbstractPacket { } public void send(Player player){ - try { - protocolManager.sendServerPacket(player, packet); - } catch (InvocationTargetException ignored) {} + protocolManager.sendServerPacket(player, packet); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/packet/EntityMetadataPacket.java b/src/main/java/net/tylermurphy/hideAndSeek/util/packet/EntityMetadataPacket.java new file mode 100644 index 0000000..d77a227 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/packet/EntityMetadataPacket.java @@ -0,0 +1,70 @@ +package net.tylermurphy.hideAndSeek.util.packet; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.wrappers.WrappedDataValue; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import com.comphenix.protocol.wrappers.WrappedWatchableObject; +import org.bukkit.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class EntityMetadataPacket extends AbstractPacket { + + private final WrappedDataWatcher watcher; + private final WrappedDataWatcher.Serializer serializer; + + public EntityMetadataPacket(){ + super(PacketType.Play.Server.ENTITY_METADATA); + watcher = new WrappedDataWatcher(); + serializer = WrappedDataWatcher.Registry.get(Byte.class); + } + + public void setEntity(@NotNull Entity target){ + super.packet.getIntegers().write(0, target.getEntityId()); + watcher.setEntity(target); + } + + public void setGlow(boolean glowing){ + if (glowing) { + watcher.setObject(0, serializer, (byte) (0x40)); + } else { + watcher.setObject(0, serializer, (byte) (0x0)); + } + } + + public void writeMetadata() { + + // thank you to + // https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/ + + try { + // 1.19.3 And Up + Class.forName("com.comphenix.protocol.wrappers.WrappedDataValue"); + + final List wrappedDataValueList = new ArrayList<>(); + + for(final WrappedWatchableObject entry : watcher.getWatchableObjects()) { + if(entry == null) continue; + + final WrappedDataWatcher.WrappedDataWatcherObject watcherObject = entry.getWatcherObject(); + wrappedDataValueList.add( + new WrappedDataValue( + watcherObject.getIndex(), + watcherObject.getSerializer(), + entry.getRawValue() + ) + ); + } + + packet.getDataValueCollectionModifier().write(0, wrappedDataValueList); + + } catch (ClassCastException | ClassNotFoundException ignored) { + // 1.9 to 1.19.2 And Up + packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); + } + + } + +} \ No newline at end of file -- cgit v1.2.3-freya From 8541dbe99ec992f594305b4223de70712565d870 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 5 Feb 2023 13:47:49 -0500 Subject: 1.7.0 rc3 --- src/main/java/net/tylermurphy/hideAndSeek/command/Send.java | 1 + src/main/java/net/tylermurphy/hideAndSeek/util/Location.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java index 95c0dd9..43620c5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java @@ -40,6 +40,7 @@ public class Send implements ICommand { } Main.getInstance().getGame().setCurrentMap(map); + Main.getInstance().getBoard().reloadLobbyBoards(); for(Player player : Main.getInstance().getBoard().getPlayers()) { map.getLobby().teleport(player); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java index a5060c6..606b64b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -87,7 +87,7 @@ public class Location { public void teleport(Player player) { if(!exists()) return; if(load() == null) return; - Main.getInstance().scheduleTask(() -> player.teleport(toBukkit())); + player.teleport(toBukkit()); } public Location changeWorld(String world) { -- cgit v1.2.3-freya