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 --- .../hideAndSeek/command/map/set/SeekerLobby.java | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java') 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; + } + +} -- 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 (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.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 (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.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 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 (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.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