From bb254145ed0bb56d0482f6ba34e05cb728a7c8cc Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Wed, 2 Nov 2022 07:18:00 -0400 Subject: [PATCH] 1.7.0 beta 2 --- .../net/tylermurphy/hideAndSeek/Main.java | 74 +++++----- .../hideAndSeek/command/About.java | 54 ------- .../hideAndSeek/command/Reload.java | 21 ++- .../command/{map/SetMap.java => Send.java} | 6 +- .../{location => }/SetExitLocation.java | 6 +- .../hideAndSeek/command/Start.java | 4 +- .../tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../tylermurphy/hideAndSeek/command/Top.java | 2 +- .../location/{util => }/LocationUtils.java | 2 +- .../location/{util => }/Locations.java | 2 +- .../command/map/{AddMap.java => Add.java} | 2 +- .../hideAndSeek/command/{ => map}/Debug.java | 2 +- .../hideAndSeek/command/map/GoTo.java | 63 ++++++++ .../command/map/{ListMaps.java => List.java} | 5 +- .../map/{RemoveMap.java => Remove.java} | 2 +- .../command/map/{SaveMap.java => Save.java} | 5 +- .../command/map/{Setup.java => Status.java} | 6 +- .../command/map/blockhunt/Enabled.java | 43 ++++++ .../map/{SetBorder.java => set/Border.java} | 6 +- .../map/{SetBounds.java => set/Bounds.java} | 4 +- .../set/Lobby.java} | 8 +- .../set/SeekerLobby.java} | 8 +- .../set/Spawn.java} | 8 +- .../command/util/CommandGroup.java | 13 +- .../hideAndSeek/configuration/Config.java | 39 ----- .../configuration/ConfigManager.java | 139 ++++++++++++------ .../configuration/Leaderboard.java | 51 +++++++ .../configuration/Localization.java | 2 +- .../tylermurphy/hideAndSeek/game/Board.java | 13 +- .../hideAndSeek/game/Disguiser.java | 3 +- .../game/listener/ChatHandler.java | 2 +- .../game/listener/DisguiseHandler.java | 3 +- .../game/listener/InventoryHandler.java | 4 +- .../hideAndSeek/world/WorldLoader.java | 4 +- src/main/resources/config.yml | 107 +++++++------- .../resources/lang/localization_en-US.yml | 19 ++- src/main/resources/leaderboard.yml | 7 +- 37 files changed, 440 insertions(+), 301 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/About.java rename src/main/java/net/tylermurphy/hideAndSeek/command/{map/SetMap.java => Send.java} (94%) rename src/main/java/net/tylermurphy/hideAndSeek/command/{location => }/SetExitLocation.java (89%) rename src/main/java/net/tylermurphy/hideAndSeek/command/location/{util => }/LocationUtils.java (96%) rename src/main/java/net/tylermurphy/hideAndSeek/command/location/{util => }/Locations.java (87%) rename src/main/java/net/tylermurphy/hideAndSeek/command/map/{AddMap.java => Add.java} (97%) rename src/main/java/net/tylermurphy/hideAndSeek/command/{ => map}/Debug.java (99%) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java rename src/main/java/net/tylermurphy/hideAndSeek/command/map/{ListMaps.java => List.java} (91%) rename src/main/java/net/tylermurphy/hideAndSeek/command/map/{RemoveMap.java => Remove.java} (97%) rename src/main/java/net/tylermurphy/hideAndSeek/command/map/{SaveMap.java => Save.java} (96%) rename src/main/java/net/tylermurphy/hideAndSeek/command/map/{Setup.java => Status.java} (96%) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java rename src/main/java/net/tylermurphy/hideAndSeek/command/map/{SetBorder.java => set/Border.java} (96%) rename src/main/java/net/tylermurphy/hideAndSeek/command/map/{SetBounds.java => set/Bounds.java} (97%) rename src/main/java/net/tylermurphy/hideAndSeek/command/{location/SetLobbyLocation.java => map/set/Lobby.java} (86%) rename src/main/java/net/tylermurphy/hideAndSeek/command/{location/SetSeekerLobbyLocation.java => map/set/SeekerLobby.java} (84%) rename src/main/java/net/tylermurphy/hideAndSeek/command/{location/SetSpawnLocation.java => map/set/Spawn.java} (91%) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index b22af5b..b1e2a83 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -20,15 +20,11 @@ package net.tylermurphy.hideAndSeek; import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.command.location.*; import net.tylermurphy.hideAndSeek.command.map.*; -import net.tylermurphy.hideAndSeek.configuration.Config; -import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.configuration.Localization; -import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.command.map.set.*; +import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.game.*; -import net.tylermurphy.hideAndSeek.game.util.Status; import net.tylermurphy.hideAndSeek.command.util.CommandGroup; import net.tylermurphy.hideAndSeek.game.listener.*; import net.tylermurphy.hideAndSeek.util.PAPIExpansion; @@ -41,7 +37,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import java.io.File; -import java.util.List; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -65,10 +60,17 @@ public class Main extends JavaPlugin implements Listener { Main.instance = this; this.updateVersion(); - Config.loadConfig(); - Maps.loadMaps(); - Localization.loadLocalization(); - Items.loadItems(); + try { + Config.loadConfig(); + Maps.loadMaps(); + Localization.loadLocalization(); + Items.loadItems(); + Leaderboard.loadLeaderboard(); + } catch (Exception e) { + getLogger().severe(e.getMessage()); + Bukkit.getPluginManager().disablePlugin(this); + return; + } this.board = new Board(); this.database = new Database(); @@ -77,28 +79,27 @@ public class Main extends JavaPlugin implements Listener { this.registerListeners(); this.commandGroup = new CommandGroup("hs", - new About(), - new Debug(), new Help(), new Reload(), new Join(), new Leave(), + new Send(), new Start(), new Stop(), new CommandGroup("map", new CommandGroup("set", - new SetLobbyLocation(), - new SetSpawnLocation(), - new SetSeekerLobbyLocation(), - new SetBorder(), - new SetBounds() + new Lobby(), + new Spawn(), + new SeekerLobby(), + new Border(), + new Bounds() ), - new AddMap(), - new RemoveMap(), - new ListMaps(), - new SetMap(), - new Setup(), - new SaveMap() + new Add(), + new Remove(), + new List(), + new Status(), + new Save(), + new Debug() ), new SetExitLocation(), new Top(), @@ -120,20 +121,25 @@ public class Main extends JavaPlugin implements Listener { version = 0; - board.getPlayers().forEach(player -> { - board.removeBoard(player); - PlayerLoader.unloadPlayer(player); - if(!Objects.equals(exitWorld, "")) - player.teleport(exitPosition); - }); + if(board != null) { + board.getPlayers().forEach(player -> { + board.removeBoard(player); + PlayerLoader.unloadPlayer(player); + if (!Objects.equals(exitWorld, "")) + player.teleport(exitPosition); + }); + board.cleanup(); + } + + if(disguiser != null) { + disguiser.cleanUp(); + } Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this); - board.cleanup(); - disguiser.cleanUp(); } private void onTick() { - if(game.getStatus() == Status.ENDED) game = new Game(game.getCurrentMap(), board); + if(game.getStatus() == net.tylermurphy.hideAndSeek.game.util.Status.ENDED) game = new Game(game.getCurrentMap(), board); game.onTick(); disguiser.check(); } @@ -168,7 +174,7 @@ public class Main extends JavaPlugin implements Listener { return commandGroup.handleCommand((Player)sender, "", args); } - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + public java.util.List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { return commandGroup.handleTabComplete(sender, args); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java deleted file mode 100644 index 119888b..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.List; - -public class About extends Command { - - public void execute(Player sender, String[] args) { - sender.sendMessage( - String.format("%s%sHide and Seek %s(%s1.7.0 ALPHA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + - String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + - String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) - ); - } - - public String getLabel() { - return "about"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Get information about the plugin"; - } - - public List autoComplete(String parameter) { - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 51bc509..9f8392f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -21,10 +21,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Config; -import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.configuration.Localization; -import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; @@ -42,10 +39,18 @@ public class Reload extends Command { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - Config.loadConfig(); - Maps.loadMaps(); - Localization.loadLocalization(); - Items.loadItems(); + + try { + Config.loadConfig(); + Maps.loadMaps(); + Localization.loadLocalization(); + Items.loadItems(); + Leaderboard.loadLeaderboard(); + } catch (Exception e) { + sender.sendMessage(errorPrefix + message("CONFIG_ERROR")); + return; + } + sender.sendMessage(messagePrefix + message("CONFIG_RELOAD")); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java similarity index 94% rename from src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/Send.java index 2df5824..9978c3c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.command.map; +package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; @@ -13,7 +13,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetMap extends Command { +public class Send extends Command { public void execute(Player sender, String[] args) { @@ -46,7 +46,7 @@ public class SetMap extends Command { } public String getLabel() { - return "goto"; + return "send"; } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java similarity index 89% rename from src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index 01e1512..874909b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -17,11 +17,11 @@ * */ -package net.tylermurphy.hideAndSeek.command.location; +package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; import org.bukkit.entity.Player; import java.util.List; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 54ad4af..674edd6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -57,7 +57,7 @@ public class Start extends Command { if (args.length < 1) { Optional rand = Main.getInstance().getBoard().getPlayers().stream().skip(new Random().nextInt(Main.getInstance().getBoard().size())).findFirst(); if (!rand.isPresent()) { - Main.getInstance().getLogger().warning("Failed to select random seeker."); + sender.sendMessage(errorPrefix + message("START_FAILED_SEEKER")); return; } seekerName = rand.get().getName(); @@ -82,7 +82,7 @@ public class Start extends Command { } public String getUsage() { - return ""; + return "<*player>"; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 1582be9..7c8cabf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -34,7 +34,7 @@ public class Stop extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { - sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); + sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } if (Main.getInstance().getGame().getStatus() == Status.STARTING || Main.getInstance().getGame().getStatus() == Status.PLAYING) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 8116eaf..0a5358d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -76,7 +76,7 @@ public class Top extends Command { } public String getUsage() { - return ""; + return "<*page>"; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java similarity index 96% rename from src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java index 69d7c26..5e4afb5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.command.location.util; +package net.tylermurphy.hideAndSeek.command.location; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Map; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java similarity index 87% rename from src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java index 35f74ea..dd73dac 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.command.location.util; +package net.tylermurphy.hideAndSeek.command.location; /** * @author bobby29831 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java similarity index 97% rename from src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java index 55b4267..03c2a95 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java @@ -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 AddMap extends Command { +public class Add extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java similarity index 99% rename from src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java index 2eb0eb9..2ec0525 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.command; +package net.tylermurphy.hideAndSeek.command.map; import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java new file mode 100644 index 0000000..8e74922 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java @@ -0,0 +1,63 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class GoTo extends Command { + + public void execute(Player sender, String[] args) { + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isNotSetup()) { + sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP").addAmount(map.getName())); + return; + } + switch (args[1].toLowerCase()) { + case "spawn": + sender.teleport(map.getSpawn()); break; + case "lobby": + sender.teleport(map.getLobby()); break; + case "seekerlobby": + sender.teleport(map.getSeekerLobby()); break; + case "exit": + sender.teleport(exitPosition); break; + default: + sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1].toLowerCase())); + } + } + + public String getLabel() { + return "goto"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Get the commands for the plugin"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } else if(parameter != null && parameter.equals("spawn")) { + return Arrays.asList("spawn","lobby","seekerlobby","exit"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java similarity index 91% rename from src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java index 79490a7..635c011 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java @@ -7,13 +7,12 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.util.Collection; -import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class ListMaps extends Command { +public class List extends Command { public void execute(Player sender, String[] args) { Collection maps = Maps.getAllMaps(); @@ -40,7 +39,7 @@ public class ListMaps extends Command { return "List all maps in the plugin"; } - public List autoComplete(String parameter) { + public java.util.List autoComplete(String parameter) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java similarity index 97% rename from src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java index 216cca9..45dec99 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java @@ -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 RemoveMap extends Command { +public class Remove extends Command { 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/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java similarity index 96% rename from src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java index f3eb4d7..b93250f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -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 SaveMap extends Command { +public class Save extends Command { public static boolean runningBackup = false; @@ -60,7 +60,8 @@ public class SaveMap extends Command { sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); World world = map.getSpawn().getWorld(); if (world == null) { - throw new RuntimeException("Unable to get spawn world"); + sender.sendMessage(warningPrefix + message("MAPSAVE_FAIL_WORLD")); + return; } world.save(); BukkitRunnable runnable = new BukkitRunnable() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java similarity index 96% rename from src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java index 46b41f7..29442c1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -19,20 +19,18 @@ package net.tylermurphy.hideAndSeek.command.map; -import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; -import java.io.File; import java.util.List; import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Setup extends Command { +public class Status extends Command { public void execute(Player sender, String[] args) { @@ -76,7 +74,7 @@ public class Setup extends Command { } public String getLabel() { - return "setup"; + return "status"; } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java new file mode 100644 index 0000000..9d47390 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -0,0 +1,43 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt; + +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class Enabled extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "enabled"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Sets hide and seeks lobby location to current position"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + if(parameter != null && parameter.equals("bool")) { + return Arrays.asList("true", "false"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java similarity index 96% rename from src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java index 8362e02..92339b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java @@ -17,7 +17,7 @@ * */ -package net.tylermurphy.hideAndSeek.command.map; +package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; @@ -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 SetBorder extends Command { +public class Border extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { @@ -86,7 +86,7 @@ public class SetBorder extends Command { change ); Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); + sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay).addAmount(change)); map.getWorldBorder().resetWorldBorder(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java similarity index 97% rename from src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java index 92bf5a4..9896389 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java @@ -17,7 +17,7 @@ * */ -package net.tylermurphy.hideAndSeek.command.map; +package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; @@ -32,7 +32,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetBounds extends Command { +public class Bounds extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java similarity index 86% rename from src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java index da41d91..c691787 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java @@ -17,18 +17,18 @@ * */ -package net.tylermurphy.hideAndSeek.command.location; +package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; import java.util.List; import java.util.stream.Collectors; -public class SetLobbyLocation extends Command { +public class Lobby extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java similarity index 84% rename from src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java index 8a5ebd1..2521f19 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java @@ -1,8 +1,8 @@ -package net.tylermurphy.hideAndSeek.command.location; +package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; @@ -11,7 +11,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetSeekerLobbyLocation extends Command { +public class SeekerLobby extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java similarity index 91% rename from src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java rename to src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java index 82f71d1..3e8f77e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java @@ -17,11 +17,11 @@ * */ -package net.tylermurphy.hideAndSeek.command.location; +package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -33,7 +33,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetSpawnLocation extends Command { +public class Spawn extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index 9079ccc..e7f43eb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -20,7 +20,8 @@ package net.tylermurphy.hideAndSeek.command.util; import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.command.map.SaveMap; +import net.tylermurphy.hideAndSeek.command.map.Save; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -38,7 +39,7 @@ public class CommandGroup { public CommandGroup(String label, Object... data) { this.label = label; - this.commandRegister = new HashMap<>(); + this.commandRegister = new LinkedHashMap<>(); for(Object o : data) registerCommand(o); } @@ -65,11 +66,15 @@ public class CommandGroup { if (permissionsRequired && !player.hasPermission("hs.about")) { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { - new About().execute(player, null); + player.sendMessage( + String.format("%s%sHide and Seek %s(%s1.7.0 ALPHA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) + ); } } else { String invoke = args[0].toLowerCase(); - if (!invoke.equals("about") && !invoke.equals("help") && SaveMap.runningBackup) { + if (!invoke.equals("about") && !invoke.equals("help") && Save.runningBackup) { player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); } else if (permissionsRequired && !player.hasPermission(permission+"."+invoke)) { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 3a43e15..0000c30 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -101,7 +101,6 @@ public class Config { lobbyItemStartPosition, flightToggleItemPosition, teleportItemPosition, - solidifyTime, delayedRespawnDelay; public static float @@ -113,24 +112,6 @@ public class Config { blockedCommands, blockedInteracts; - public static String - LOBBY_TITLE, - GAME_TITLE, - COUNTDOWN_WAITING, - COUNTDOWN_COUNTING, - COUNTDOWN_ADMINSTART, - TAUNT_COUNTING, - TAUNT_ACTIVE, - TAUNT_EXPIRED, - GLOW_ACTIVE, - GLOW_INACTIVE, - BORDER_COUNTING, - BORDER_DECREASING; - - public static List - LOBBY_CONTENTS, - GAME_CONTENTS; - public static ItemStack lobbyLeaveItem, lobbyStartItem, @@ -152,7 +133,6 @@ public class Config { config = ConfigManager.create("config.yml"); config.saveConfig(); - ConfigManager leaderboard = ConfigManager.create("leaderboard.yml"); announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers"); @@ -247,25 +227,6 @@ public class Config { } bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy"); leaveServer = config.getString("leaveServer"); - solidifyTime = Math.max(20,config.getInt("blockhunt.solidifyTime")); - - //Leaderboard - LOBBY_TITLE = leaderboard.getString("lobby.title"); - GAME_TITLE = leaderboard.getString("game.title"); - LOBBY_CONTENTS = leaderboard.getStringList("lobby.content"); - Collections.reverse(LOBBY_CONTENTS); - GAME_CONTENTS = leaderboard.getStringList("game.content"); - Collections.reverse(GAME_CONTENTS); - COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting"); - COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting"); - COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart"); - TAUNT_COUNTING = leaderboard.getString("taunt.counting"); - TAUNT_ACTIVE = leaderboard.getString("taunt.active"); - TAUNT_EXPIRED = leaderboard.getString("taunt.expired"); - GLOW_ACTIVE = leaderboard.getString("glow.active"); - GLOW_INACTIVE = leaderboard.getString("glow.inactive"); - BORDER_COUNTING = leaderboard.getString("border.counting"); - BORDER_DECREASING = leaderboard.getString("border.decreasing"); //Lobby Items if (config.getBoolean("lobbyItems.leave.enabled")) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index e09001e..b7671c2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -93,6 +93,7 @@ public class ConfigManager { try { this.config.load(reader); } catch(InvalidConfigurationException e) { + Main.getInstance().getLogger().severe(e.getMessage()); throw new RuntimeException("Invalid configuration in config file: "+file.getPath()); } catch(IOException e) { throw new RuntimeException("Could not access file: "+file.getPath()); @@ -107,9 +108,10 @@ public class ConfigManager { try { this.defaultConfig.load(default_reader); } catch(InvalidConfigurationException e) { - throw new RuntimeException("Invalid configuration in config file: "+file.getPath()); + Main.getInstance().getLogger().severe(e.getMessage()); + throw new RuntimeException("Invalid configuration in internal config file: "+defaultFilename); } catch(IOException e) { - throw new RuntimeException("Could not access file: "+file.getPath()); + throw new RuntimeException("Could not access internal file: "+defaultFilename); } try{ @@ -240,69 +242,110 @@ public class ConfigManager { public void saveConfig() { try { + // open config file InputStream is = Main.getInstance().getResource(defaultFilename); + // if failed error if (is == null) { throw new RuntimeException("Could not create input stream for "+defaultFilename); } + // manually read in each character to preserve string data StringBuilder textBuilder = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); Reader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); int c; - while((c = reader.read()) != -1) { + while((c = reader.read()) != -1) textBuilder.append((char) c); - } - String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8); - Map temp = config.getValues(true); - for(Map.Entry entry: temp.entrySet()) { - if (entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List) { - String[] parts = entry.getKey().split("\\."); - int index = 0; - int i = 0; - for(String part : parts) { - if (i == 0) { - index = yamlString.indexOf(part+":", index); - } else { - index = yamlString.indexOf(" " + part+":", index); - index++; - } - i++; - if (index == -1) break; - } - if (index < 10) continue; - int start = yamlString.indexOf(' ', index); - int end = yamlString.indexOf('\n', index); - if (end == -1) end = yamlString.length(); - StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); - if (entry.getValue() instanceof List) { - if (((List) entry.getValue()).isEmpty()) { - replace.append("[]"); - } else { - replace.append("["); - for (Object o : (List) entry.getValue()) { - replace.append(o.toString()).append(", "); - } - replace = new StringBuilder(replace.substring(0, replace.length() - 2)); - replace.append("]"); - } + // store yaml file into a string + String yaml = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8); + // get config values + Map data = config.getValues(true); + // write each stored config value into the yaml string + for(Map.Entry entry: data.entrySet()) { + // if type isn't supported, skip + if(!isSupported(entry.getValue())) continue; + // get index of key in yaml string + int index = getIndex(yaml, entry.getKey()); + // if index not found, skip + if (index < 10) continue; + // get start and end of the value + int start = yaml.indexOf(' ', index) + 1; + int end = yaml.indexOf('\n', index); + // if end not found, set it to the end of the file + if (end == -1) end = yaml.length(); + // create new replace sting + StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); + // get value + Object value = entry.getValue(); + // if the value is a list, + if (value instanceof List) { + end = yaml.indexOf(']', start) + 1; + List list = (List) entry.getValue(); + if (list.isEmpty()) { + // if list is empty, put an empty list + replace.append("[]"); } else { - replace.append(entry.getValue()); + // if list has values, populate values into the string + // get gap before key + int gap = whitespaceBefore(yaml, index); + String space = new String(new char[gap]).replace('\0', ' '); + replace.append("[\n"); + for (int i = 0; i < list.size(); i++) { + replace.append(space).append(" ").append(convert(list.get(i))); + if(i != list.size() -1) replace.append(",\n"); + } + replace.append('\n').append(space).append("]"); } - if (entry.getValue() instanceof String) { - replace.append("\""); - replace.reverse(); - replace.append("\""); - replace.reverse(); - } - StringBuilder builder = new StringBuilder(yamlString); - builder.replace(start+1, end, replace.toString()); - yamlString = builder.toString(); + // otherwise just put the value directly + } else { + replace.append(convert(value)); } + // replace the new value in the yaml string + StringBuilder builder = new StringBuilder(yaml); + builder.replace(start, end, replace.toString()); + yaml = builder.toString(); } + + // write yaml string to file Writer fileWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8)); - fileWriter.write(yamlString); + fileWriter.write(yaml); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } } + private int getIndex(String yaml, String key) { + String[] parts = key.split("\\."); + int index = 0; + for(String part : parts) { + if (index == 0) { + index = yaml.indexOf(part + ":", index); + } else { + index = yaml.indexOf(" " + part + ":", index) + 1; + } + if (index == -1) break; + } + return index; + } + + public boolean isSupported(Object o) { + return o instanceof Integer || + o instanceof Double || + o instanceof String || + o instanceof Boolean || + o instanceof List; + } + + public int whitespaceBefore(String yaml, int index) { + int count = 0; + for(int i = index - 1; yaml.charAt(i) == ' '; i--) count++; + return count; + } + + private String convert(Object o) { + if(o instanceof String) { + return "\"" + o + "\""; + } + return o.toString(); + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java new file mode 100644 index 0000000..63dc850 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java @@ -0,0 +1,51 @@ +package net.tylermurphy.hideAndSeek.configuration; + +import java.util.Collections; +import java.util.List; + +public class Leaderboard { + + public static String + LOBBY_TITLE, + GAME_TITLE, + COUNTDOWN_WAITING, + COUNTDOWN_COUNTING, + COUNTDOWN_ADMINSTART, + TAUNT_COUNTING, + TAUNT_ACTIVE, + TAUNT_EXPIRED, + GLOW_ACTIVE, + GLOW_INACTIVE, + BORDER_COUNTING, + BORDER_DECREASING; + + public static List + LOBBY_CONTENTS, + GAME_CONTENTS; + + public static void loadLeaderboard() { + + ConfigManager leaderboard = ConfigManager.create("leaderboard.yml"); + + LOBBY_TITLE = leaderboard.getString("lobby.title"); + GAME_TITLE = leaderboard.getString("game.title"); + LOBBY_CONTENTS = leaderboard.getStringList("lobby.content"); + Collections.reverse(LOBBY_CONTENTS); + GAME_CONTENTS = leaderboard.getStringList("game.content"); + Collections.reverse(GAME_CONTENTS); + COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting"); + COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting"); + COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart"); + TAUNT_COUNTING = leaderboard.getString("taunt.counting"); + TAUNT_ACTIVE = leaderboard.getString("taunt.active"); + TAUNT_EXPIRED = leaderboard.getString("taunt.expired"); + GLOW_ACTIVE = leaderboard.getString("glow.active"); + GLOW_INACTIVE = leaderboard.getString("glow.inactive"); + BORDER_COUNTING = leaderboard.getString("border.counting"); + BORDER_DECREASING = leaderboard.getString("border.decreasing"); + + leaderboard.saveConfig(); + + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 9418414..72ab366 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -31,7 +31,7 @@ public class Localization { public static final Map DEFAULT_LOCAL = new HashMap<>(); private static final Map CHANGES = new HashMap() {{ - put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"}}); + put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"},{"GAME_SETUP"}}); put("de-DE", new String[][]{{},{"TAUNTED"}}); }}; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 18cad40..83fc2a6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -33,6 +33,7 @@ import java.util.*; import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Leaderboard.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Board { @@ -218,7 +219,9 @@ public class Board { } else if (line.contains("{SEEKER%}")) { board.setLine(String.valueOf(i), line.replace("{SEEKER%}", getSeekerPercent()+"")); } else if (line.contains("{HIDER%}")) { - board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent()+"")); + board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent() + "")); + } else if (line.contains("{MAP}")) { + board.setLine(String.valueOf(i), line.replace("{MAP}", getMapName() + "")); } else { board.setLine(String.valueOf(i), line); } @@ -228,6 +231,12 @@ public class Board { customBoards.put(player.getUniqueId().toString(), board); } + public String getMapName() { + net.tylermurphy.hideAndSeek.configuration.Map map = Main.getInstance().getGame().getCurrentMap(); + if(map == null) return "Invalid"; + else return map.getName(); + } + public void createGameBoard(Player player) { createGameBoard(player, true); } @@ -288,6 +297,8 @@ public class Board { board.setLine(String.valueOf(i), line.replace("{#SEEKER}", getSeekers().size()+"")); } else if (line.contains("{#HIDER}")) { board.setLine(String.valueOf(i), line.replace("{#HIDER}", getHiders().size()+"")); + } else if (line.contains("{MAP}")) { + board.setLine(String.valueOf(i), line.replace("{MAP}", getMapName() + "")); } else { board.setLine(String.valueOf(i), line); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java index dabb735..5fce7d3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java @@ -1,6 +1,7 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.game.util.Disguise; @@ -49,7 +50,7 @@ public class Disguiser { public void disguise(Player player, Material material, Map map){ if(!map.isBlockHuntEnabled()){ - player.sendMessage(errorPrefix + "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8"); + player.sendMessage(errorPrefix + message("BLOCKHUNT_DISABLED")); return; } if(disguises.containsKey(player)){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java index 27a6235..27347c2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java @@ -11,7 +11,7 @@ public class ChatHandler implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onChat(AsyncPlayerChatEvent event) { - if (Main.getInstance().getBoard().isSeeker(event.getPlayer())) { + if (Main.getInstance().getBoard().isSpectator(event.getPlayer())) { event.setCancelled(true); Main.getInstance().getBoard().getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage())); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java index cb8ad04..c80e83f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java @@ -1,7 +1,6 @@ package net.tylermurphy.hideAndSeek.game.listener; import static com.comphenix.protocol.PacketType.Play.Client.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.solidifyTime; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; @@ -42,7 +41,7 @@ public class DisguiseHandler implements Listener { if(lastLocation.getWorld() != currentLocation.getWorld()) return; double distance = lastLocation.distance(currentLocation); disguise.setSolidify(distance < .1); - }, solidifyTime); + }, 20 * 3); if(event.getFrom().distance(event.getTo()) > .1) disguise.setSolidify(false); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java index 2439b2b..af915e2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java @@ -19,11 +19,9 @@ package net.tylermurphy.hideAndSeek.game.listener; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.Debug; +import net.tylermurphy.hideAndSeek.command.map.Debug; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 322519a..d4deafe 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -75,7 +75,7 @@ public class WorldLoader { public String save() { World world = Bukkit.getServer().getWorld(map.getSpawnName()); if(world == null){ - return errorPrefix + "Invalid world to save: " + map.getSpawnName(); + return errorPrefix + message("MAPSAVE_INVALID").addAmount(map.getSpawnName()); } File current = new File(Main.getInstance().getWorldContainer()+File.separator+ map.getSpawnName()); if (current.exists()) { @@ -94,7 +94,7 @@ public class WorldLoader { } if (!temp_destination.renameTo(destination)) { - return errorPrefix + "Failed to rename directory: " + temp_destination.getPath(); + return errorPrefix + message("MAPSAVE_FAIL_DIR").addAmount(temp_destination.getPath()); } } catch(IOException e) { e.printStackTrace(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6463898..389352a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -15,23 +15,23 @@ gameLength: 1200 announceMessagesToNonPlayers: true # When the game is starting, the plugin will state there is x seconds left to hide. -# You change where countdown messages to be displayed: in the chat, action bar, or a title. +# You change where countdown messages are to be displayed: in the chat, action bar, or a title. # Below you can set CHAT, ACTIONBAR, or TITLE. Any invalid option will revert to CHAT. # -# CHAT - Messages will be displayed in the chat +# CHAT - Staring messages will be displayed in the chat # -# ACTIONBAR - Messages will be displayed in the action bar (area above the hotbar) +# ACTIONBAR - Staring messages will be displayed in the action bar (area above the hotbar) # -# TITLE - Messages will be displayed as a title +# TITLE - Staring messages will be displayed as a title # # default: CHAT -hideCountdownDisplay: CHAT +hideCountdownDisplay: "CHAT" # Allow Hiders to see their own teams nametags as well as seekers. Seekers can never see nametags regardless. # default: false nametagsVisible: false -# Require bukkit permissions though a plugin to run commands, recommended on large servers +# Require bukkit permissions though a permissions plugin to run commands, or require op, recommended on most servers # default: true permissionsRequired: true @@ -80,11 +80,11 @@ leaveOnEnd: false # PROXY - Send the player to a specified server in a bungee-cord / velocity setup. # # default: EXIT -leaveType: EXIT +leaveType: "EXIT" # Ignore this setting if you aren't using the PROXY leave type method above. If you are, set this to the server you want to send # players too. -leaveServer: hub +leaveServer: "hub" # By default, the plugin forces you to use a map save to protect from changes to a map thought a game play though. It copies your # hide-and-seek world to a separate world, and loads the game there to contain the game in an isolated and backed up map This allows you to @@ -117,40 +117,16 @@ delayedRespawn: # MYSQL - Uses a mysql server to store data, good for multi-server setups or large servers. # # default: SQLITE -databaseType: SQLITE +databaseType: "SQLITE" # The following settings are used for MYSQL databases ONLY. If you are running SQLITE, these # will be ignored. If you are running MYSQL, you need to provide the database host url, database # host port (usually 3306), database username, and database password. -databaseHost: localhost +databaseHost: "localhost" databasePort: 3306 -databaseUser: root -databasePass: -databaseName: hideandseek - -# The world border closes every interval, which is evey [delay] in minutes. -# Thw world border starts at [size], and decreases 100 blocks every interval. -# x & z are the center location. [enabled] is whenever the border is enabled. -# You can choose if Hiders are warned 30 seconds before the border moves. - -# You want block hunt? We have block hunt! Just enable it below, and set the -# available blocks to pick from, and you're all set! It's that easy! -# Items are displayed in the order that they are listed below. -# The solidifyTime is the time in server ticks that it takes players to solidify. -# Every 20 ticks is a second. Minimum solidifyTime is 20 ticks. -blockhunt: - enabled: false - solidifyTime: 60 - blocks: [CRAFTING_TABLE, GRASS_BLOCK, DIRT, BEACON, BOOKSHELF] - -worldBorder: - x: 0 - z: 0 - delay: 10 - size: 500 - moveAmount: 100 - warn: true - enabled: false +databaseUser: "root" +databasePass: "pass" +databaseName: "hideandseek" # The taunt will activate every delay set in seconds. It will spawn a firework # on a random Hider to alert a Seeker where someone may be. You can choose @@ -173,8 +149,12 @@ glow: stackable: true enabled: true name: "Glow Powerup" - lore: [ "Throw to make all seekers glow", "Last 30s, all hiders can see it", "Time stacks on multi use" ] - material: SNOWBALL + lore: [ + "Throw to make all seekers glow", + "Last 30s, all hiders can see it", + "Time stacks on multi use" + ] + material: "SNOWBALL" model-data: 0 # This has the same glow effect as the glow powerup in that all seekers positions get @@ -221,14 +201,16 @@ lobby: # If you set adminOnly to false, only the item will become non admin only, not the command. lobbyItems: leave: - material: BED + material: "BED" name: "&cLeave Lobby" - lore: ["Go back to server hub"] + lore: [ + "Go back to server hub" + ] position: 8 model-data: 0 enabled: true start: - material: CLOCK + material: "CLOCK" name: "&bStart Game" lore: [] position: 0 @@ -241,15 +223,19 @@ lobbyItems: # and position of the item. You can also change the model data if your server is running 1.14 or above. spectatorItems: flight: - material: FEATHER + material: "FEATHER" name: "&bToggle Flight" - lore: [ "Turns flying on and off" ] + lore: [ + "Turns flying on and off" + ] position: 3 model-data: 0 teleport: - material: COMPASS + material: "COMPASS" name: "&bTeleport to Others" - lore: [ "Allows you to teleport to all other players in game" ] + lore: [ + "Allows you to teleport to all other players in game" + ] position: 5 model-data: 0 @@ -265,8 +251,8 @@ seekerPing: leadingVolume: 0.5 volume: 0.3 pitch: 1 - heartbeatNoise: BLOCK_NOTE_BLOCK_BASEDRUM - ringingNoise: BLOCK_NOTE_BLOCK_PLING + heartbeatNoise: "BLOCK_NOTE_BLOCK_BASEDRUM" + ringingNoise: "BLOCK_NOTE_BLOCK_PLING" enabled: true # Changes the default plugin language. Currently, Supported localizations are: @@ -275,26 +261,37 @@ seekerPing: locale: "en-US" # Stop commands being run by any user while playing the game. -# Can be usefull If you aren't using a permission plugin and want +# Can be usefull If you aren't using a permission plugin and don't want # to op people, but still want to block certain commands. # Not really usefully if using permission plugins. # You can add /kill for any use, but it's already blocked on those # playing the game. -blockedCommands: [msg, tp, gamemode, kill, give, effect] +blockedCommands: [ + "msg", + "tp", + "gamemode", + "kill", + "give", + "effect" +] # Stop interactions with any block by any user while playing the game. # If your map has things such as chests for aesthetic only, you can # block the use of clicking them. It shouldn't matter what version of # the block ID you enter, as the plugin will automatically switch to the # block ID of your current Minecraft server version. -blockedInteracts: [FURNACE, CRAFTING_TABLE, ANVIL, CHEST, BARREL] -# ---------------------------------------------------------- # -# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # -# ---------------------------------------------------------- # +blockedInteracts: [ + "FURNACE", + "CRAFTING_TABLE", + "ANVIL", + "CHEST", + "BARREL" +] # Location where players are teleported when they exit (/hs leave) +# Auto filled by /hs setexit, so you don't need to touch this here exit: x: 0 y: 0 z: 0 - world: world \ No newline at end of file + world: "world" \ No newline at end of file diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 91d7abe..53f86be 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -10,6 +10,7 @@ Localization: COMMAND_PLAYER_ONLY: "This command can only be run as a player." COMMAND_NOT_ALLOWED: "You are not allowed to run this command." COMMAND_ERROR: "An internal error has occurred." + COMMAND_INVALID_ARG: "Invalid argument: {AMOUNT}" GAME_PLAYER_DEATH: "&c{PLAYER}&f was killed." GAME_PLAYER_FOUND: "&e{PLAYER}&f was found and became a seeker." GAME_PLAYER_FOUND_BY: "&e{PLAYER}&f was found by &c{PLAYER}&f and became a seeker." @@ -17,7 +18,7 @@ Localization: GAME_GAMEOVER_SEEKERS_QUIT: "All seekers have quit." GAME_GAMEOVER_HIDERS_QUIT: "All hiders have quit." GAME_GAMEOVER_TIME: "Seekers ran out of time. Hiders win!" - GAME_SETUP: "There are no setup maps! Run /hs setup on a map to see what you need to do." + GAME_SETUP: "There are no setup maps! Run /hs map status on a map to see what you need to do." GAME_INGAME: "You are already in the lobby/game." GAME_NOT_INGAME: "You are not in a lobby/game." GAME_INPROGRESS: "There is currently a game in progress." @@ -32,6 +33,9 @@ Localization: MAPSAVE_END: "Map save complete." MAPSAVE_ERROR: "Couldn't find current map." MAPSAVE_DISABLED: "Mapsave is disabled in config.yml." + MAPSAVE_FAIL_WORLD: "Mapsave failed. Failed to load current world." + MAPSAVE_INVALID: "Invalid world to save: {AMOUNT}" + MAPSAVE_FAIL_DIR: "Failed to rename directory: {AMOUNT}" WORLDBORDER_DISABLE: "Disabled world border." WORLDBORDER_INVALID_INPUT: "Invalid integer {AMOUNT}." WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks." @@ -58,6 +62,7 @@ Localization: SEEKER_SPAWN: "Set seeker lobby position to current location" START_MIN_PLAYERS: "You must have at least {AMOUNT} players to start." START_INVALID_NAME: "Invalid player: {PLAYER}." + START_FAILED_SEEKER: "Failed to select random seeker." START_COUNTDOWN: "Hiders have {AMOUNT} seconds to hide!" START_COUNTDOWN_LAST: "Hiders have {AMOUNT} second to hide!" START: "Attention SEEKERS, its time to find the hiders!" @@ -77,9 +82,9 @@ Localization: FLYING_ENABLED: "&l&bFlying Enabled" FLYING_DISABLED: "&l&bFlying Disabled" RESPAWN_NOTICE: "You will respawn in {AMOUNT} seconds." - INVALID_MAP: "That is an invalid map name!!" + INVALID_MAP: "That is an invalid map name!" MAP_ALREADY_EXISTS: "This map already exists!" - INVALID_MAP_NAME: "A map name can only contain numbers or letters" + INVALID_MAP_NAME: "A map name can only contain numbers or letters." MAP_CREATED: "Created new map: {AMOUNT}" MAP_FAIL_DELETE: "Failed to delete map: {AMOUNT}" MAP_DELETED: "Deleted map: {AMOUNT}" @@ -88,9 +93,11 @@ Localization: LIST_MAPS: "The current maps are:" ARGUMENT_COUNT: "This command requires more arguments to run." GAME_SPAWN_NEEDED: "Game spawn must be set before seeker spawn." - SEEKER_LOBBY_SPAWN_RESET: "Seeker lobby spawn reset since the game spawn was moved to a new world" - SEEKER_LOBBY_INVALID: "Seeker lobby must be in the same world as game spawn" + SEEKER_LOBBY_SPAWN_RESET: "Seeker lobby spawn reset since the game spawn was moved to a new world." + SEEKER_LOBBY_INVALID: "Seeker lobby must be in the same world as game spawn." + CONFIG_ERROR: "Error reloading config. Check server logs." + BLOCKHUNT_DISABLED: "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE -version: 3 +version: 4 type: "en-US" \ No newline at end of file diff --git a/src/main/resources/leaderboard.yml b/src/main/resources/leaderboard.yml index 9c7a777..cd958a3 100644 --- a/src/main/resources/leaderboard.yml +++ b/src/main/resources/leaderboard.yml @@ -16,6 +16,7 @@ # {COUNT} - The amount of player currently in the lobby. # {SEEKER%} - The chance that a player will be selected to be a seeker. # {HIDER%} - The chance that a player will be selected to be a hider. +# {MAP} - The current map the player is on # # GAME BOARD PLACEHOLDERS # @@ -38,6 +39,7 @@ # only Hiders will be able to see its effects though. # {#SEEKER} - Number of current seekers. # {#HIDER} - Number of current hiders. +# {MAP} - The current map the player is on # # YOU CANNOT USE TWO PLACEHOLDERS ON THE SAME LINE. ONLY THE FIRST ONE WILL # BE CHANGED, AND THE SECOND ONE WILL SAY A PLACEHOLDER MARKER! @@ -50,12 +52,15 @@ lobby: "Players: {COUNT}", "", "&cSEEKER % &f{SEEKER%}", - "&6HIDER % &f{HIDER%}" + "&6HIDER % &f{HIDER%}", + "", + "Map: {MAP}", ] game: title: "&eHIDE AND SEEK" content: [ + "Map: {MAP}", "Team: {TEAM}", "", "Time Left: &a{TIME}",