From 37b3840ca163a1824d3799bcf14bb62173157ece Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 2 Nov 2022 13:38:22 -0400 Subject: [PATCH] 1.7.0 beta 3 --- .../net/tylermurphy/hideAndSeek/Main.java | 12 +++- .../hideAndSeek/command/map/Debug.java | 20 ++---- .../hideAndSeek/command/map/Save.java | 4 ++ .../hideAndSeek/command/map/Status.java | 16 +++-- .../command/map/blockhunt/Enabled.java | 29 ++++++-- .../command/map/blockhunt/blocks/Add.java | 68 +++++++++++++++++++ .../command/map/blockhunt/blocks/List.java | 54 +++++++++++++++ .../command/map/blockhunt/blocks/Remove.java | 68 +++++++++++++++++++ .../command/util/CommandGroup.java | 2 +- .../hideAndSeek/configuration/Config.java | 24 +++---- .../configuration/ConfigManager.java | 2 + .../configuration/Localization.java | 11 ++- .../hideAndSeek/configuration/Map.java | 38 ++++++++--- .../hideAndSeek/configuration/Maps.java | 9 ++- .../tylermurphy/hideAndSeek/game/Game.java | 2 +- .../game/listener/InventoryHandler.java | 6 +- .../resources/lang/localization_en-US.yml | 23 +++++-- 17 files changed, 324 insertions(+), 64 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index b1e2a83..4646e57 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -21,6 +21,7 @@ package net.tylermurphy.hideAndSeek; import net.tylermurphy.hideAndSeek.command.*; import net.tylermurphy.hideAndSeek.command.map.*; +import net.tylermurphy.hideAndSeek.command.map.blockhunt.Enabled; import net.tylermurphy.hideAndSeek.command.map.set.*; import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.database.Database; @@ -87,6 +88,14 @@ public class Main extends JavaPlugin implements Listener { new Start(), new Stop(), new CommandGroup("map", + new CommandGroup("blockhunt", + new CommandGroup("blocks", + new net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks.Add(), + new net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks.Remove(), + new net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks.List() + ), + new Enabled() + ), new CommandGroup("set", new Lobby(), new Spawn(), @@ -99,7 +108,8 @@ public class Main extends JavaPlugin implements Listener { new List(), new Status(), new Save(), - new Debug() + new Debug(), + new GoTo() ), new SetExitLocation(), new Top(), diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java index 2ec0525..4adb806 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -74,20 +74,12 @@ public class Debug extends Command { player.setHealth(0.1); } })); - debugMenu.setItem(6, createOption(functions, 6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - player.teleport(map.getGameSpawn()); - })); - debugMenu.setItem(7, createOption(functions, 7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { - player.teleport(map.getLobby()); - })); - debugMenu.setItem(8, createOption(functions, 8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> player.teleport(exitPosition))); - debugMenu.setItem(9, createOption(functions, 9, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { - PlayerLoader.openBlockHuntPicker(player, map); - })); - debugMenu.setItem(10, createOption(functions, 10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + if(map.isBlockHuntEnabled()) { + debugMenu.setItem(9, createOption(functions, 7, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { + PlayerLoader.openBlockHuntPicker(player, map); + })); + debugMenu.setItem(10, createOption(functions, 8, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + } debugMenuFunctions.put(sender, functions); return debugMenu; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java index b93250f..1f95df3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -56,6 +56,10 @@ public class Save extends Command { sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); return; } + if (map.isBoundsNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_MAP_BOUNDS")); + return; + } sender.sendMessage(messagePrefix + message("MAPSAVE_START")); sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); World world = map.getSpawn().getWorld(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java index 29442c1..d9dd8fb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -41,31 +41,33 @@ public class Status extends Command { sender.sendMessage(errorPrefix + message("INVALID_MAP")); return; } - if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || Map.worldDoesntExist(map.getLobbyName())) { msg = msg + "\n" + message("SETUP_GAME"); count++; } - if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || Map.worldDoesntExist(map.getLobbyName())) { msg = msg + "\n" + message("SETUP_LOBBY"); count++; } - if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !Map.worldExists(map.getSeekerLobbyName())) { + if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || Map.worldDoesntExist(map.getSeekerLobbyName())) { msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); count++; } - if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld)) { + if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || Map.worldDoesntExist(exitWorld)) { msg = msg + "\n" + message("SETUP_EXIT"); count++; } - if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || - map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { + if (map.isBoundsNotSetup()) { msg = msg + "\n" + message("SETUP_BOUNDS"); count++; } - if (mapSaveEnabled && !Map.worldExists(map.getGameSpawnName())) { + if (mapSaveEnabled && Map.worldDoesntExist(map.getGameSpawnName())) { msg = msg + "\n" + message("SETUP_SAVEMAP"); count++; } + if (map.isBlockHuntEnabled() && map.getBlockHunt().isEmpty()) { + msg = msg + "\n" + message("SETUP_BLOCKHUNT"); + } if (count < 1) { sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); } else { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java index 9d47390..b8d2e15 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -1,21 +1,38 @@ package net.tylermurphy.hideAndSeek.command.map.blockhunt; -import net.tylermurphy.hideAndSeek.command.location.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + public class Enabled extends Command { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { - map.setLobby(sender.getLocation()); - }); + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + boolean bool = Boolean.parseBoolean(args[1]); + map.setBlockhunt(bool, map.getBlockHunt()); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BLOCKHUNT_SET_TO") + .addAmount(bool ? ChatColor.GREEN + "true" : ChatColor.RED + "false") + ChatColor.WHITE); } public String getLabel() { @@ -27,7 +44,7 @@ public class Enabled extends Command { } public String getDescription() { - return "Sets hide and seeks lobby location to current position"; + return "Sets blockhunt enabled or disabled in a current map"; } public List autoComplete(String parameter) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java new file mode 100644 index 0000000..021dae0 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java @@ -0,0 +1,68 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Add extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + Material block; + try { block = Material.valueOf(args[1]); } + catch (IllegalArgumentException e) { + sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1])); + return; + } + List blocks = map.getBlockHunt(); + if(blocks.contains(block)) { + sender.sendMessage(errorPrefix + message("BLOCKHUNT_BLOCK_EXISTS").addAmount(args[1])); + } + blocks.add(block); + map.setBlockhunt(map.isBlockHuntEnabled(), blocks); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BLOCKHUNT_BLOCK_ADDED").addAmount(args[1])); + } + + public String getLabel() { + return "add"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Add a blockhunt block to a map!"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } else if(parameter != null && parameter.equals("block")) { + return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList()); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java new file mode 100644 index 0000000..ecb626f --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java @@ -0,0 +1,54 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; + +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class List extends Command { + + public void execute(Player sender, String[] args) { + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + java.util.List blocks = map.getBlockHunt(); + if(blocks.isEmpty()) { + sender.sendMessage(errorPrefix + message("NO_BLOCKS")); + return; + } + StringBuilder response = new StringBuilder(messagePrefix + message("BLOCKHUNT_LIST_BLOCKS")); + for(int i = 0; i < blocks.size(); i++) { + response.append(String.format("\n%s. %s", i, blocks.get(i).toString())); + } + sender.sendMessage(response.toString()); + } + + public String getLabel() { + return "list"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "List all blockhunt blocks in a map"; + } + + public java.util.List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java new file mode 100644 index 0000000..7bbd5d3 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java @@ -0,0 +1,68 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Remove extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + Material block; + try { block = Material.valueOf(args[1]); } + catch (IllegalArgumentException e) { + sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1])); + return; + } + java.util.List blocks = map.getBlockHunt(); + if(!blocks.contains(block)) { + sender.sendMessage(errorPrefix + message("BLOCKHUNT_BLOCK_DOESNT_EXIT").addAmount(args[1])); + } + blocks.remove(block); + map.setBlockhunt(map.isBlockHuntEnabled(), blocks); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BLOCKHUNT_BLOCK_REMOVED").addAmount(args[1])); + } + + public String getLabel() { + return "remove"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Remove a blockhunt block from a map!"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } else if(parameter != null && parameter.equals("block")) { + return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index e7f43eb..32f4081 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -67,7 +67,7 @@ public class CommandGroup { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { player.sendMessage( - String.format("%s%sHide and Seek %s(%s1.7.0 ALPHA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 0000c30..ee7aa18 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -137,16 +137,16 @@ public class Config { announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers"); //Prefix - char SYMBOLE = '\u00A7'; - String SYMBOLE_STRING = String.valueOf(SYMBOLE); + char SYMBOL = '\u00A7'; + String SYMBOL_STRING = String.valueOf(SYMBOL); - messagePrefix = config.getString("prefix.default").replace("&", SYMBOLE_STRING); - errorPrefix = config.getString("prefix.error").replace("&", SYMBOLE_STRING); - tauntPrefix = config.getString("prefix.taunt").replace("&", SYMBOLE_STRING); - worldBorderPrefix = config.getString("prefix.border").replace("&", SYMBOLE_STRING); - abortPrefix = config.getString("prefix.abort").replace("&", SYMBOLE_STRING); - gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOLE_STRING); - warningPrefix = config.getString("prefix.warning").replace("&", SYMBOLE_STRING); + messagePrefix = config.getString("prefix.default").replace("&", SYMBOL_STRING); + errorPrefix = config.getString("prefix.error").replace("&", SYMBOL_STRING); + tauntPrefix = config.getString("prefix.taunt").replace("&", SYMBOL_STRING); + worldBorderPrefix = config.getString("prefix.border").replace("&", SYMBOL_STRING); + abortPrefix = config.getString("prefix.abort").replace("&", SYMBOL_STRING); + gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOL_STRING); + warningPrefix = config.getString("prefix.warning").replace("&", SYMBOL_STRING); // Locations exitPosition = new Location( @@ -211,8 +211,7 @@ public class Config { try { countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay")); } catch (IllegalArgumentException e) { - countdownDisplay = CountdownDisplay.CHAT; - Main.getInstance().getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!"); + throw new RuntimeException("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+", is not a valid configuration option!"); } blockedInteracts = new ArrayList<>(); List tempInteracts = config.getStringList("blockedInteracts"); @@ -255,8 +254,7 @@ public class Config { databaseType = config.getString("databaseType").toUpperCase(); if(!databaseType.equals("SQLITE") && !databaseType.equals("MYSQL")){ - Main.getInstance().getLogger().warning("databaseType: "+databaseType+" is not a valid configuration option!"); - databaseType = "SQLITE"; + throw new RuntimeException("databaseType: "+databaseType+" is not a valid configuration option!"); } delayedRespawn = config.getBoolean("delayedRespawn.enabled"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index b7671c2..eda8470 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -344,6 +344,8 @@ public class ConfigManager { private String convert(Object o) { if(o instanceof String) { return "\"" + o + "\""; + } else if (o instanceof Boolean) { + return (boolean)o ? "true" : "false"; } return o.toString(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 72ab366..6f3f88b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -31,8 +31,15 @@ public class Localization { public static final Map DEFAULT_LOCAL = new HashMap<>(); private static final Map CHANGES = new HashMap() {{ - put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"},{"GAME_SETUP"}}); - put("de-DE", new String[][]{{},{"TAUNTED"}}); + put("en-US", new String[][]{ + {"WORLDBORDER_DECREASING"}, + {"START","TAUNTED"}, + {"GAME_SETUP", "SETUP_GAME", "SETUP_LOBBY", "SETUP_SEEKER_LOBBY", "SETUP_EXIT", "SETUP_SAVEMAP", "SETUP_BOUNDS"} + }); + put("de-DE", new String[][]{ + {}, + {"TAUNTED"} + }); }}; public static void loadLocalization() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java index 5e9b6ae..406f161 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -6,10 +6,10 @@ import java.util.List; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.game.events.Border; -import net.tylermurphy.hideAndSeek.world.VoidGenerator; import net.tylermurphy.hideAndSeek.world.WorldLoader; import org.bukkit.*; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -118,6 +118,7 @@ public class Map { this.zBoundMax = z; } + @NotNull public Location getGameSpawn() { if(mapSaveEnabled) { return new Location( @@ -131,6 +132,7 @@ public class Map { } } + @NotNull public String getGameSpawnName() { if(mapSaveEnabled) return "hs_"+ spawnWorldName; @@ -138,30 +140,37 @@ public class Map { return spawnWorldName; } + @NotNull public Location getSpawn() { return spawnPosition; } + @NotNull public String getSpawnName() { return spawnWorldName; } + @NotNull public Location getLobby() { return lobbyPosition; } + @NotNull public String getLobbyName() { return lobbyWorldName; } + @NotNull public Location getSeekerLobby() { return seekerLobbyPosition; } + @NotNull public String getSeekerLobbyName() { return seekerLobbyWorldName; } + @NotNull public Location getGameSeekerLobby() { if(mapSaveEnabled) { return new Location( @@ -179,6 +188,7 @@ public class Map { return worldBorderSize > 0; } + @NotNull public Vector getWorldBorderPos() { return new Vector( xWorldBorder, @@ -187,6 +197,7 @@ public class Map { ); } + @NotNull public Vector getWorldBorderData() { return new Vector( worldBorderSize, @@ -195,6 +206,7 @@ public class Map { ); } + @NotNull public Border getWorldBorder() { return worldBorder; } @@ -203,10 +215,12 @@ public class Map { return blockhunt; } + @NotNull public List getBlockHunt() { return blockhuntBlocks; } + @NotNull public Vector getBoundsMin() { return new Vector( xBoundMin, @@ -215,6 +229,7 @@ public class Map { ); } + @NotNull public Vector getBoundsMax() { return new Vector( xBoundMax, @@ -223,20 +238,23 @@ public class Map { ); } + @NotNull public String getName() { return name; } + @NotNull public WorldLoader getWorldLoader() { return worldLoader; } public boolean isNotSetup() { - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !Map.worldExists(spawnWorldName)) return true; - if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !Map.worldExists(lobbyWorldName)) return true; - if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld) ) return true; - if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !Map.worldExists(seekerLobbyWorldName)) return true; - if (mapSaveEnabled && !Map.worldExists(getGameSpawnName())) return true; + if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || Map.worldDoesntExist(spawnWorldName)) return true; + if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || Map.worldDoesntExist(lobbyWorldName)) return true; + if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || Map.worldDoesntExist(exitWorld)) return true; + if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || Map.worldDoesntExist(seekerLobbyWorldName)) return true; + if (mapSaveEnabled && Map.worldDoesntExist(getGameSpawnName())) return true; + if (blockhunt && blockhuntBlocks.isEmpty()) return true; if(isWorldBorderEnabled() && new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true; return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; @@ -246,9 +264,13 @@ public class Map { return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0; } - public static boolean worldExists(String worldName) { + public boolean isBoundsNotSetup() { + return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; + } + + public static boolean worldDoesntExist(String worldName) { File destination = new File(Main.getInstance().getWorldContainer()+File.separator+worldName); - return destination.isDirectory(); + return !destination.isDirectory(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java index ff1b396..a27a542 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -11,15 +11,19 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import com.cryptomorin.xseries.XMaterial; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class Maps { private static final HashMap MAPS = new HashMap<>(); + @Nullable public static Map getMap(String name) { return MAPS.get(name); } + @Nullable public static Map getRandomMap() { Optional map; if(MAPS.values().size() > 0) { @@ -45,6 +49,7 @@ public class Maps { return status; } + @NotNull public static Collection getAllMaps() { return MAPS.values(); } @@ -102,7 +107,7 @@ public class Maps { private static Location setSpawn(ConfigurationSection data, String spawn) { String worldName = data.getString("spawns."+spawn+".world"); if(worldName == null) return new Location(null, 0, 0, 0); - if(!Map.worldExists(worldName)) return new Location(null, 0, 0, 0); + if(Map.worldDoesntExist(worldName)) return new Location(null, 0, 0, 0); World world = Bukkit.getWorld(worldName); double x = data.getDouble("spawns."+spawn+".x"); double y = data.getDouble("spawns."+spawn+".y"); @@ -141,7 +146,7 @@ public class Maps { private static void saveSpawn(ConfigurationSection data, Location spawn, String name, Map map) { String worldName = getWorldName(name, map); - if(worldName == null || !Map.worldExists(worldName)) { + if(worldName == null || Map.worldDoesntExist(worldName)) { data.set("spawns." + name + ".world", "world"); } else { data.set("spawns." + name + ".world", worldName); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 4dd5fa9..0e54184 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -330,7 +330,7 @@ public class Game { } public boolean checkCurrentMap() { - if(currentMap != null) return false; + if(currentMap != null && !currentMap.isNotSetup()) return false; this.currentMap = Maps.getRandomMap(); return this.currentMap == null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java index af915e2..0f306b1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java @@ -82,12 +82,13 @@ public class InventoryHandler implements Listener { String mapName; if(Main.getInstance().supports(14)){ test = event.getView().getTitle().startsWith("Select a Block: "); + if(!test) return; mapName = event.getView().getTitle().substring("Select a Block: ".length()); } else { test = event.getInventory().getName().startsWith("Select a Block: "); + if(!test) return; mapName = event.getInventory().getName().substring("Select a Block: ".length()); } - if(!test) return; event.setCancelled(true); Map map = Maps.getMap(mapName); if(map == null) return; @@ -105,12 +106,13 @@ public class InventoryHandler implements Listener { String mapName; if(Main.getInstance().supports(14)){ test = event.getView().getTitle().startsWith("Select a Block: "); + if(!test) return; mapName = event.getView().getTitle().substring("Select a Block: ".length()); } else { test = event.getInventory().getName().startsWith("Select a Block: "); + if(!test) return; mapName = event.getInventory().getName().substring("Select a Block: ".length()); } - if(!test) return; Map map = Maps.getMap(mapName); if(map == null) return; Material mat = map.getBlockHunt().get(0); diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 53f86be..a78a421 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -48,13 +48,15 @@ Localization: TAUNT: "A random hider will be taunted in the next 30s." TAUNT_ACTIVATE: "Taunt has been activated." ERROR_GAME_SPAWN: "Please set game spawn location first" + ERROR_MAP_BOUNDS: "Please set map bounds before saving" SETUP: "&f&lThe following is needed for setup..." - SETUP_GAME: "&c&l- &fGame spawn isn't set, /hs setspawn" - SETUP_LOBBY: "&c&l- &fLobby spawn isn't set, /hs setlobby" - SETUP_SEEKER_LOBBY: "&c&l- &fSeeker Lobby spawn isn't set, /hs setseekerlobby" + SETUP_GAME: "&c&l- &fGame spawn isn't set, /hs map set spawn " + SETUP_LOBBY: "&c&l- &fLobby spawn isn't set, /hs map set lobby " + SETUP_SEEKER_LOBBY: "&c&l- &fSeeker Lobby spawn isn't set, /hs map set seekerlobby " SETUP_EXIT: "&c&l- &fQuit/exit teleport location isn't set, /hs setexit" - SETUP_SAVEMAP: "&c&l- &fHide and seek map isn't saved, /hs savemap (after /hs setspawn)" - SETUP_BOUNDS: "&c&l- &fPlease set game bounds in 2 opposite corners of the game map, /hs setbounds" + SETUP_SAVEMAP: "&c&l- &fHide and seek map isn't saved, /hs map save " + SETUP_BOUNDS: "&c&l- &fPlease set game bounds in 2 opposite corners of the game map, /hs map set bounds " + SETUP_BLOCKHUNT: "&c&l - &fIf blockhunt is enabled, there needs to be at least 1 block set, /hs map blockhunt block add block " SETUP_COMPLETE: "Everything is setup and ready to go!" GAME_SPAWN: "Set game spawn position to current location" LOBBY_SPAWN: "Set lobby position to current location" @@ -88,8 +90,8 @@ Localization: MAP_CREATED: "Created new map: {AMOUNT}" MAP_FAIL_DELETE: "Failed to delete map: {AMOUNT}" MAP_DELETED: "Deleted map: {AMOUNT}" - NO_MAPS: "There are no maps in the plugin rn (/hs addmap)" - MAP_NOT_SETUP: "Map {AMOUNT} is not setup (/hs setup )" + NO_MAPS: "There are no maps in the plugin rn (/hs map add )" + MAP_NOT_SETUP: "Map {AMOUNT} is not setup (/hs map status )" LIST_MAPS: "The current maps are:" ARGUMENT_COUNT: "This command requires more arguments to run." GAME_SPAWN_NEEDED: "Game spawn must be set before seeker spawn." @@ -97,6 +99,13 @@ Localization: SEEKER_LOBBY_INVALID: "Seeker lobby must be in the same world as game spawn." CONFIG_ERROR: "Error reloading config. Check server logs." BLOCKHUNT_DISABLED: "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8" + BLOCKHUNT_SET_TO: "Blockhunt set to {AMOUNT}." + BLOCKHUNT_BLOCK_EXISTS: "{AMOUNT} is already set in the blockhunt config." + BLOCKHUNT_BLOCK_DOESNT_EXIT: "{AMOUNT} is already not set in the blochunt config." + BLOCKHUNT_BLOCK_ADDED: "Added {AMOUNT} to blockhunt config." + BLOCKHUNT_BLOCK_REMOVED: "Removed {AMOUNT} from blockhunt config." + BLOCKHUNT_LIST_BLOCKS: "The following blockhunt blocks are:" + NO_BLOCKS: "There are no blockhunt blocks in this map." # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 4