From 90b99235257770e39a96f4d54293e4ebd7f6256c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 14 May 2022 21:12:27 -0400 Subject: [PATCH] debug menu and 1.8/1.14 fixes --- .../hideAndSeek/command/About.java | 4 +- .../hideAndSeek/command/Debug.java | 111 ++++++++++++++++++ .../tylermurphy/hideAndSeek/command/Help.java | 4 +- .../hideAndSeek/command/ICommand.java | 4 +- .../tylermurphy/hideAndSeek/command/Join.java | 3 +- .../hideAndSeek/command/Leave.java | 3 +- .../hideAndSeek/command/Reload.java | 4 +- .../hideAndSeek/command/SaveMap.java | 4 +- .../hideAndSeek/command/SetBorder.java | 3 +- .../hideAndSeek/command/SetBounds.java | 3 +- .../hideAndSeek/command/Setup.java | 4 +- .../hideAndSeek/command/Start.java | 3 +- .../tylermurphy/hideAndSeek/command/Stop.java | 4 +- .../tylermurphy/hideAndSeek/command/Top.java | 4 +- .../tylermurphy/hideAndSeek/command/Wins.java | 3 +- .../command/location/SetExitLocation.java | 10 +- .../command/location/SetLobbyLocation.java | 10 +- .../command/location/SetSpawnLocation.java | 14 +-- .../command/location/util/LocationUtils.java | 4 +- .../command/location/util/Locations.java | 3 + .../tylermurphy/hideAndSeek/game/Board.java | 7 +- .../game/listener/InteractHandler.java | 21 +++- .../game/listener/MovementHandler.java | 1 - .../hideAndSeek/util/CommandHandler.java | 10 +- .../hideAndSeek/world/WorldLoader.java | 3 + src/main/resources/plugin.yml | 6 +- 26 files changed, 186 insertions(+), 64 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 046c2d8..f996519 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -20,11 +20,11 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class About implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { sender.sendMessage( String.format("%s%sHide and Seek %s(%s1.4.3%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java new file mode 100644 index 0000000..a051d8e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java @@ -0,0 +1,111 @@ +package net.tylermurphy.hideAndSeek.command; + +import com.cryptomorin.xseries.XMaterial; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.util.PlayerUtil; +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.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; + +public class Debug implements ICommand { + + private static final Map> debugMenuFunctions = new HashMap<>(); + private Inventory debugMenu; + + public void execute(Player sender, String[] args) { + if(debugMenu == null) createMenu(); + sender.openInventory(debugMenu); + } + + private void createMenu(){ + debugMenu = Main.getInstance().getServer().createInventory(null, 9, "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(); + } + Main.getInstance().getBoard().addHider(player); + PlayerUtil.loadHider(player, Main.getInstance().getGame().getGameWorld()); + PlayerUtil.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(); + } + Main.getInstance().getBoard().addSeeker(player); + PlayerUtil.loadSeeker(player, Main.getInstance().getGame().getGameWorld()); + PlayerUtil.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(); + } + Main.getInstance().getBoard().addSpectator(player); + PlayerUtil.loadSpectator(player, Main.getInstance().getGame().getGameWorld()); + })); + debugMenu.setItem(3, createOption(3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> { + Main.getInstance().getBoard().remove(player); + PlayerUtil.unloadPlayer(player); + player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + })); + 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){ + player.setHealth(0.1); + } + })); + debugMenu.setItem(6, createOption(6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { + if(mapSaveEnabled) { + if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap(); + } + player.teleport(new Location(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + })); + 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())); + })); + } + + private ItemStack createOption(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); + return temp; + } + + public static void handleOption(Player player, int slotId){ + Main.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { + Consumer callback = debugMenuFunctions.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"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 11b0b0a..97224d7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -21,11 +21,11 @@ package net.tylermurphy.hideAndSeek.command; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.util.CommandHandler; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class Help implements ICommand { - public void execute(CommandSender sender, String[] args) { + 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")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java index 6404c22..275d189 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java @@ -19,11 +19,11 @@ package net.tylermurphy.hideAndSeek.command; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public interface ICommand { - void execute(CommandSender sender, String[] args); + void execute(Player sender, String[] args); String getLabel(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index eb8fd82..941cec0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -21,7 +21,6 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; @@ -29,7 +28,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Join implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().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 0b895b4..092ff50 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -21,7 +21,6 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; @@ -29,7 +28,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Leave implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 0f959f2..56f4517 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -24,7 +24,7 @@ import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; @@ -32,7 +32,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Reload implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index e69c882..1e66395 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -23,7 +23,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -33,7 +33,7 @@ public class SaveMap implements ICommand { public static boolean runningBackup = false; - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { if (!mapSaveEnabled) { sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index 3286c74..45e66b9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -21,7 +21,6 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -30,7 +29,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetBorder implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index 7d2da96..90ecb28 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -21,7 +21,6 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -29,7 +28,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetBounds implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index 0bedcb5..7b29f79 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.io.File; @@ -29,7 +29,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Setup implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { String msg = message("SETUP").toString(); int count = 0; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index b1e5895..18bcbba 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -22,7 +22,6 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.Optional; @@ -34,7 +33,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Start implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().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 b5f0c17..9280b53 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -21,7 +21,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import static net.tylermurphy.hideAndSeek.configuration.Config.abortPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; @@ -29,7 +29,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Stop implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().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/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 4f2c628..e0aa2fb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -22,7 +22,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.database.PlayerInfo; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.util.List; @@ -31,7 +31,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Top implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { int page; if (args.length == 0) page = 1; else try{ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index e12e094..bb69cd4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -22,7 +22,6 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.database.PlayerInfo; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.UUID; @@ -32,7 +31,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Wins implements ICommand { - public void execute(CommandSender sender, String[] args) { + public void execute(Player sender, String[] args) { Main.getInstance().getServer().getScheduler().runTaskAsynchronously(Main.getInstance(), () -> { UUID uuid; 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 abe6f69..93c0d8c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -22,18 +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 org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetExitLocation implements ICommand { - public void execute(CommandSender sender, String[] args) { - if (!(sender instanceof Player)) return; - Player player = (Player) sender; - - LocationUtils.setLocation(player, Locations.EXIT, vector -> { - exitWorld = player.getLocation().getWorld().getName(); + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.EXIT, vector -> { + exitWorld = sender.getLocation().getWorld().getName(); exitPosition = vector; }); } 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 fab7076..eb228f9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -22,19 +22,15 @@ 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 org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetLobbyLocation implements ICommand { - public void execute(CommandSender sender, String[] args) { - if (!(sender instanceof Player)) return; - Player player = (Player) sender; - - LocationUtils.setLocation(player, Locations.LOBBY, vector -> { - lobbyWorld = player.getLocation().getWorld().getName(); + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, vector -> { + lobbyWorld = sender.getLocation().getWorld().getName(); lobbyPosition = vector; }); } 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 1f454d6..5ecfb8d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -23,7 +23,6 @@ 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.command.CommandSender; import org.bukkit.entity.Player; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -31,22 +30,19 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetSpawnLocation implements ICommand { - public void execute(CommandSender sender, String[] args) { - if (!(sender instanceof Player)) return; - Player player = (Player) sender; - - LocationUtils.setLocation(player, Locations.GAME, vector -> { + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.GAME, vector -> { if (worldBorderEnabled && vector.distance(worldBorderPosition) > 100) { sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); throw new RuntimeException("World border not enabled or not in valid position!"); } - if (!player.getLocation().getWorld().getName().equals(spawnWorld)) { + if (!sender.getLocation().getWorld().getName().equals(spawnWorld)) { Main.getInstance().getGame().getWorldLoader().unloadMap(); - Main.getInstance().getGame().getWorldLoader().setNewMap(player.getLocation().getWorld().getName()); + Main.getInstance().getGame().getWorldLoader().setNewMap(sender.getLocation().getWorld().getName()); } - spawnWorld = player.getLocation().getWorld().getName(); + spawnWorld = sender.getLocation().getWorld().getName(); spawnPosition = vector; }); } 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 e0fc033..50d1776 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,7 +1,6 @@ package net.tylermurphy.hideAndSeek.command.location.util; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.game.Game; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Location; import org.bukkit.World; @@ -14,6 +13,9 @@ 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 { /** 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 index bde5456..59e1517 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java @@ -1,5 +1,8 @@ package net.tylermurphy.hideAndSeek.command.location.util; +/** + * @author bobby29831 + */ public enum Locations { GAME("spawns.game", "GAME_SPAWN"), diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 876cb42..f13942f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -27,7 +27,6 @@ import net.tylermurphy.hideAndSeek.game.util.Status; import net.tylermurphy.hideAndSeek.game.util.Version; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scoreboard.*; @@ -48,10 +47,6 @@ public class Board { return playerList.containsKey(player.getUniqueId().toString()); } - public boolean contains(CommandSender sender) { - return contains((Player) sender); - } - public boolean isHider(Player player) { return Hider.contains(player.getUniqueId().toString()); } @@ -203,7 +198,7 @@ public class Board { private void createLobbyBoard(Player player, boolean recreate) { CustomBoard board = customBoards.get(player.getUniqueId().toString()); - if (recreate) { + if (recreate || board == null) { board = new CustomBoard(player, LOBBY_TITLE); board.updateTeams(); } 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 7fe924f..4e30a50 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InteractHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InteractHandler.java @@ -3,8 +3,13 @@ package net.tylermurphy.hideAndSeek.game.listener; import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.messages.ActionBar; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.Debug; +import net.tylermurphy.hideAndSeek.game.util.PlayerUtil; import net.tylermurphy.hideAndSeek.game.util.Status; +import net.tylermurphy.hideAndSeek.game.util.Version; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -110,7 +115,7 @@ public class InteractHandler implements Listener { private ItemStack getSkull(Player player, List lore){ assert XMaterial.PLAYER_HEAD.parseMaterial() != null; - ItemStack playerhead = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial(), 1); + ItemStack playerhead = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial(), 1, (byte) 3); SkullMeta playerheadmeta = (SkullMeta) playerhead.getItemMeta(); playerheadmeta.setOwner(player.getName()); playerheadmeta.setDisplayName(player.getName()); @@ -123,9 +128,11 @@ public class InteractHandler implements Listener { public void onInventoryClick(InventoryClickEvent event) { if (event.getWhoClicked() instanceof Player) { Player player = (Player) event.getWhoClicked(); + // Block players from moving lobby items if (Main.getInstance().getBoard().contains(player) && Main.getInstance().getGame().getStatus() == Status.STANDBY) { event.setCancelled(true); } + // Spectator Teleport Menu if (Main.getInstance().getBoard().isSpectator(player) && event.getCurrentItem().getType() == XMaterial.PLAYER_HEAD.parseMaterial()) { event.setCancelled(true); player.closeInventory(); @@ -134,6 +141,18 @@ public class InteractHandler implements Listener { if(clicked == null) return; player.teleport(clicked); } + // Debug Menu + boolean debug = false; + if(Version.atLeast("1.14")){ + debug = event.getView().getTitle().equals("Debug Menu") && player.hasPermission("hideandseek.debug"); + } else { + debug = event.getInventory().getName().equals("Debug Menu") && player.hasPermission("hideandseek.debug"); + } + if (debug){ + event.setCancelled(true); + player.closeInventory(); + Debug.handleOption(player, event.getRawSlot()); + } } } 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 aafc529..aba8275 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/MovementHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/MovementHandler.java @@ -22,7 +22,6 @@ public class MovementHandler implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onMove(PlayerMoveEvent event) { if (event.getTo() == null || event.getTo().getWorld() == null) return; - checkJumping(event); checkBounds(event); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java index 6034607..1f0c8a3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java @@ -62,16 +62,20 @@ public class CommandHandler { registerCommand(new Leave()); registerCommand(new Top()); registerCommand(new Wins()); + registerCommand(new Debug()); } public static boolean handleCommand(CommandSender sender, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); - } else if (args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) { + 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(sender, null); + COMMAND_REGISTER.get("about").execute(player, null); } } else { if (!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) { @@ -80,7 +84,7 @@ public class CommandHandler { sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { try { - COMMAND_REGISTER.get(args[0].toLowerCase()).execute(sender,Arrays.copyOfRange(args, 1, args.length)); + COMMAND_REGISTER.get(args[0].toLowerCase()).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/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 193c34e..21b6a76 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -95,6 +95,9 @@ public class WorldLoader { throw new RuntimeException("Failed to create directory: "+destenation.getPath()); } } + if(!destenation.delete()){ + throw new RuntimeException("Unable to delete folder: "+destenation.getPath()); + } if (!temp_destenation.renameTo(destenation)) { throw new RuntimeException("Failed to rename directory: "+temp_destenation.getPath()); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b9ad408..74c4855 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -31,7 +31,8 @@ permissions: hideandseek.leave: true hideandseek.leavebounds: true hideandseek.wins: true - hideand.top: true + hideandseek.top: true + hideandseek.debug: true hideandseek.about: description: Allows you to run the about command default: true @@ -83,3 +84,6 @@ permissions: hideandseek.top: description: Allows players to see the global wins leaderboard default: true + hideandseek.debug: + description: Opens the debug menu + default: op