From 1325e042a6e7af37669bcd32e9d7a133f2ae22e6 Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 30 Oct 2022 21:40:59 -0400 Subject: finish beta build of multi map support --- src/main/java/net/tylermurphy/hideAndSeek/command/About.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/About.java') diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 54af32b..54e0de7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -22,11 +22,13 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import java.util.List; + public class About implements ICommand { public void execute(Player sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(%s1.6.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(%s1.7.0 ALPHA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); @@ -44,4 +46,8 @@ public class About implements ICommand { return "Get information about the plugin"; } + public List autoComplete(String parameter) { + return null; + } + } -- cgit v1.2.3-freya From 7530fe5e2dad89cabd694aefc91758a651ca9196 Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Mon, 31 Oct 2022 23:28:45 -0400 Subject: 1.7.0 beta 1 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 55 +++++-- .../net/tylermurphy/hideAndSeek/command/About.java | 3 +- .../tylermurphy/hideAndSeek/command/AddMap.java | 54 ------- .../net/tylermurphy/hideAndSeek/command/Debug.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Help.java | 17 ++- .../tylermurphy/hideAndSeek/command/ICommand.java | 39 ----- .../net/tylermurphy/hideAndSeek/command/Join.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Leave.java | 3 +- .../tylermurphy/hideAndSeek/command/ListMaps.java | 46 ------ .../tylermurphy/hideAndSeek/command/Reload.java | 3 +- .../tylermurphy/hideAndSeek/command/RemoveMap.java | 52 ------- .../tylermurphy/hideAndSeek/command/SaveMap.java | 96 ------------ .../tylermurphy/hideAndSeek/command/SetBorder.java | 113 -------------- .../tylermurphy/hideAndSeek/command/SetBounds.java | 111 -------------- .../tylermurphy/hideAndSeek/command/SetMap.java | 66 -------- .../net/tylermurphy/hideAndSeek/command/Setup.java | 99 ------------ .../net/tylermurphy/hideAndSeek/command/Start.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Stop.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Top.java | 3 +- .../net/tylermurphy/hideAndSeek/command/Wins.java | 3 +- .../command/location/SetExitLocation.java | 6 +- .../command/location/SetLobbyLocation.java | 8 +- .../command/location/SetSeekerLobbyLocation.java | 6 +- .../command/location/SetSpawnLocation.java | 6 +- .../hideAndSeek/command/map/AddMap.java | 54 +++++++ .../hideAndSeek/command/map/ListMaps.java | 47 ++++++ .../hideAndSeek/command/map/RemoveMap.java | 53 +++++++ .../hideAndSeek/command/map/SaveMap.java | 97 ++++++++++++ .../hideAndSeek/command/map/SetBorder.java | 112 ++++++++++++++ .../hideAndSeek/command/map/SetBounds.java | 112 ++++++++++++++ .../hideAndSeek/command/map/SetMap.java | 67 ++++++++ .../tylermurphy/hideAndSeek/command/map/Setup.java | 97 ++++++++++++ .../hideAndSeek/command/util/Command.java | 43 ++++++ .../hideAndSeek/command/util/CommandGroup.java | 170 +++++++++++++++++++++ .../tylermurphy/hideAndSeek/configuration/Map.java | 64 +++++--- .../hideAndSeek/configuration/Maps.java | 30 ++-- .../net/tylermurphy/hideAndSeek/game/Game.java | 4 - .../hideAndSeek/game/listener/DamageHandler.java | 1 - .../hideAndSeek/util/CommandHandler.java | 111 -------------- .../tylermurphy/hideAndSeek/util/TabCompleter.java | 59 ------- 40 files changed, 1001 insertions(+), 923 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/About.java') diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index aace88e..b22af5b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -19,6 +19,9 @@ package net.tylermurphy.hideAndSeek; +import net.tylermurphy.hideAndSeek.command.*; +import net.tylermurphy.hideAndSeek.command.location.*; +import net.tylermurphy.hideAndSeek.command.map.*; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Localization; @@ -26,13 +29,13 @@ import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.game.*; import net.tylermurphy.hideAndSeek.game.util.Status; -import net.tylermurphy.hideAndSeek.util.CommandHandler; +import net.tylermurphy.hideAndSeek.command.util.CommandGroup; import net.tylermurphy.hideAndSeek.game.listener.*; import net.tylermurphy.hideAndSeek.util.PAPIExpansion; -import net.tylermurphy.hideAndSeek.util.TabCompleter; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; @@ -43,8 +46,8 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; -import static net.tylermurphy.hideAndSeek.configuration.Config.exitWorld; +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Main extends JavaPlugin implements Listener { @@ -56,6 +59,7 @@ public class Main extends JavaPlugin implements Listener { private Disguiser disguiser; private EntityHider entityHider; private Game game; + private CommandGroup commandGroup; public void onEnable() { Main.instance = this; @@ -72,9 +76,36 @@ public class Main extends JavaPlugin implements Listener { this.entityHider = new EntityHider(this, EntityHider.Policy.BLACKLIST); this.registerListeners(); - CommandHandler.registerCommands(); - - game = new Game(game.getCurrentMap(), board); + this.commandGroup = new CommandGroup("hs", + new About(), + new Debug(), + new Help(), + new Reload(), + new Join(), + new Leave(), + new Start(), + new Stop(), + new CommandGroup("map", + new CommandGroup("set", + new SetLobbyLocation(), + new SetSpawnLocation(), + new SetSeekerLobbyLocation(), + new SetBorder(), + new SetBounds() + ), + new AddMap(), + new RemoveMap(), + new ListMaps(), + new SetMap(), + new Setup(), + new SaveMap() + ), + new SetExitLocation(), + new Top(), + new Wins() + ); + + game = new Game(null, board); getServer().getScheduler().runTaskTimer(this, this::onTick,0,1).getTaskId(); @@ -102,7 +133,7 @@ public class Main extends JavaPlugin implements Listener { } private void onTick() { - if(game.getStatus() == Status.ENDED) game = new Game(board); + if(game.getStatus() == Status.ENDED) game = new Game(game.getCurrentMap(), board); game.onTick(); disguiser.check(); } @@ -130,11 +161,15 @@ public class Main extends JavaPlugin implements Listener { } public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { - return CommandHandler.handleCommand(sender, args); + if (!(sender instanceof Player)) { + sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); + return true; + } + return commandGroup.handleCommand((Player)sender, "", args); } public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { - return TabCompleter.handleTabComplete(sender, args); + return commandGroup.handleTabComplete(sender, args); } public static Main getInstance() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 54e0de7..119888b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -19,12 +19,13 @@ package net.tylermurphy.hideAndSeek.command; +import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.util.List; -public class About implements ICommand { +public class About extends Command { public void execute(Player sender, String[] args) { sender.sendMessage( diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java deleted file mode 100644 index 086280e..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/AddMap.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class AddMap implements ICommand { - - public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map != null) { - sender.sendMessage(errorPrefix + message("MAP_ALREADY_EXISTS")); - } else if(!args[0].matches("[a-zA-Z0-9]*") || args[0].length() < 1) { - sender.sendMessage(errorPrefix + message("INVALID_MAP_NAME")); - } else { - Maps.setMap(args[0], new Map(args[0])); - sender.sendMessage(messagePrefix + message("MAP_CREATED").addAmount(args[0])); - } - } - - public String getLabel() { - return "addmap"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Add a map to the plugin!"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("name")) { - return Collections.singletonList("name"); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java index e877659..2eb0eb9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.command; import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.PlayerLoader; import net.tylermurphy.hideAndSeek.game.util.Status; @@ -21,7 +22,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Debug implements ICommand { +public class Debug extends Command { private static final Map>> debugMenuFunctions = new HashMap<>(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 5de7210..4297f3d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -20,20 +20,21 @@ package net.tylermurphy.hideAndSeek.command; import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.util.CommandHandler; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.util.CommandGroup; import org.bukkit.entity.Player; import java.util.List; -public class Help implements ICommand { +public class Help extends Command { public void execute(Player sender, String[] args) { - StringBuilder message = new StringBuilder(); - for(ICommand command : CommandHandler.COMMAND_REGISTER.values()) { - message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n")); - } - message = new StringBuilder(message.substring(0, message.length() - 1)); - sender.sendMessage(message.toString()); +// StringBuilder message = new StringBuilder(); +// for(Command command : CommandGroup.COMMAND_REGISTER.values()) { +// message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n")); +// } +// message = new StringBuilder(message.substring(0, message.length() - 1)); +// sender.sendMessage(message.toString()); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java deleted file mode 100644 index 91fd8f9..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public interface ICommand { - - void execute(Player sender, String[] args); - - String getLabel(); - - String getUsage(); - - String getDescription(); - - List autoComplete(@Nullable String parameter); - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index c57b953..ca2a77f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -28,7 +29,7 @@ import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Join implements ICommand { +public class Join extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index 0e860cb..d22aad9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -28,7 +29,7 @@ import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Leave implements ICommand { +public class Leave extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java deleted file mode 100644 index 0025de5..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ListMaps.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.Collection; -import java.util.List; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class ListMaps implements ICommand { - - public void execute(Player sender, String[] args) { - Collection maps = Maps.getAllMaps(); - if(maps.size() < 1) { - sender.sendMessage(errorPrefix + message("NO_MAPS")); - return; - } - StringBuilder response = new StringBuilder(messagePrefix + message("LIST_MAPS")); - for(Map map : maps) { - response.append("\n ").append(map.getName()).append(": ").append(map.isNotSetup() ? ChatColor.RED + "NOT SETUP" : ChatColor.GREEN + "SETUP").append(ChatColor.WHITE); - } - sender.sendMessage(response.toString()); - } - - public String getLabel() { - return "listmaps"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "List all maps in the plugin"; - } - - public List autoComplete(String parameter) { - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 4a4efbe..51bc509 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Localization; @@ -33,7 +34,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Reload implements ICommand { +public class Reload extends Command { public void execute(Player sender, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java deleted file mode 100644 index b5727c8..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/RemoveMap.java +++ /dev/null @@ -1,52 +0,0 @@ -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class RemoveMap implements ICommand { - - public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - } else if(!Maps.removeMap(args[0])){ - sender.sendMessage(errorPrefix + message("MAP_FAIL_DELETE").addAmount(args[0])); - } else { - sender.sendMessage(messagePrefix + message("MAP_DELETED").addAmount(args[0])); - } - } - - public String getLabel() { - return "removemap"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Remove a map from the plugin!"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java deleted file mode 100644 index ca2532c..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SaveMap implements ICommand { - - public static boolean runningBackup = false; - - public void execute(Player sender, String[] args) { - if (!mapSaveEnabled) { - sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); - return; - } - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - sender.sendMessage(messagePrefix + message("MAPSAVE_START")); - sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); - World world = map.getSpawn().getWorld(); - if (world == null) { - throw new RuntimeException("Unable to get spawn world"); - } - world.save(); - BukkitRunnable runnable = new BukkitRunnable() { - public void run() { - sender.sendMessage( - map.getWorldLoader().save() - ); - runningBackup = false; - } - }; - runnable.runTaskAsynchronously(Main.getInstance()); - runningBackup = true; - } - - public String getLabel() { - return "saveMap"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Saves current map for the game. May lag server."; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java deleted file mode 100644 index 9768030..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetBorder implements ICommand { - - public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - if (args.length < 4) { - map.setWorldBorderData(0, 0, 0, 0, 0); - addToConfig("worldBorder.enabled",false); - saveConfig(); - sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); - Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); - return; - } - int num,delay,change; - try { num = Integer.parseInt(args[0]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); - return; - } - try { delay = Integer.parseInt(args[1]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); - return; - } - try { change = Integer.parseInt(args[2]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); - return; - } - if (num < 100) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); - return; - } - if (change < 1) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); - return; - } - map.setWorldBorderData( - sender.getLocation().getBlockX(), - sender.getLocation().getBlockZ(), - num, - delay, - change - ); - Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); - map.getWorldBorder().resetWorldBorder(); - } - - public String getLabel() { - return "setBorder"; - } - - public String getUsage() { - return " <*size> <*delay> <*move>"; - } - - public String getDescription() { - return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return Collections.singletonList(parameter); - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java deleted file mode 100644 index 563116d..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetBounds implements ICommand { - - public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - if (!sender.getWorld().getName().equals(map.getSpawnName())) { - sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); - return; - } - if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { - sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - boolean first = true; - int bxs = map.getBoundsMin().getBlockX(); - int bzs = map.getBoundsMin().getBlockZ(); - int bxl = map.getBoundsMax().getBlockX(); - int bzl = map.getBoundsMax().getBlockZ(); - if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { - bxs = bzs = bxl = bzl = 0; - } - if (bxl == 0) { - bxl = sender.getLocation().getBlockX(); - } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { - first = false; - bxs = bxl; - bxl = sender.getLocation().getBlockX(); - } else { - first = false; - bxs = sender.getLocation().getBlockX(); - } - if (bzl == 0) { - bzl = sender.getLocation().getBlockZ(); - } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { - first = false; - bzs = bzl; - bzl = sender.getLocation().getBlockZ(); - } else { - first = false; - bzs = sender.getLocation().getBlockZ(); - } - map.setBoundMin(bxs, bzs); - map.setBoundMax(bxl, bzl); - Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); - } - - public String getLabel() { - return "setBounds"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets the map bounds for the game."; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java deleted file mode 100644 index c2c6a6e..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetMap.java +++ /dev/null @@ -1,66 +0,0 @@ -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetMap implements ICommand { - - public void execute(Player sender, String[] args) { - - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - - if(map.isNotSetup()){ - sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP")); - return; - } - - if (!Main.getInstance().getBoard().contains(sender)) { - sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); - return; - } - - Main.getInstance().getGame().setCurrentMap(map); - for(Player player : Main.getInstance().getBoard().getPlayers()) { - player.teleport(map.getLobby()); - } - - } - - public String getLabel() { - return "setmap"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Set the current lobby to another map"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java deleted file mode 100644 index b222c61..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.entity.Player; - -import java.io.File; -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class Setup implements ICommand { - - public void execute(Player sender, String[] args) { - - String msg = message("SETUP").toString(); - int count = 0; - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.getSpawn().getWorld() == null || map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_GAME"); - count++; - } - if (map.getLobby().getWorld() == null || map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_LOBBY"); - count++; - } - if (map.getSeekerLobby().getWorld() == null || map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); - count++; - } - if (exitWorld == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_EXIT"); - count++; - } - if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || - map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { - msg = msg + "\n" + message("SETUP_BOUNDS"); - count++; - } - if (mapSaveEnabled) { - File destenation = new File(Main.getInstance().getWorldContainer() + File.separator + map.getGameSpawnName()); - if (!destenation.exists()) { - msg = msg + "\n" + message("SETUP_SAVEMAP"); - count++; - } - } - if (count < 1) { - sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); - } else { - sender.sendMessage(msg); - } - } - - public String getLabel() { - return "setup"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Shows what needs to be setup"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 085aeab..54ad4af 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -34,7 +34,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.minPlayers; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Start implements ICommand { +public class Start extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 4567bb1..1582be9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -20,17 +20,17 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; import java.util.List; -import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.abortPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Stop implements ICommand { +public class Stop extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index c57f246..8116eaf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -30,7 +31,7 @@ import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Top implements ICommand { +public class Top extends Command { public void execute(Player sender, String[] args) { int page; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index 9ed7345..c5917c2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.database.util.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -31,7 +32,7 @@ import java.util.UUID; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Wins implements ICommand { +public class Wins extends Command { public void execute(Player sender, String[] args) { Main.getInstance().getServer().getScheduler().runTaskAsynchronously(Main.getInstance(), () -> { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java index 1bb1d6f..01e1512 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -19,18 +19,16 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; -import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; import java.util.List; -import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -public class SetExitLocation implements ICommand { +public class SetExitLocation extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.EXIT, null, map -> { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java index 84e1109..da41d91 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -19,7 +19,7 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; @@ -28,9 +28,7 @@ import org.bukkit.entity.Player; import java.util.List; import java.util.stream.Collectors; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -public class SetLobbyLocation implements ICommand { +public class SetLobbyLocation extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { @@ -39,7 +37,7 @@ public class SetLobbyLocation implements ICommand { } public String getLabel() { - return "setlobby"; + return "lobby"; } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java index c6d9f93..8a5ebd1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java @@ -1,6 +1,6 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; @@ -11,7 +11,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetSeekerLobbyLocation implements ICommand { +public class SetSeekerLobbyLocation extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { @@ -26,7 +26,7 @@ public class SetSeekerLobbyLocation implements ICommand { } public String getLabel() { - return "setseekerlobby"; + return "seekerlobby"; } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java index 50932d6..82f71d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -19,7 +19,7 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; import net.tylermurphy.hideAndSeek.configuration.Maps; @@ -33,7 +33,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetSpawnLocation implements ICommand { +public class SetSpawnLocation extends Command { public void execute(Player sender, String[] args) { LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { @@ -58,7 +58,7 @@ public class SetSpawnLocation implements ICommand { } public String getLabel() { - return "setspawn"; + return "spawn"; } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java new file mode 100644 index 0000000..55b4267 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java @@ -0,0 +1,54 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class AddMap extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map != null) { + sender.sendMessage(errorPrefix + message("MAP_ALREADY_EXISTS")); + } else if(!args[0].matches("[a-zA-Z0-9]*") || args[0].length() < 1) { + sender.sendMessage(errorPrefix + message("INVALID_MAP_NAME")); + } else { + Maps.setMap(args[0], new Map(args[0])); + sender.sendMessage(messagePrefix + message("MAP_CREATED").addAmount(args[0])); + } + } + + public String getLabel() { + return "add"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Add a map to the plugin!"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("name")) { + return Collections.singletonList("name"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java new file mode 100644 index 0000000..79490a7 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java @@ -0,0 +1,47 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class ListMaps extends Command { + + public void execute(Player sender, String[] args) { + Collection maps = Maps.getAllMaps(); + if(maps.size() < 1) { + sender.sendMessage(errorPrefix + message("NO_MAPS")); + return; + } + StringBuilder response = new StringBuilder(messagePrefix + message("LIST_MAPS")); + for(Map map : maps) { + response.append("\n ").append(map.getName()).append(": ").append(map.isNotSetup() ? ChatColor.RED + "NOT SETUP" : ChatColor.GREEN + "SETUP").append(ChatColor.WHITE); + } + sender.sendMessage(response.toString()); + } + + public String getLabel() { + return "list"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "List all maps in the plugin"; + } + + public List autoComplete(String parameter) { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java new file mode 100644 index 0000000..216cca9 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java @@ -0,0 +1,53 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class RemoveMap extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + } else if(!Maps.removeMap(args[0])){ + sender.sendMessage(errorPrefix + message("MAP_FAIL_DELETE").addAmount(args[0])); + } else { + sender.sendMessage(messagePrefix + message("MAP_DELETED").addAmount(args[0])); + } + } + + public String getLabel() { + return "remove"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Remove a map from the plugin!"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java new file mode 100644 index 0000000..f3eb4d7 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java @@ -0,0 +1,97 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SaveMap extends Command { + + public static boolean runningBackup = false; + + public void execute(Player sender, String[] args) { + if (!mapSaveEnabled) { + sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); + return; + } + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + sender.sendMessage(messagePrefix + message("MAPSAVE_START")); + sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); + World world = map.getSpawn().getWorld(); + if (world == null) { + throw new RuntimeException("Unable to get spawn world"); + } + world.save(); + BukkitRunnable runnable = new BukkitRunnable() { + public void run() { + sender.sendMessage( + map.getWorldLoader().save() + ); + runningBackup = false; + } + }; + runnable.runTaskAsynchronously(Main.getInstance()); + runningBackup = true; + } + + public String getLabel() { + return "save"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Saves current map for the game. May lag server."; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java new file mode 100644 index 0000000..8362e02 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java @@ -0,0 +1,112 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SetBorder extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + if (args.length < 4) { + map.setWorldBorderData(0, 0, 0, 0, 0); + addToConfig("worldBorder.enabled",false); + saveConfig(); + sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); + Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); + return; + } + int num,delay,change; + try { num = Integer.parseInt(args[1]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + try { delay = Integer.parseInt(args[2]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); + return; + } + try { change = Integer.parseInt(args[3]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); + return; + } + if (num < 100) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); + return; + } + if (change < 1) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); + return; + } + map.setWorldBorderData( + sender.getLocation().getBlockX(), + sender.getLocation().getBlockZ(), + num, + delay, + change + ); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); + map.getWorldBorder().resetWorldBorder(); + } + + public String getLabel() { + return "border"; + } + + public String getUsage() { + return " <*size> <*delay> <*move>"; + } + + public String getDescription() { + return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return Collections.singletonList(parameter); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java new file mode 100644 index 0000000..92bf5a4 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java @@ -0,0 +1,112 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SetBounds extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + if (!sender.getWorld().getName().equals(map.getSpawnName())) { + sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); + return; + } + if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { + sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + boolean first = true; + int bxs = map.getBoundsMin().getBlockX(); + int bzs = map.getBoundsMin().getBlockZ(); + int bxl = map.getBoundsMax().getBlockX(); + int bzl = map.getBoundsMax().getBlockZ(); + if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { + bxs = bzs = bxl = bzl = 0; + } + if (bxl == 0) { + bxl = sender.getLocation().getBlockX(); + } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { + first = false; + bxs = bxl; + bxl = sender.getLocation().getBlockX(); + } else { + first = false; + bxs = sender.getLocation().getBlockX(); + } + if (bzl == 0) { + bzl = sender.getLocation().getBlockZ(); + } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { + first = false; + bzs = bzl; + bzl = sender.getLocation().getBlockZ(); + } else { + first = false; + bzs = sender.getLocation().getBlockZ(); + } + map.setBoundMin(bxs, bzs); + map.setBoundMax(bxl, bzl); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); + } + + public String getLabel() { + return "bounds"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets the map bounds for the game."; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java new file mode 100644 index 0000000..2df5824 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java @@ -0,0 +1,67 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SetMap extends Command { + + public void execute(Player sender, String[] args) { + + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + + if(map.isNotSetup()){ + sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP")); + return; + } + + if (!Main.getInstance().getBoard().contains(sender)) { + sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); + return; + } + + Main.getInstance().getGame().setCurrentMap(map); + for(Player player : Main.getInstance().getBoard().getPlayers()) { + player.teleport(map.getLobby()); + } + + } + + public String getLabel() { + return "goto"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Set the current lobby to another map"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java new file mode 100644 index 0000000..46b41f7 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java @@ -0,0 +1,97 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.io.File; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Setup extends Command { + + public void execute(Player sender, String[] args) { + + String msg = message("SETUP").toString(); + int count = 0; + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + msg = msg + "\n" + message("SETUP_GAME"); + count++; + } + if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + msg = msg + "\n" + message("SETUP_LOBBY"); + count++; + } + if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !Map.worldExists(map.getSeekerLobbyName())) { + msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); + count++; + } + if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld)) { + msg = msg + "\n" + message("SETUP_EXIT"); + count++; + } + if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || + map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { + msg = msg + "\n" + message("SETUP_BOUNDS"); + count++; + } + if (mapSaveEnabled && !Map.worldExists(map.getGameSpawnName())) { + msg = msg + "\n" + message("SETUP_SAVEMAP"); + count++; + } + if (count < 1) { + sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); + } else { + sender.sendMessage(msg); + } + } + + public String getLabel() { + return "setup"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Shows what needs to be setup"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java new file mode 100644 index 0000000..d03274d --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java @@ -0,0 +1,43 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.util; + +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public abstract class Command { + + public abstract void execute(Player sender, String[] args); + + public abstract String getLabel(); + + public abstract String getUsage(); + + public abstract String getDescription(); + + public abstract List autoComplete(@Nullable String parameter); + + public boolean hasPermission(Player sender, String permission) { + return sender.hasPermission(permission+"."+getLabel()); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java new file mode 100644 index 0000000..9079ccc --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -0,0 +1,170 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.util; + +import net.tylermurphy.hideAndSeek.command.*; +import net.tylermurphy.hideAndSeek.command.map.SaveMap; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.permissionsRequired; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class CommandGroup { + + private final Map commandRegister; + private final String label; + + public CommandGroup(String label, Object... data) { + this.label = label; + this.commandRegister = new HashMap<>(); + for(Object o : data) registerCommand(o); + } + + public String getLabel() { + return label; + } + + private void registerCommand(Object object) { + if(object instanceof Command) { + Command command = (Command) object; + if (!commandRegister.containsKey(command.getLabel())) { + commandRegister.put(command.getLabel().toLowerCase(), command); + } + } else if(object instanceof CommandGroup) { + CommandGroup group = (CommandGroup) object; + if (!commandRegister.containsKey(group.getLabel())) { + commandRegister.put(group.getLabel().toLowerCase(), group); + } + } + } + + public boolean handleCommand(Player player, String permission, String[] args) { + if (args.length < 1 && permission.equals("hs") || !commandRegister.containsKey(args[0].toLowerCase()) ) { + if (permissionsRequired && !player.hasPermission("hs.about")) { + player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); + } else { + new About().execute(player, null); + } + } else { + String invoke = args[0].toLowerCase(); + if (!invoke.equals("about") && !invoke.equals("help") && SaveMap.runningBackup) { + player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); + } else if (permissionsRequired && !player.hasPermission(permission+"."+invoke)) { + player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); + } else { + try { + Object object = commandRegister.get(invoke); + if(object instanceof CommandGroup) return ((CommandGroup) object).handleCommand(player, permission+"."+this.label, Arrays.copyOfRange(args, 1, args.length)); + Command command = (Command) object; + + int parameters = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); + if(args.length - 1 < parameters) { + player.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); + return true; + } + command.execute(player,Arrays.copyOfRange(args, 1, args.length)); + } catch (Exception e) { + player.sendMessage(errorPrefix + "An error has occurred."); + e.printStackTrace(); + } + } + } + return true; + } + + public List handleTabComplete(CommandSender sender, String[] args) { + String invoke = args[0].toLowerCase(); + if (args.length == 1) { + if(sender instanceof Player) { + Player player = (Player) sender; + return new ArrayList<>(commandRegister.keySet()) + .stream() + .filter(handle -> handle.toLowerCase().startsWith(invoke)) + .filter(handle -> { + Object object = commandRegister.get(handle); + if (object instanceof Command) return ((Command) object).hasPermission(player, this.label); + if (object instanceof CommandGroup) + return ((CommandGroup) object).hasPermission(player, this.label); + return false; + }) + .collect(Collectors.toList()); + } + return commandRegister.keySet().stream().filter(handle -> handle.toLowerCase().startsWith(invoke)).collect(Collectors.toList()); + } else { + if (!commandRegister.containsKey(invoke)) { + return new ArrayList<>(); + } else { + Object object = commandRegister.get(invoke); + if(object instanceof CommandGroup) return ((CommandGroup) object).handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length)); + Command command = (Command) object; + String[] usage = command.getUsage().split(" "); + List complete; + if (args.length - 2 < usage.length) { + String parameter = usage[args.length-2]; + String name = parameter.replace("<", "").replace(">", ""); + complete = command.autoComplete(name); + } else { + complete = command.autoComplete(null); + } + if(complete == null) return new ArrayList<>(); + else return complete; + } + } + } + + private boolean hasPermission(Player player, String permission) { + for(Object object : commandRegister.values()) { + if(object instanceof Command) if(((Command) object).hasPermission(player, this.label)) return true; + if(object instanceof CommandGroup) if (((CommandGroup) object).hasPermission(player, permission+"."+this.label)) return true; + } + return false; + } + + // public static void registerCommands() { +// registerCommand(new About()); +// registerCommand(new Help()); +// registerCommand(new Setup()); +// registerCommand(new Start()); +// registerCommand(new Stop()); +// registerCommand(new SetSpawnLocation()); +// registerCommand(new SetLobbyLocation()); +// registerCommand(new SetSeekerLobbyLocation()); +// registerCommand(new SetExitLocation()); +// registerCommand(new SetBorder()); +// registerCommand(new Reload()); +// registerCommand(new SaveMap()); +// registerCommand(new SetBounds()); +// registerCommand(new Join()); +// registerCommand(new Leave()); +// registerCommand(new Top()); +// registerCommand(new Wins()); +// registerCommand(new Debug()); +// registerCommand(new AddMap()); +// registerCommand(new RemoveMap()); +// registerCommand(new ListMaps()); +// registerCommand(new SetMap()); +// } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java index 42cab4b..5e9b6ae 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java @@ -23,7 +23,9 @@ public class Map { seekerLobbyPosition = new Location(null, 0, 0, 0); private String - gameWorldName = "world"; + spawnWorldName = "world", + lobbyWorldName = "world", + seekerLobbyWorldName = "world"; private int xBoundMin = 0, @@ -57,15 +59,31 @@ public class Map { public void setSpawn(Location pos) { this.spawnPosition = pos; if(pos.getWorld() != null) - this.gameWorldName = pos.getWorld().getName(); + this.spawnWorldName = pos.getWorld().getName(); } public void setLobby(Location pos) { this.lobbyPosition = pos; + if(pos.getWorld() != null) + this.lobbyWorldName = pos.getWorld().getName(); } public void setSeekerLobby(Location pos) { this.seekerLobbyPosition = pos; + if(pos.getWorld() != null) + this.seekerLobbyWorldName = pos.getWorld().getName(); + } + + public void setSpawnName(String name) { + this.spawnWorldName = name; + } + + public void setLobbyName(String name) { + this.lobbyWorldName = name; + } + + public void setSeekerLobbyName(String name) { + this.seekerLobbyWorldName = name; } public void setWorldBorderData(int x, int z, int size, int delay, int move) { @@ -103,7 +121,7 @@ public class Map { public Location getGameSpawn() { if(mapSaveEnabled) { return new Location( - Bukkit.getWorld("hs_" + gameWorldName), + Bukkit.getWorld("hs_" + spawnWorldName), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ() @@ -114,7 +132,10 @@ public class Map { } public String getGameSpawnName() { - return "hs_"+gameWorldName; + if(mapSaveEnabled) + return "hs_"+ spawnWorldName; + else + return spawnWorldName; } public Location getSpawn() { @@ -122,21 +143,29 @@ public class Map { } public String getSpawnName() { - return gameWorldName; + return spawnWorldName; } public Location getLobby() { return lobbyPosition; } + public String getLobbyName() { + return lobbyWorldName; + } + public Location getSeekerLobby() { return seekerLobbyPosition; } + public String getSeekerLobbyName() { + return seekerLobbyWorldName; + } + public Location getGameSeekerLobby() { if(mapSaveEnabled) { return new Location( - Bukkit.getWorld("hs_" + gameWorldName), + Bukkit.getWorld("hs_" + getSeekerLobbyName()), seekerLobbyPosition.getX(), seekerLobbyPosition.getY(), seekerLobbyPosition.getZ() @@ -203,19 +232,11 @@ public class Map { } public boolean isNotSetup() { - if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true; - if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true; - if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true; - if (exitPosition.getWorld() == null) { - Bukkit.getServer().createWorld(new WorldCreator(exitWorld).generator(new VoidGenerator())); - World world = Bukkit.getServer().getWorld(exitWorld); - if(world == null) return true; - } - if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0) return true; - if (mapSaveEnabled) { - File destination = new File(Main.getInstance().getWorldContainer() + File.separator + spawnPosition.getWorld().getName()); - if (!destination.exists()) return true; - } + if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !Map.worldExists(spawnWorldName)) return true; + if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !Map.worldExists(lobbyWorldName)) return true; + if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld) ) return true; + if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !Map.worldExists(seekerLobbyWorldName)) return true; + if (mapSaveEnabled && !Map.worldExists(getGameSpawnName())) return true; if(isWorldBorderEnabled() && new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true; return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; @@ -225,4 +246,9 @@ public class Map { return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0; } + public static boolean worldExists(String worldName) { + File destination = new File(Main.getInstance().getWorldContainer()+File.separator+worldName); + return destination.isDirectory(); + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java index 4f18639..ff1b396 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Maps.java @@ -60,7 +60,6 @@ public class Maps { MAPS.clear(); for(String key : keys) { - System.out.println(key); MAPS.put(key, parseMap(maps, key)); } @@ -71,8 +70,11 @@ public class Maps { if(data == null) return null; Map map = new Map(name); map.setSpawn(setSpawn(data, "game")); + map.setSpawnName(data.getString("spawns.game.world")); map.setLobby(setSpawn(data, "lobby")); + map.setLobbyName(data.getString("spawns.lobby.world")); map.setSeekerLobby(setSpawn(data, "seeker")); + map.setSeekerLobbyName(data.getString("spawns.seeker.world")); map.setBoundMin(data.getInt("bounds.min.x"), data.getInt("bounds.min.z")); map.setBoundMax(data.getInt("bounds.max.x"), data.getInt("bounds.max.z")); map.setWorldBorderData( @@ -100,8 +102,8 @@ public class Maps { private static Location setSpawn(ConfigurationSection data, String spawn) { String worldName = data.getString("spawns."+spawn+".world"); if(worldName == null) return new Location(null, 0, 0, 0); + if(!Map.worldExists(worldName)) return new Location(null, 0, 0, 0); World world = Bukkit.getWorld(worldName); - if(world == null) return new Location(null, 0, 0, 0); double x = data.getDouble("spawns."+spawn+".x"); double y = data.getDouble("spawns."+spawn+".y"); double z = data.getDouble("spawns."+spawn+".z"); @@ -115,9 +117,9 @@ public class Maps { for(Map map : MAPS.values()) { ConfigurationSection data = new YamlConfiguration(); - saveSpawn(data, map.getSpawn(), "game"); - saveSpawn(data, map.getLobby(), "lobby"); - saveSpawn(data, map.getSeekerLobby(), "seeker"); + saveSpawn(data, map.getSpawn(), "game", map); + saveSpawn(data, map.getLobby(), "lobby", map); + saveSpawn(data, map.getSeekerLobby(), "seeker", map); data.set("bounds.min.x", map.getBoundsMin().getX()); data.set("bounds.min.z", map.getBoundsMin().getZ()); data.set("bounds.max.x", map.getBoundsMax().getX()); @@ -137,15 +139,25 @@ public class Maps { } - private static void saveSpawn(ConfigurationSection data, Location spawn, String name) { - if(spawn.getWorld() != null) { - data.set("spawns." + name + ".world", spawn.getWorld().getName()); - } else { + private static void saveSpawn(ConfigurationSection data, Location spawn, String name, Map map) { + String worldName = getWorldName(name, map); + if(worldName == null || !Map.worldExists(worldName)) { data.set("spawns." + name + ".world", "world"); + } else { + data.set("spawns." + name + ".world", worldName); } data.set("spawns." + name + ".x", spawn.getX()); data.set("spawns." + name + ".y", spawn.getY()); data.set("spawns." + name + ".z", spawn.getZ()); } + private static String getWorldName(String name, Map map) { + switch (name) { + case "game": return map.getSpawnName(); + case "lobby": return map.getLobbyName(); + case "seeker": return map.getSeekerLobbyName(); + default: return null; + } + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 53e61df..4dd5fa9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -58,10 +58,6 @@ public class Game { private int gameTimer; private boolean hiderLeft; - public Game(Board board) { - this(Maps.getRandomMap(), board); - } - public Game(Map map, Board board) { this.currentMap = map; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java index 08a5a80..d6eceb2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java @@ -42,7 +42,6 @@ public class DamageHandler implements Listener { } // Makes sure that if there was an attacking player, that the event is allowed for the game if (attacker != null) { - System.out.println(event.getFinalDamage() + " " + player.getDisplayName() + " " + attacker.getDisplayName()); // Cancel if one player is in the game but other isn't if ((board.contains(player) && !board.contains(attacker)) || (!board.contains(player) && board.contains(attacker))) { event.setCancelled(true); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java deleted file mode 100644 index 3b0f1b4..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.util; - -import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.command.location.SetExitLocation; -import net.tylermurphy.hideAndSeek.command.location.SetLobbyLocation; -import net.tylermurphy.hideAndSeek.command.location.SetSeekerLobbyLocation; -import net.tylermurphy.hideAndSeek.command.location.SetSpawnLocation; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Config.permissionsRequired; -import static net.tylermurphy.hideAndSeek.configuration.Localization.LOCAL; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class CommandHandler { - - public static final Map COMMAND_REGISTER = new LinkedHashMap<>(); - - private static void registerCommand(ICommand command) { - if (!COMMAND_REGISTER.containsKey(command.getLabel())) { - COMMAND_REGISTER.put(command.getLabel().toLowerCase(), command); - } - } - - public static void registerCommands() { - registerCommand(new About()); - registerCommand(new Help()); - registerCommand(new Setup()); - registerCommand(new Start()); - registerCommand(new Stop()); - registerCommand(new SetSpawnLocation()); - registerCommand(new SetLobbyLocation()); - registerCommand(new SetSeekerLobbyLocation()); - registerCommand(new SetExitLocation()); - registerCommand(new SetBorder()); - registerCommand(new Reload()); - registerCommand(new SaveMap()); - registerCommand(new SetBounds()); - registerCommand(new Join()); - registerCommand(new Leave()); - registerCommand(new Top()); - registerCommand(new Wins()); - registerCommand(new Debug()); - registerCommand(new AddMap()); - registerCommand(new RemoveMap()); - registerCommand(new ListMaps()); - registerCommand(new SetMap()); - } - - public static boolean handleCommand(CommandSender sender, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); - return true; - } - Player player = (Player) sender; - if (args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) { - if (permissionsRequired && !sender.hasPermission("hideandseek.about")) { - sender.sendMessage(errorPrefix + LOCAL.get("")); - } else { - COMMAND_REGISTER.get("about").execute(player, null); - } - } else { - if (!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) { - sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); - } else if (permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) { - sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); - } else { - - try { - ICommand command = COMMAND_REGISTER.get(args[0].toLowerCase()); - int parameters = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count(); - if(args.length - 1 < parameters) { - sender.sendMessage(errorPrefix + message("ARGUMENT_COUNT")); - return true; - } - command.execute(player,Arrays.copyOfRange(args, 1, args.length)); - } catch (Exception e) { - sender.sendMessage(errorPrefix + "An error has occurred."); - e.printStackTrace(); - } - } - } - return true; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java deleted file mode 100644 index 28154d1..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.util; - -import net.tylermurphy.hideAndSeek.command.ICommand; -import org.bukkit.command.CommandSender; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - -public class TabCompleter { - - public static List handleTabComplete(CommandSender sender, String[] args) { - if (args.length == 1) { - return new ArrayList<>(CommandHandler.COMMAND_REGISTER.keySet()) - .stream() - .filter(handle -> sender.hasPermission("hideandseek."+handle.toLowerCase()) && handle.toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT))) - .collect(Collectors.toList()); - } else if (args.length > 1) { - if (!CommandHandler.COMMAND_REGISTER.containsKey(args[0].toLowerCase())) { - return new ArrayList<>(); - } else { - ICommand command = CommandHandler.COMMAND_REGISTER.get(args[0].toLowerCase()); - String[] usage = command.getUsage().split(" "); - List complete; - if (args.length - 2 < usage.length) { - String parameter = usage[args.length-2]; - String name = parameter.replace("<", "").replace(">", ""); - complete = command.autoComplete(name); - } else { - complete = command.autoComplete(null); - } - if(complete == null) return new ArrayList<>(); - else return complete; - } - } - return null; - } - -} -- cgit v1.2.3-freya From bb254145ed0bb56d0482f6ba34e05cb728a7c8cc Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Wed, 2 Nov 2022 07:18:00 -0400 Subject: 1.7.0 beta 2 --- .../java/net/tylermurphy/hideAndSeek/Main.java | 74 ++++++----- .../net/tylermurphy/hideAndSeek/command/About.java | 54 -------- .../net/tylermurphy/hideAndSeek/command/Debug.java | 130 ------------------- .../tylermurphy/hideAndSeek/command/Reload.java | 21 ++-- .../net/tylermurphy/hideAndSeek/command/Send.java | 67 ++++++++++ .../hideAndSeek/command/SetExitLocation.java | 61 +++++++++ .../net/tylermurphy/hideAndSeek/command/Start.java | 4 +- .../net/tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../net/tylermurphy/hideAndSeek/command/Top.java | 2 +- .../command/location/LocationUtils.java | 53 ++++++++ .../hideAndSeek/command/location/Locations.java | 26 ++++ .../command/location/SetExitLocation.java | 61 --------- .../command/location/SetLobbyLocation.java | 58 --------- .../command/location/SetSeekerLobbyLocation.java | 47 ------- .../command/location/SetSpawnLocation.java | 79 ------------ .../command/location/util/LocationUtils.java | 53 -------- .../command/location/util/Locations.java | 26 ---- .../tylermurphy/hideAndSeek/command/map/Add.java | 54 ++++++++ .../hideAndSeek/command/map/AddMap.java | 54 -------- .../tylermurphy/hideAndSeek/command/map/Debug.java | 130 +++++++++++++++++++ .../tylermurphy/hideAndSeek/command/map/GoTo.java | 63 ++++++++++ .../tylermurphy/hideAndSeek/command/map/List.java | 46 +++++++ .../hideAndSeek/command/map/ListMaps.java | 47 ------- .../hideAndSeek/command/map/Remove.java | 53 ++++++++ .../hideAndSeek/command/map/RemoveMap.java | 53 -------- .../tylermurphy/hideAndSeek/command/map/Save.java | 98 +++++++++++++++ .../hideAndSeek/command/map/SaveMap.java | 97 -------------- .../hideAndSeek/command/map/SetBorder.java | 112 ----------------- .../hideAndSeek/command/map/SetBounds.java | 112 ----------------- .../hideAndSeek/command/map/SetMap.java | 67 ---------- .../tylermurphy/hideAndSeek/command/map/Setup.java | 97 -------------- .../hideAndSeek/command/map/Status.java | 95 ++++++++++++++ .../hideAndSeek/command/map/blockhunt/Enabled.java | 43 +++++++ .../hideAndSeek/command/map/set/Border.java | 112 +++++++++++++++++ .../hideAndSeek/command/map/set/Bounds.java | 112 +++++++++++++++++ .../hideAndSeek/command/map/set/Lobby.java | 58 +++++++++ .../hideAndSeek/command/map/set/SeekerLobby.java | 47 +++++++ .../hideAndSeek/command/map/set/Spawn.java | 79 ++++++++++++ .../hideAndSeek/command/util/CommandGroup.java | 13 +- .../hideAndSeek/configuration/Config.java | 39 ------ .../hideAndSeek/configuration/ConfigManager.java | 139 ++++++++++++++------- .../hideAndSeek/configuration/Leaderboard.java | 51 ++++++++ .../hideAndSeek/configuration/Localization.java | 2 +- .../net/tylermurphy/hideAndSeek/game/Board.java | 13 +- .../tylermurphy/hideAndSeek/game/Disguiser.java | 3 +- .../hideAndSeek/game/listener/ChatHandler.java | 2 +- .../hideAndSeek/game/listener/DisguiseHandler.java | 3 +- .../game/listener/InventoryHandler.java | 4 +- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 4 +- src/main/resources/config.yml | 107 ++++++++-------- src/main/resources/lang/localization_en-US.yml | 19 ++- src/main/resources/leaderboard.yml | 7 +- 52 files changed, 1496 insertions(+), 1357 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/About.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Send.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/About.java') diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index b22af5b..b1e2a83 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -20,15 +20,11 @@ package net.tylermurphy.hideAndSeek; import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.command.location.*; import net.tylermurphy.hideAndSeek.command.map.*; -import net.tylermurphy.hideAndSeek.configuration.Config; -import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.configuration.Localization; -import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.command.map.set.*; +import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.game.*; -import net.tylermurphy.hideAndSeek.game.util.Status; import net.tylermurphy.hideAndSeek.command.util.CommandGroup; import net.tylermurphy.hideAndSeek.game.listener.*; import net.tylermurphy.hideAndSeek.util.PAPIExpansion; @@ -41,7 +37,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import java.io.File; -import java.util.List; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -65,10 +60,17 @@ public class Main extends JavaPlugin implements Listener { Main.instance = this; this.updateVersion(); - Config.loadConfig(); - Maps.loadMaps(); - Localization.loadLocalization(); - Items.loadItems(); + try { + Config.loadConfig(); + Maps.loadMaps(); + Localization.loadLocalization(); + Items.loadItems(); + Leaderboard.loadLeaderboard(); + } catch (Exception e) { + getLogger().severe(e.getMessage()); + Bukkit.getPluginManager().disablePlugin(this); + return; + } this.board = new Board(); this.database = new Database(); @@ -77,28 +79,27 @@ public class Main extends JavaPlugin implements Listener { this.registerListeners(); this.commandGroup = new CommandGroup("hs", - new About(), - new Debug(), new Help(), new Reload(), new Join(), new Leave(), + new Send(), new Start(), new Stop(), new CommandGroup("map", new CommandGroup("set", - new SetLobbyLocation(), - new SetSpawnLocation(), - new SetSeekerLobbyLocation(), - new SetBorder(), - new SetBounds() + new Lobby(), + new Spawn(), + new SeekerLobby(), + new Border(), + new Bounds() ), - new AddMap(), - new RemoveMap(), - new ListMaps(), - new SetMap(), - new Setup(), - new SaveMap() + new Add(), + new Remove(), + new List(), + new Status(), + new Save(), + new Debug() ), new SetExitLocation(), new Top(), @@ -120,20 +121,25 @@ public class Main extends JavaPlugin implements Listener { version = 0; - board.getPlayers().forEach(player -> { - board.removeBoard(player); - PlayerLoader.unloadPlayer(player); - if(!Objects.equals(exitWorld, "")) - player.teleport(exitPosition); - }); + if(board != null) { + board.getPlayers().forEach(player -> { + board.removeBoard(player); + PlayerLoader.unloadPlayer(player); + if (!Objects.equals(exitWorld, "")) + player.teleport(exitPosition); + }); + board.cleanup(); + } + + if(disguiser != null) { + disguiser.cleanUp(); + } Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this); - board.cleanup(); - disguiser.cleanUp(); } private void onTick() { - if(game.getStatus() == Status.ENDED) game = new Game(game.getCurrentMap(), board); + if(game.getStatus() == net.tylermurphy.hideAndSeek.game.util.Status.ENDED) game = new Game(game.getCurrentMap(), board); game.onTick(); disguiser.check(); } @@ -168,7 +174,7 @@ public class Main extends JavaPlugin implements Listener { return commandGroup.handleCommand((Player)sender, "", args); } - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + public java.util.List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { return commandGroup.handleTabComplete(sender, args); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java deleted file mode 100644 index 119888b..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.List; - -public class About extends Command { - - public void execute(Player sender, String[] args) { - sender.sendMessage( - String.format("%s%sHide and Seek %s(%s1.7.0 ALPHA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + - String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + - String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) - ); - } - - public String getLabel() { - return "about"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Get information about the plugin"; - } - - public List autoComplete(String parameter) { - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java deleted file mode 100644 index 2eb0eb9..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java +++ /dev/null @@ -1,130 +0,0 @@ -package net.tylermurphy.hideAndSeek.command; - -import com.cryptomorin.xseries.XMaterial; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.PlayerLoader; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class Debug extends Command { - - private static final Map>> debugMenuFunctions = new HashMap<>(); - - public void execute(Player sender, String[] args) { - net.tylermurphy.hideAndSeek.configuration.Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - Inventory debugMenu = createMenu(map, sender); - sender.openInventory(debugMenu); - } - - private Inventory createMenu(net.tylermurphy.hideAndSeek.configuration.Map map, Player sender){ - Map> functions = new HashMap<>(); - Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu"); - debugMenu.setItem(0, createOption(functions, 0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - Main.getInstance().getBoard().addHider(player); - PlayerLoader.loadHider(player, map); - if(Main.getInstance().getGame().getStatus() != Status.STARTING) - PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); - })); - debugMenu.setItem(1, createOption(functions, 1, XMaterial.GOLDEN_CHESTPLATE.parseMaterial(), "&cBecome a &lSeeker", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - Main.getInstance().getBoard().addSeeker(player); - PlayerLoader.loadSeeker(player, map); - if(Main.getInstance().getGame().getStatus() != Status.STARTING) - PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); - })); - debugMenu.setItem(2, createOption(functions, 2, XMaterial.IRON_CHESTPLATE.parseMaterial(), "&8Become a &lSpectator", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - Main.getInstance().getBoard().addSpectator(player); - PlayerLoader.loadSpectator(player, map); - })); - debugMenu.setItem(3, createOption(functions, 3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> { - Main.getInstance().getBoard().remove(player); - PlayerLoader.unloadPlayer(player); - player.teleport(exitPosition); - })); - debugMenu.setItem(4, createOption(functions, 4, XMaterial.BARRIER.parseMaterial(), "&cDie In Game", 2, player -> { - if((Main.getInstance().getBoard().isSeeker(player) || Main.getInstance().getBoard().isHider(player)) && Main.getInstance().getGame().getStatus() == Status.PLAYING){ - player.setHealth(0.1); - } - })); - debugMenu.setItem(6, createOption(functions, 6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { - if(mapSaveEnabled) { - if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); - } - player.teleport(map.getGameSpawn()); - })); - debugMenu.setItem(7, createOption(functions, 7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { - player.teleport(map.getLobby()); - })); - debugMenu.setItem(8, createOption(functions, 8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> player.teleport(exitPosition))); - debugMenu.setItem(9, createOption(functions, 9, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { - PlayerLoader.openBlockHuntPicker(player, map); - })); - debugMenu.setItem(10, createOption(functions, 10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); - debugMenuFunctions.put(sender, functions); - return debugMenu; - } - - private ItemStack createOption(Map> functions, int slow, Material material, String name, int amount, Consumer callback){ - ItemStack temp = new ItemStack(material, amount); - ItemMeta meta = temp.getItemMeta(); - meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); - temp.setItemMeta(meta); - functions.put(slow, callback); - return temp; - } - - public static void handleOption(Player player, int slotId){ - Main.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { - Consumer callback = debugMenuFunctions.get(player).get(slotId); - if(callback != null) callback.accept(player); - }, 0); - } - - public String getLabel() { - return "debug"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Run debug commands"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 51bc509..9f8392f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -21,10 +21,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Config; -import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.configuration.Localization; -import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.configuration.*; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; @@ -42,10 +39,18 @@ public class Reload extends Command { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - Config.loadConfig(); - Maps.loadMaps(); - Localization.loadLocalization(); - Items.loadItems(); + + try { + Config.loadConfig(); + Maps.loadMaps(); + Localization.loadLocalization(); + Items.loadItems(); + Leaderboard.loadLeaderboard(); + } catch (Exception e) { + sender.sendMessage(errorPrefix + message("CONFIG_ERROR")); + return; + } + sender.sendMessage(messagePrefix + message("CONFIG_RELOAD")); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java new file mode 100644 index 0000000..9978c3c --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java @@ -0,0 +1,67 @@ +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Send extends Command { + + public void execute(Player sender, String[] args) { + + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + + if(map.isNotSetup()){ + sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP")); + return; + } + + if (!Main.getInstance().getBoard().contains(sender)) { + sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); + return; + } + + Main.getInstance().getGame().setCurrentMap(map); + for(Player player : Main.getInstance().getBoard().getPlayers()) { + player.teleport(map.getLobby()); + } + + } + + public String getLabel() { + return "send"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Set the current lobby to another map"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java new file mode 100644 index 0000000..874909b --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -0,0 +1,61 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import org.bukkit.entity.Player; + +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class SetExitLocation extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.EXIT, null, map -> { + addToConfig("exit.x", sender.getLocation().getBlockX()); + addToConfig("exit.y", sender.getLocation().getBlockY()); + addToConfig("exit.z", sender.getLocation().getBlockZ()); + addToConfig("exit.world", sender.getLocation().getWorld().getName()); + exitPosition = sender.getLocation(); + exitWorld = sender.getLocation().getWorld().getName(); + saveConfig(); + }); + } + + public String getLabel() { + return "setexit"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks exit location to current position and world"; + } + + public List autoComplete(String parameter) { + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 54ad4af..674edd6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -57,7 +57,7 @@ public class Start extends Command { if (args.length < 1) { Optional rand = Main.getInstance().getBoard().getPlayers().stream().skip(new Random().nextInt(Main.getInstance().getBoard().size())).findFirst(); if (!rand.isPresent()) { - Main.getInstance().getLogger().warning("Failed to select random seeker."); + sender.sendMessage(errorPrefix + message("START_FAILED_SEEKER")); return; } seekerName = rand.get().getName(); @@ -82,7 +82,7 @@ public class Start extends Command { } public String getUsage() { - return ""; + return "<*player>"; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 1582be9..7c8cabf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -34,7 +34,7 @@ public class Stop extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().checkCurrentMap()) { - sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); + sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } if (Main.getInstance().getGame().getStatus() == Status.STARTING || Main.getInstance().getGame().getStatus() == Status.PLAYING) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 8116eaf..0a5358d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -76,7 +76,7 @@ public class Top extends Command { } public String getUsage() { - return ""; + return "<*page>"; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java new file mode 100644 index 0000000..5e4afb5 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java @@ -0,0 +1,53 @@ +package net.tylermurphy.hideAndSeek.command.location; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +/** + * @author bobby29831 + */ +public class LocationUtils { + + public static void setLocation(@NotNull Player player, @NotNull Locations place, String mapName, @NotNull Consumer consumer) { + + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + player.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + + if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ + player.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + + Map map = null; + if(mapName != null) { + map = Maps.getMap(mapName); + if (map == null) { + player.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + } + + try { + consumer.accept(map); + } catch (Exception e) { + player.sendMessage(errorPrefix + e.getMessage()); + return; + } + + if(map != null) + Maps.setMap(mapName, map); + player.sendMessage(messagePrefix + message(place.message())); + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java new file mode 100644 index 0000000..dd73dac --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java @@ -0,0 +1,26 @@ +package net.tylermurphy.hideAndSeek.command.location; + +/** + * @author bobby29831 + */ +public enum Locations { + + GAME("spawns.game"), + LOBBY("spawns.lobby"), + EXIT("spawns.exit"), + SEEKER("spawns.seeker"); + + private final String path; + Locations(String path) { + this.path = path; + } + + public String message() { + return this + "_SPAWN"; + } + + public String path(String additive) { + return path + "." + additive; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java deleted file mode 100644 index 01e1512..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.location; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; -import org.bukkit.entity.Player; - -import java.util.List; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -public class SetExitLocation extends Command { - - public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.EXIT, null, map -> { - addToConfig("exit.x", sender.getLocation().getBlockX()); - addToConfig("exit.y", sender.getLocation().getBlockY()); - addToConfig("exit.z", sender.getLocation().getBlockZ()); - addToConfig("exit.world", sender.getLocation().getWorld().getName()); - exitPosition = sender.getLocation(); - exitWorld = sender.getLocation().getWorld().getName(); - saveConfig(); - }); - } - - public String getLabel() { - return "setexit"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets hide and seeks exit location to current position and world"; - } - - public List autoComplete(String parameter) { - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java deleted file mode 100644 index da41d91..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.location; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.stream.Collectors; - -public class SetLobbyLocation extends Command { - - public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { - map.setLobby(sender.getLocation()); - }); - } - - public String getLabel() { - return "lobby"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets hide and seeks lobby location to current position"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java deleted file mode 100644 index 8a5ebd1..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.location; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetSeekerLobbyLocation extends Command { - - public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { - if(map.isSpawnNotSetup()) { - throw new RuntimeException(message("GAME_SPAWN_NEEDED").toString()); - } - if(!map.getSpawnName().equals(sender.getLocation().getWorld().getName())) { - throw new RuntimeException(message("SEEKER_LOBBY_INVALID").toString()); - } - map.setSeekerLobby(sender.getLocation()); - }); - } - - public String getLabel() { - return "seekerlobby"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets hide and seeks seeker lobby location to current position"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java deleted file mode 100644 index 82f71d1..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.location; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; -import net.tylermurphy.hideAndSeek.command.location.util.Locations; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetSpawnLocation extends Command { - - public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { - - if (map.isWorldBorderEnabled() && - new Vector(sender.getLocation().getX(), 0, sender.getLocation().getZ()).distance(map.getWorldBorderPos()) > 100) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); - throw new RuntimeException("World border not enabled or not in valid position!"); - } - - map.setSpawn(sender.getLocation()); - - if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().getName().equals(sender.getLocation().getWorld().getName())) { - sender.sendMessage(message("SEEKER_LOBBY_SPAWN_RESET").toString()); - map.setSeekerLobby(new Location(null, 0, 0, 0)); - } - - if (!sender.getLocation().getWorld().getName().equals(map.getSpawnName()) && mapSaveEnabled) { - map.getWorldLoader().unloadMap(); - } - }); - } - - public String getLabel() { - return "spawn"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets hide and seeks spawn location to current position"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java deleted file mode 100644 index 69d7c26..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.location.util; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.function.Consumer; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -/** - * @author bobby29831 - */ -public class LocationUtils { - - public static void setLocation(@NotNull Player player, @NotNull Locations place, String mapName, @NotNull Consumer consumer) { - - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - player.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - - if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ - player.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - - Map map = null; - if(mapName != null) { - map = Maps.getMap(mapName); - if (map == null) { - player.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - } - - try { - consumer.accept(map); - } catch (Exception e) { - player.sendMessage(errorPrefix + e.getMessage()); - return; - } - - if(map != null) - Maps.setMap(mapName, map); - player.sendMessage(messagePrefix + message(place.message())); - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java deleted file mode 100644 index 35f74ea..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.location.util; - -/** - * @author bobby29831 - */ -public enum Locations { - - GAME("spawns.game"), - LOBBY("spawns.lobby"), - EXIT("spawns.exit"), - SEEKER("spawns.seeker"); - - private final String path; - Locations(String path) { - this.path = path; - } - - public String message() { - return this + "_SPAWN"; - } - - public String path(String additive) { - return path + "." + additive; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java new file mode 100644 index 0000000..03c2a95 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java @@ -0,0 +1,54 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Add extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map != null) { + sender.sendMessage(errorPrefix + message("MAP_ALREADY_EXISTS")); + } else if(!args[0].matches("[a-zA-Z0-9]*") || args[0].length() < 1) { + sender.sendMessage(errorPrefix + message("INVALID_MAP_NAME")); + } else { + Maps.setMap(args[0], new Map(args[0])); + sender.sendMessage(messagePrefix + message("MAP_CREATED").addAmount(args[0])); + } + } + + public String getLabel() { + return "add"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Add a map to the plugin!"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("name")) { + return Collections.singletonList("name"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java deleted file mode 100644 index 55b4267..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.Collections; -import java.util.List; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class AddMap extends Command { - - public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map != null) { - sender.sendMessage(errorPrefix + message("MAP_ALREADY_EXISTS")); - } else if(!args[0].matches("[a-zA-Z0-9]*") || args[0].length() < 1) { - sender.sendMessage(errorPrefix + message("INVALID_MAP_NAME")); - } else { - Maps.setMap(args[0], new Map(args[0])); - sender.sendMessage(messagePrefix + message("MAP_CREATED").addAmount(args[0])); - } - } - - public String getLabel() { - return "add"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Add a map to the plugin!"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("name")) { - return Collections.singletonList("name"); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java new file mode 100644 index 0000000..2ec0525 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -0,0 +1,130 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import com.cryptomorin.xseries.XMaterial; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.PlayerLoader; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Debug extends Command { + + private static final Map>> debugMenuFunctions = new HashMap<>(); + + public void execute(Player sender, String[] args) { + net.tylermurphy.hideAndSeek.configuration.Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + Inventory debugMenu = createMenu(map, sender); + sender.openInventory(debugMenu); + } + + private Inventory createMenu(net.tylermurphy.hideAndSeek.configuration.Map map, Player sender){ + Map> functions = new HashMap<>(); + Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu"); + debugMenu.setItem(0, createOption(functions, 0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addHider(player); + PlayerLoader.loadHider(player, map); + if(Main.getInstance().getGame().getStatus() != Status.STARTING) + PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); + })); + debugMenu.setItem(1, createOption(functions, 1, XMaterial.GOLDEN_CHESTPLATE.parseMaterial(), "&cBecome a &lSeeker", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addSeeker(player); + PlayerLoader.loadSeeker(player, map); + if(Main.getInstance().getGame().getStatus() != Status.STARTING) + PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); + })); + debugMenu.setItem(2, createOption(functions, 2, XMaterial.IRON_CHESTPLATE.parseMaterial(), "&8Become a &lSpectator", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addSpectator(player); + PlayerLoader.loadSpectator(player, map); + })); + debugMenu.setItem(3, createOption(functions, 3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> { + Main.getInstance().getBoard().remove(player); + PlayerLoader.unloadPlayer(player); + player.teleport(exitPosition); + })); + debugMenu.setItem(4, createOption(functions, 4, XMaterial.BARRIER.parseMaterial(), "&cDie In Game", 2, player -> { + if((Main.getInstance().getBoard().isSeeker(player) || Main.getInstance().getBoard().isHider(player)) && Main.getInstance().getGame().getStatus() == Status.PLAYING){ + player.setHealth(0.1); + } + })); + debugMenu.setItem(6, createOption(functions, 6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + player.teleport(map.getGameSpawn()); + })); + debugMenu.setItem(7, createOption(functions, 7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { + player.teleport(map.getLobby()); + })); + debugMenu.setItem(8, createOption(functions, 8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> player.teleport(exitPosition))); + debugMenu.setItem(9, createOption(functions, 9, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { + PlayerLoader.openBlockHuntPicker(player, map); + })); + debugMenu.setItem(10, createOption(functions, 10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + debugMenuFunctions.put(sender, functions); + return debugMenu; + } + + private ItemStack createOption(Map> functions, int slow, Material material, String name, int amount, Consumer callback){ + ItemStack temp = new ItemStack(material, amount); + ItemMeta meta = temp.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); + temp.setItemMeta(meta); + functions.put(slow, callback); + return temp; + } + + public static void handleOption(Player player, int slotId){ + Main.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { + Consumer callback = debugMenuFunctions.get(player).get(slotId); + if(callback != null) callback.accept(player); + }, 0); + } + + public String getLabel() { + return "debug"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Run debug commands"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java new file mode 100644 index 0000000..8e74922 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java @@ -0,0 +1,63 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class GoTo extends Command { + + public void execute(Player sender, String[] args) { + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isNotSetup()) { + sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP").addAmount(map.getName())); + return; + } + switch (args[1].toLowerCase()) { + case "spawn": + sender.teleport(map.getSpawn()); break; + case "lobby": + sender.teleport(map.getLobby()); break; + case "seekerlobby": + sender.teleport(map.getSeekerLobby()); break; + case "exit": + sender.teleport(exitPosition); break; + default: + sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1].toLowerCase())); + } + } + + public String getLabel() { + return "goto"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Get the commands for the plugin"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } else if(parameter != null && parameter.equals("spawn")) { + return Arrays.asList("spawn","lobby","seekerlobby","exit"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java new file mode 100644 index 0000000..635c011 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java @@ -0,0 +1,46 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.util.Collection; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class List extends Command { + + public void execute(Player sender, String[] args) { + Collection maps = Maps.getAllMaps(); + if(maps.size() < 1) { + sender.sendMessage(errorPrefix + message("NO_MAPS")); + return; + } + StringBuilder response = new StringBuilder(messagePrefix + message("LIST_MAPS")); + for(Map map : maps) { + response.append("\n ").append(map.getName()).append(": ").append(map.isNotSetup() ? ChatColor.RED + "NOT SETUP" : ChatColor.GREEN + "SETUP").append(ChatColor.WHITE); + } + sender.sendMessage(response.toString()); + } + + public String getLabel() { + return "list"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "List all maps in the plugin"; + } + + public java.util.List autoComplete(String parameter) { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java deleted file mode 100644 index 79490a7..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.Collection; -import java.util.List; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class ListMaps extends Command { - - public void execute(Player sender, String[] args) { - Collection maps = Maps.getAllMaps(); - if(maps.size() < 1) { - sender.sendMessage(errorPrefix + message("NO_MAPS")); - return; - } - StringBuilder response = new StringBuilder(messagePrefix + message("LIST_MAPS")); - for(Map map : maps) { - response.append("\n ").append(map.getName()).append(": ").append(map.isNotSetup() ? ChatColor.RED + "NOT SETUP" : ChatColor.GREEN + "SETUP").append(ChatColor.WHITE); - } - sender.sendMessage(response.toString()); - } - - public String getLabel() { - return "list"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "List all maps in the plugin"; - } - - public List autoComplete(String parameter) { - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java new file mode 100644 index 0000000..45dec99 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java @@ -0,0 +1,53 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Remove extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + } else if(!Maps.removeMap(args[0])){ + sender.sendMessage(errorPrefix + message("MAP_FAIL_DELETE").addAmount(args[0])); + } else { + sender.sendMessage(messagePrefix + message("MAP_DELETED").addAmount(args[0])); + } + } + + public String getLabel() { + return "remove"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Remove a map from the plugin!"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java deleted file mode 100644 index 216cca9..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class RemoveMap extends Command { - - public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - } else if(!Maps.removeMap(args[0])){ - sender.sendMessage(errorPrefix + message("MAP_FAIL_DELETE").addAmount(args[0])); - } else { - sender.sendMessage(messagePrefix + message("MAP_DELETED").addAmount(args[0])); - } - } - - public String getLabel() { - return "remove"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Remove a map from the plugin!"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java new file mode 100644 index 0000000..b93250f --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -0,0 +1,98 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Save extends Command { + + public static boolean runningBackup = false; + + public void execute(Player sender, String[] args) { + if (!mapSaveEnabled) { + sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); + return; + } + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + sender.sendMessage(messagePrefix + message("MAPSAVE_START")); + sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); + World world = map.getSpawn().getWorld(); + if (world == null) { + sender.sendMessage(warningPrefix + message("MAPSAVE_FAIL_WORLD")); + return; + } + world.save(); + BukkitRunnable runnable = new BukkitRunnable() { + public void run() { + sender.sendMessage( + map.getWorldLoader().save() + ); + runningBackup = false; + } + }; + runnable.runTaskAsynchronously(Main.getInstance()); + runningBackup = true; + } + + public String getLabel() { + return "save"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Saves current map for the game. May lag server."; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java deleted file mode 100644 index f3eb4d7..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SaveMap extends Command { - - public static boolean runningBackup = false; - - public void execute(Player sender, String[] args) { - if (!mapSaveEnabled) { - sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); - return; - } - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - sender.sendMessage(messagePrefix + message("MAPSAVE_START")); - sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); - World world = map.getSpawn().getWorld(); - if (world == null) { - throw new RuntimeException("Unable to get spawn world"); - } - world.save(); - BukkitRunnable runnable = new BukkitRunnable() { - public void run() { - sender.sendMessage( - map.getWorldLoader().save() - ); - runningBackup = false; - } - }; - runnable.runTaskAsynchronously(Main.getInstance()); - runningBackup = true; - } - - public String getLabel() { - return "save"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Saves current map for the game. May lag server."; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java deleted file mode 100644 index 8362e02..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetBorder extends Command { - - public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - if (args.length < 4) { - map.setWorldBorderData(0, 0, 0, 0, 0); - addToConfig("worldBorder.enabled",false); - saveConfig(); - sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); - Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); - return; - } - int num,delay,change; - try { num = Integer.parseInt(args[1]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); - return; - } - try { delay = Integer.parseInt(args[2]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); - return; - } - try { change = Integer.parseInt(args[3]); } catch (Exception e) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); - return; - } - if (num < 100) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); - return; - } - if (change < 1) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); - return; - } - map.setWorldBorderData( - sender.getLocation().getBlockX(), - sender.getLocation().getBlockZ(), - num, - delay, - change - ); - Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); - map.getWorldBorder().resetWorldBorder(); - } - - public String getLabel() { - return "border"; - } - - public String getUsage() { - return " <*size> <*delay> <*move>"; - } - - public String getDescription() { - return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return Collections.singletonList(parameter); - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java deleted file mode 100644 index 92bf5a4..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetBounds extends Command { - - public void execute(Player sender, String[] args) { - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.isSpawnNotSetup()) { - sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); - return; - } - if (!sender.getWorld().getName().equals(map.getSpawnName())) { - sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); - return; - } - if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { - sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - boolean first = true; - int bxs = map.getBoundsMin().getBlockX(); - int bzs = map.getBoundsMin().getBlockZ(); - int bxl = map.getBoundsMax().getBlockX(); - int bzl = map.getBoundsMax().getBlockZ(); - if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { - bxs = bzs = bxl = bzl = 0; - } - if (bxl == 0) { - bxl = sender.getLocation().getBlockX(); - } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { - first = false; - bxs = bxl; - bxl = sender.getLocation().getBlockX(); - } else { - first = false; - bxs = sender.getLocation().getBlockX(); - } - if (bzl == 0) { - bzl = sender.getLocation().getBlockZ(); - } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { - first = false; - bzs = bzl; - bzl = sender.getLocation().getBlockZ(); - } else { - first = false; - bzs = sender.getLocation().getBlockZ(); - } - map.setBoundMin(bxs, bzs); - map.setBoundMax(bxl, bzl); - Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); - } - - public String getLabel() { - return "bounds"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets the map bounds for the game."; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java deleted file mode 100644 index 2df5824..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java +++ /dev/null @@ -1,67 +0,0 @@ -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetMap extends Command { - - public void execute(Player sender, String[] args) { - - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - - if(map.isNotSetup()){ - sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP")); - return; - } - - if (!Main.getInstance().getBoard().contains(sender)) { - sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); - return; - } - - Main.getInstance().getGame().setCurrentMap(map); - for(Player player : Main.getInstance().getBoard().getPlayers()) { - player.teleport(map.getLobby()); - } - - } - - public String getLabel() { - return "goto"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Set the current lobby to another map"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java deleted file mode 100644 index 46b41f7..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of Kenshins Hide and Seek - * - * Copyright (c) 2021 Tyler Murphy. - * - * Kenshins Hide and Seek free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * he Free Software Foundation version 3. - * - * Kenshins Hide and Seek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package net.tylermurphy.hideAndSeek.command.map; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.util.Command; -import net.tylermurphy.hideAndSeek.configuration.Map; -import net.tylermurphy.hideAndSeek.configuration.Maps; -import org.bukkit.entity.Player; - -import java.io.File; -import java.util.List; -import java.util.stream.Collectors; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class Setup extends Command { - - public void execute(Player sender, String[] args) { - - String msg = message("SETUP").toString(); - int count = 0; - Map map = Maps.getMap(args[0]); - if(map == null) { - sender.sendMessage(errorPrefix + message("INVALID_MAP")); - return; - } - if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { - msg = msg + "\n" + message("SETUP_GAME"); - count++; - } - if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { - msg = msg + "\n" + message("SETUP_LOBBY"); - count++; - } - if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !Map.worldExists(map.getSeekerLobbyName())) { - msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); - count++; - } - if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld)) { - msg = msg + "\n" + message("SETUP_EXIT"); - count++; - } - if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || - map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { - msg = msg + "\n" + message("SETUP_BOUNDS"); - count++; - } - if (mapSaveEnabled && !Map.worldExists(map.getGameSpawnName())) { - msg = msg + "\n" + message("SETUP_SAVEMAP"); - count++; - } - if (count < 1) { - sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); - } else { - sender.sendMessage(msg); - } - } - - public String getLabel() { - return "setup"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Shows what needs to be setup"; - } - - public List autoComplete(String parameter) { - if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); - } - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java new file mode 100644 index 0000000..29442c1 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -0,0 +1,95 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Status extends Command { + + public void execute(Player sender, String[] args) { + + String msg = message("SETUP").toString(); + int count = 0; + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + msg = msg + "\n" + message("SETUP_GAME"); + count++; + } + if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !Map.worldExists(map.getLobbyName())) { + msg = msg + "\n" + message("SETUP_LOBBY"); + count++; + } + if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !Map.worldExists(map.getSeekerLobbyName())) { + msg = msg + "\n" + message("SETUP_SEEKER_LOBBY"); + count++; + } + if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !Map.worldExists(exitWorld)) { + msg = msg + "\n" + message("SETUP_EXIT"); + count++; + } + if (map.getBoundsMin().getBlockX() == 0 || map.getBoundsMin().getBlockZ() == 0 || + map.getBoundsMax().getBlockX() == 0 || map.getBoundsMax().getBlockX() == 0) { + msg = msg + "\n" + message("SETUP_BOUNDS"); + count++; + } + if (mapSaveEnabled && !Map.worldExists(map.getGameSpawnName())) { + msg = msg + "\n" + message("SETUP_SAVEMAP"); + count++; + } + if (count < 1) { + sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); + } else { + sender.sendMessage(msg); + } + } + + public String getLabel() { + return "status"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Shows what needs to be setup"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java new file mode 100644 index 0000000..9d47390 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -0,0 +1,43 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt; + +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class Enabled extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "enabled"; + } + + public String getUsage() { + return " "; + } + + public String getDescription() { + return "Sets hide and seeks lobby location to current position"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + if(parameter != null && parameter.equals("bool")) { + return Arrays.asList("true", "false"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java new file mode 100644 index 0000000..92339b4 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java @@ -0,0 +1,112 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Border extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + if (args.length < 4) { + map.setWorldBorderData(0, 0, 0, 0, 0); + addToConfig("worldBorder.enabled",false); + saveConfig(); + sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); + Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); + return; + } + int num,delay,change; + try { num = Integer.parseInt(args[1]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + try { delay = Integer.parseInt(args[2]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); + return; + } + try { change = Integer.parseInt(args[3]); } catch (Exception e) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); + return; + } + if (num < 100) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); + return; + } + if (change < 1) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE")); + return; + } + map.setWorldBorderData( + sender.getLocation().getBlockX(), + sender.getLocation().getBlockZ(), + num, + delay, + change + ); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay).addAmount(change)); + map.getWorldBorder().resetWorldBorder(); + } + + public String getLabel() { + return "border"; + } + + public String getUsage() { + return " <*size> <*delay> <*move>"; + } + + public String getDescription() { + return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable."; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return Collections.singletonList(parameter); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java new file mode 100644 index 0000000..9896389 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java @@ -0,0 +1,112 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Bounds extends Command { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + if (map.isSpawnNotSetup()) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + if (!sender.getWorld().getName().equals(map.getSpawnName())) { + sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); + return; + } + if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { + sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + boolean first = true; + int bxs = map.getBoundsMin().getBlockX(); + int bzs = map.getBoundsMin().getBlockZ(); + int bxl = map.getBoundsMax().getBlockX(); + int bzl = map.getBoundsMax().getBlockZ(); + if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { + bxs = bzs = bxl = bzl = 0; + } + if (bxl == 0) { + bxl = sender.getLocation().getBlockX(); + } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { + first = false; + bxs = bxl; + bxl = sender.getLocation().getBlockX(); + } else { + first = false; + bxs = sender.getLocation().getBlockX(); + } + if (bzl == 0) { + bzl = sender.getLocation().getBlockZ(); + } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { + first = false; + bzs = bzl; + bzl = sender.getLocation().getBlockZ(); + } else { + first = false; + bzs = sender.getLocation().getBlockZ(); + } + map.setBoundMin(bxs, bzs); + map.setBoundMax(bxl, bzl); + Maps.setMap(map.getName(), map); + sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); + } + + public String getLabel() { + return "bounds"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets the map bounds for the game."; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java new file mode 100644 index 0000000..c691787 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java @@ -0,0 +1,58 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +public class Lobby extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "lobby"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks lobby location to current position"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java new file mode 100644 index 0000000..2521f19 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java @@ -0,0 +1,47 @@ +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SeekerLobby extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { + if(map.isSpawnNotSetup()) { + throw new RuntimeException(message("GAME_SPAWN_NEEDED").toString()); + } + if(!map.getSpawnName().equals(sender.getLocation().getWorld().getName())) { + throw new RuntimeException(message("SEEKER_LOBBY_INVALID").toString()); + } + map.setSeekerLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "seekerlobby"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks seeker lobby location to current position"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java new file mode 100644 index 0000000..3e8f77e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java @@ -0,0 +1,79 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Spawn extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { + + if (map.isWorldBorderEnabled() && + new Vector(sender.getLocation().getX(), 0, sender.getLocation().getZ()).distance(map.getWorldBorderPos()) > 100) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); + throw new RuntimeException("World border not enabled or not in valid position!"); + } + + map.setSpawn(sender.getLocation()); + + if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().getName().equals(sender.getLocation().getWorld().getName())) { + sender.sendMessage(message("SEEKER_LOBBY_SPAWN_RESET").toString()); + map.setSeekerLobby(new Location(null, 0, 0, 0)); + } + + if (!sender.getLocation().getWorld().getName().equals(map.getSpawnName()) && mapSaveEnabled) { + map.getWorldLoader().unloadMap(); + } + }); + } + + public String getLabel() { + return "spawn"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks spawn location to current position"; + } + + public List autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index 9079ccc..e7f43eb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -20,7 +20,8 @@ package net.tylermurphy.hideAndSeek.command.util; import net.tylermurphy.hideAndSeek.command.*; -import net.tylermurphy.hideAndSeek.command.map.SaveMap; +import net.tylermurphy.hideAndSeek.command.map.Save; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -38,7 +39,7 @@ public class CommandGroup { public CommandGroup(String label, Object... data) { this.label = label; - this.commandRegister = new HashMap<>(); + this.commandRegister = new LinkedHashMap<>(); for(Object o : data) registerCommand(o); } @@ -65,11 +66,15 @@ public class CommandGroup { if (permissionsRequired && !player.hasPermission("hs.about")) { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); } else { - new About().execute(player, null); + player.sendMessage( + String.format("%s%sHide and Seek %s(%s1.7.0 ALPHA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) + ); } } else { String invoke = args[0].toLowerCase(); - if (!invoke.equals("about") && !invoke.equals("help") && SaveMap.runningBackup) { + if (!invoke.equals("about") && !invoke.equals("help") && Save.runningBackup) { player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); } else if (permissionsRequired && !player.hasPermission(permission+"."+invoke)) { player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 3a43e15..0000c30 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -101,7 +101,6 @@ public class Config { lobbyItemStartPosition, flightToggleItemPosition, teleportItemPosition, - solidifyTime, delayedRespawnDelay; public static float @@ -113,24 +112,6 @@ public class Config { blockedCommands, blockedInteracts; - public static String - LOBBY_TITLE, - GAME_TITLE, - COUNTDOWN_WAITING, - COUNTDOWN_COUNTING, - COUNTDOWN_ADMINSTART, - TAUNT_COUNTING, - TAUNT_ACTIVE, - TAUNT_EXPIRED, - GLOW_ACTIVE, - GLOW_INACTIVE, - BORDER_COUNTING, - BORDER_DECREASING; - - public static List - LOBBY_CONTENTS, - GAME_CONTENTS; - public static ItemStack lobbyLeaveItem, lobbyStartItem, @@ -152,7 +133,6 @@ public class Config { config = ConfigManager.create("config.yml"); config.saveConfig(); - ConfigManager leaderboard = ConfigManager.create("leaderboard.yml"); announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers"); @@ -247,25 +227,6 @@ public class Config { } bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy"); leaveServer = config.getString("leaveServer"); - solidifyTime = Math.max(20,config.getInt("blockhunt.solidifyTime")); - - //Leaderboard - LOBBY_TITLE = leaderboard.getString("lobby.title"); - GAME_TITLE = leaderboard.getString("game.title"); - LOBBY_CONTENTS = leaderboard.getStringList("lobby.content"); - Collections.reverse(LOBBY_CONTENTS); - GAME_CONTENTS = leaderboard.getStringList("game.content"); - Collections.reverse(GAME_CONTENTS); - COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting"); - COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting"); - COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart"); - TAUNT_COUNTING = leaderboard.getString("taunt.counting"); - TAUNT_ACTIVE = leaderboard.getString("taunt.active"); - TAUNT_EXPIRED = leaderboard.getString("taunt.expired"); - GLOW_ACTIVE = leaderboard.getString("glow.active"); - GLOW_INACTIVE = leaderboard.getString("glow.inactive"); - BORDER_COUNTING = leaderboard.getString("border.counting"); - BORDER_DECREASING = leaderboard.getString("border.decreasing"); //Lobby Items if (config.getBoolean("lobbyItems.leave.enabled")) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index e09001e..b7671c2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -93,6 +93,7 @@ public class ConfigManager { try { this.config.load(reader); } catch(InvalidConfigurationException e) { + Main.getInstance().getLogger().severe(e.getMessage()); throw new RuntimeException("Invalid configuration in config file: "+file.getPath()); } catch(IOException e) { throw new RuntimeException("Could not access file: "+file.getPath()); @@ -107,9 +108,10 @@ public class ConfigManager { try { this.defaultConfig.load(default_reader); } catch(InvalidConfigurationException e) { - throw new RuntimeException("Invalid configuration in config file: "+file.getPath()); + Main.getInstance().getLogger().severe(e.getMessage()); + throw new RuntimeException("Invalid configuration in internal config file: "+defaultFilename); } catch(IOException e) { - throw new RuntimeException("Could not access file: "+file.getPath()); + throw new RuntimeException("Could not access internal file: "+defaultFilename); } try{ @@ -240,69 +242,110 @@ public class ConfigManager { public void saveConfig() { try { + // open config file InputStream is = Main.getInstance().getResource(defaultFilename); + // if failed error if (is == null) { throw new RuntimeException("Could not create input stream for "+defaultFilename); } + // manually read in each character to preserve string data StringBuilder textBuilder = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); Reader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); int c; - while((c = reader.read()) != -1) { + while((c = reader.read()) != -1) textBuilder.append((char) c); - } - String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8); - Map temp = config.getValues(true); - for(Map.Entry entry: temp.entrySet()) { - if (entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List) { - String[] parts = entry.getKey().split("\\."); - int index = 0; - int i = 0; - for(String part : parts) { - if (i == 0) { - index = yamlString.indexOf(part+":", index); - } else { - index = yamlString.indexOf(" " + part+":", index); - index++; - } - i++; - if (index == -1) break; - } - if (index < 10) continue; - int start = yamlString.indexOf(' ', index); - int end = yamlString.indexOf('\n', index); - if (end == -1) end = yamlString.length(); - StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); - if (entry.getValue() instanceof List) { - if (((List) entry.getValue()).isEmpty()) { - replace.append("[]"); - } else { - replace.append("["); - for (Object o : (List) entry.getValue()) { - replace.append(o.toString()).append(", "); - } - replace = new StringBuilder(replace.substring(0, replace.length() - 2)); - replace.append("]"); - } + // store yaml file into a string + String yaml = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8); + // get config values + Map data = config.getValues(true); + // write each stored config value into the yaml string + for(Map.Entry entry: data.entrySet()) { + // if type isn't supported, skip + if(!isSupported(entry.getValue())) continue; + // get index of key in yaml string + int index = getIndex(yaml, entry.getKey()); + // if index not found, skip + if (index < 10) continue; + // get start and end of the value + int start = yaml.indexOf(' ', index) + 1; + int end = yaml.indexOf('\n', index); + // if end not found, set it to the end of the file + if (end == -1) end = yaml.length(); + // create new replace sting + StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8)); + // get value + Object value = entry.getValue(); + // if the value is a list, + if (value instanceof List) { + end = yaml.indexOf(']', start) + 1; + List list = (List) entry.getValue(); + if (list.isEmpty()) { + // if list is empty, put an empty list + replace.append("[]"); } else { - replace.append(entry.getValue()); - } - if (entry.getValue() instanceof String) { - replace.append("\""); - replace.reverse(); - replace.append("\""); - replace.reverse(); + // if list has values, populate values into the string + // get gap before key + int gap = whitespaceBefore(yaml, index); + String space = new String(new char[gap]).replace('\0', ' '); + replace.append("[\n"); + for (int i = 0; i < list.size(); i++) { + replace.append(space).append(" ").append(convert(list.get(i))); + if(i != list.size() -1) replace.append(",\n"); + } + replace.append('\n').append(space).append("]"); } - StringBuilder builder = new StringBuilder(yamlString); - builder.replace(start+1, end, replace.toString()); - yamlString = builder.toString(); + // otherwise just put the value directly + } else { + replace.append(convert(value)); } + // replace the new value in the yaml string + StringBuilder builder = new StringBuilder(yaml); + builder.replace(start, end, replace.toString()); + yaml = builder.toString(); } + + // write yaml string to file Writer fileWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8)); - fileWriter.write(yamlString); + fileWriter.write(yaml); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } } + private int getIndex(String yaml, String key) { + String[] parts = key.split("\\."); + int index = 0; + for(String part : parts) { + if (index == 0) { + index = yaml.indexOf(part + ":", index); + } else { + index = yaml.indexOf(" " + part + ":", index) + 1; + } + if (index == -1) break; + } + return index; + } + + public boolean isSupported(Object o) { + return o instanceof Integer || + o instanceof Double || + o instanceof String || + o instanceof Boolean || + o instanceof List; + } + + public int whitespaceBefore(String yaml, int index) { + int count = 0; + for(int i = index - 1; yaml.charAt(i) == ' '; i--) count++; + return count; + } + + private String convert(Object o) { + if(o instanceof String) { + return "\"" + o + "\""; + } + return o.toString(); + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java new file mode 100644 index 0000000..63dc850 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Leaderboard.java @@ -0,0 +1,51 @@ +package net.tylermurphy.hideAndSeek.configuration; + +import java.util.Collections; +import java.util.List; + +public class Leaderboard { + + public static String + LOBBY_TITLE, + GAME_TITLE, + COUNTDOWN_WAITING, + COUNTDOWN_COUNTING, + COUNTDOWN_ADMINSTART, + TAUNT_COUNTING, + TAUNT_ACTIVE, + TAUNT_EXPIRED, + GLOW_ACTIVE, + GLOW_INACTIVE, + BORDER_COUNTING, + BORDER_DECREASING; + + public static List + LOBBY_CONTENTS, + GAME_CONTENTS; + + public static void loadLeaderboard() { + + ConfigManager leaderboard = ConfigManager.create("leaderboard.yml"); + + LOBBY_TITLE = leaderboard.getString("lobby.title"); + GAME_TITLE = leaderboard.getString("game.title"); + LOBBY_CONTENTS = leaderboard.getStringList("lobby.content"); + Collections.reverse(LOBBY_CONTENTS); + GAME_CONTENTS = leaderboard.getStringList("game.content"); + Collections.reverse(GAME_CONTENTS); + COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting"); + COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting"); + COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart"); + TAUNT_COUNTING = leaderboard.getString("taunt.counting"); + TAUNT_ACTIVE = leaderboard.getString("taunt.active"); + TAUNT_EXPIRED = leaderboard.getString("taunt.expired"); + GLOW_ACTIVE = leaderboard.getString("glow.active"); + GLOW_INACTIVE = leaderboard.getString("glow.inactive"); + BORDER_COUNTING = leaderboard.getString("border.counting"); + BORDER_DECREASING = leaderboard.getString("border.decreasing"); + + leaderboard.saveConfig(); + + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 9418414..72ab366 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -31,7 +31,7 @@ public class Localization { public static final Map DEFAULT_LOCAL = new HashMap<>(); private static final Map CHANGES = new HashMap() {{ - put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"}}); + put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"},{"GAME_SETUP"}}); put("de-DE", new String[][]{{},{"TAUNTED"}}); }}; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 18cad40..83fc2a6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -33,6 +33,7 @@ import java.util.*; import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Leaderboard.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Board { @@ -218,7 +219,9 @@ public class Board { } else if (line.contains("{SEEKER%}")) { board.setLine(String.valueOf(i), line.replace("{SEEKER%}", getSeekerPercent()+"")); } else if (line.contains("{HIDER%}")) { - board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent()+"")); + board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent() + "")); + } else if (line.contains("{MAP}")) { + board.setLine(String.valueOf(i), line.replace("{MAP}", getMapName() + "")); } else { board.setLine(String.valueOf(i), line); } @@ -228,6 +231,12 @@ public class Board { customBoards.put(player.getUniqueId().toString(), board); } + public String getMapName() { + net.tylermurphy.hideAndSeek.configuration.Map map = Main.getInstance().getGame().getCurrentMap(); + if(map == null) return "Invalid"; + else return map.getName(); + } + public void createGameBoard(Player player) { createGameBoard(player, true); } @@ -288,6 +297,8 @@ public class Board { board.setLine(String.valueOf(i), line.replace("{#SEEKER}", getSeekers().size()+"")); } else if (line.contains("{#HIDER}")) { board.setLine(String.valueOf(i), line.replace("{#HIDER}", getHiders().size()+"")); + } else if (line.contains("{MAP}")) { + board.setLine(String.valueOf(i), line.replace("{MAP}", getMapName() + "")); } else { board.setLine(String.valueOf(i), line); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java index dabb735..5fce7d3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java @@ -1,6 +1,7 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.game.util.Disguise; @@ -49,7 +50,7 @@ public class Disguiser { public void disguise(Player player, Material material, Map map){ if(!map.isBlockHuntEnabled()){ - player.sendMessage(errorPrefix + "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8"); + player.sendMessage(errorPrefix + message("BLOCKHUNT_DISABLED")); return; } if(disguises.containsKey(player)){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java index 27a6235..27347c2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/ChatHandler.java @@ -11,7 +11,7 @@ public class ChatHandler implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onChat(AsyncPlayerChatEvent event) { - if (Main.getInstance().getBoard().isSeeker(event.getPlayer())) { + if (Main.getInstance().getBoard().isSpectator(event.getPlayer())) { event.setCancelled(true); Main.getInstance().getBoard().getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage())); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java index cb8ad04..c80e83f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DisguiseHandler.java @@ -1,7 +1,6 @@ package net.tylermurphy.hideAndSeek.game.listener; import static com.comphenix.protocol.PacketType.Play.Client.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.solidifyTime; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; @@ -42,7 +41,7 @@ public class DisguiseHandler implements Listener { if(lastLocation.getWorld() != currentLocation.getWorld()) return; double distance = lastLocation.distance(currentLocation); disguise.setSolidify(distance < .1); - }, solidifyTime); + }, 20 * 3); if(event.getFrom().distance(event.getTo()) > .1) disguise.setSolidify(false); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java index 2439b2b..af915e2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/InventoryHandler.java @@ -19,11 +19,9 @@ package net.tylermurphy.hideAndSeek.game.listener; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - import com.cryptomorin.xseries.XMaterial; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.Debug; +import net.tylermurphy.hideAndSeek.command.map.Debug; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 322519a..d4deafe 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -75,7 +75,7 @@ public class WorldLoader { public String save() { World world = Bukkit.getServer().getWorld(map.getSpawnName()); if(world == null){ - return errorPrefix + "Invalid world to save: " + map.getSpawnName(); + return errorPrefix + message("MAPSAVE_INVALID").addAmount(map.getSpawnName()); } File current = new File(Main.getInstance().getWorldContainer()+File.separator+ map.getSpawnName()); if (current.exists()) { @@ -94,7 +94,7 @@ public class WorldLoader { } if (!temp_destination.renameTo(destination)) { - return errorPrefix + "Failed to rename directory: " + temp_destination.getPath(); + return errorPrefix + message("MAPSAVE_FAIL_DIR").addAmount(temp_destination.getPath()); } } catch(IOException e) { e.printStackTrace(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6463898..389352a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -15,23 +15,23 @@ gameLength: 1200 announceMessagesToNonPlayers: true # When the game is starting, the plugin will state there is x seconds left to hide. -# You change where countdown messages to be displayed: in the chat, action bar, or a title. +# You change where countdown messages are to be displayed: in the chat, action bar, or a title. # Below you can set CHAT, ACTIONBAR, or TITLE. Any invalid option will revert to CHAT. # -# CHAT - Messages will be displayed in the chat +# CHAT - Staring messages will be displayed in the chat # -# ACTIONBAR - Messages will be displayed in the action bar (area above the hotbar) +# ACTIONBAR - Staring messages will be displayed in the action bar (area above the hotbar) # -# TITLE - Messages will be displayed as a title +# TITLE - Staring messages will be displayed as a title # # default: CHAT -hideCountdownDisplay: CHAT +hideCountdownDisplay: "CHAT" # Allow Hiders to see their own teams nametags as well as seekers. Seekers can never see nametags regardless. # default: false nametagsVisible: false -# Require bukkit permissions though a plugin to run commands, recommended on large servers +# Require bukkit permissions though a permissions plugin to run commands, or require op, recommended on most servers # default: true permissionsRequired: true @@ -80,11 +80,11 @@ leaveOnEnd: false # PROXY - Send the player to a specified server in a bungee-cord / velocity setup. # # default: EXIT -leaveType: EXIT +leaveType: "EXIT" # Ignore this setting if you aren't using the PROXY leave type method above. If you are, set this to the server you want to send # players too. -leaveServer: hub +leaveServer: "hub" # By default, the plugin forces you to use a map save to protect from changes to a map thought a game play though. It copies your # hide-and-seek world to a separate world, and loads the game there to contain the game in an isolated and backed up map This allows you to @@ -117,40 +117,16 @@ delayedRespawn: # MYSQL - Uses a mysql server to store data, good for multi-server setups or large servers. # # default: SQLITE -databaseType: SQLITE +databaseType: "SQLITE" # The following settings are used for MYSQL databases ONLY. If you are running SQLITE, these # will be ignored. If you are running MYSQL, you need to provide the database host url, database # host port (usually 3306), database username, and database password. -databaseHost: localhost +databaseHost: "localhost" databasePort: 3306 -databaseUser: root -databasePass: -databaseName: hideandseek - -# The world border closes every interval, which is evey [delay] in minutes. -# Thw world border starts at [size], and decreases 100 blocks every interval. -# x & z are the center location. [enabled] is whenever the border is enabled. -# You can choose if Hiders are warned 30 seconds before the border moves. - -# You want block hunt? We have block hunt! Just enable it below, and set the -# available blocks to pick from, and you're all set! It's that easy! -# Items are displayed in the order that they are listed below. -# The solidifyTime is the time in server ticks that it takes players to solidify. -# Every 20 ticks is a second. Minimum solidifyTime is 20 ticks. -blockhunt: - enabled: false - solidifyTime: 60 - blocks: [CRAFTING_TABLE, GRASS_BLOCK, DIRT, BEACON, BOOKSHELF] - -worldBorder: - x: 0 - z: 0 - delay: 10 - size: 500 - moveAmount: 100 - warn: true - enabled: false +databaseUser: "root" +databasePass: "pass" +databaseName: "hideandseek" # The taunt will activate every delay set in seconds. It will spawn a firework # on a random Hider to alert a Seeker where someone may be. You can choose @@ -173,8 +149,12 @@ glow: stackable: true enabled: true name: "Glow Powerup" - lore: [ "Throw to make all seekers glow", "Last 30s, all hiders can see it", "Time stacks on multi use" ] - material: SNOWBALL + lore: [ + "Throw to make all seekers glow", + "Last 30s, all hiders can see it", + "Time stacks on multi use" + ] + material: "SNOWBALL" model-data: 0 # This has the same glow effect as the glow powerup in that all seekers positions get @@ -221,14 +201,16 @@ lobby: # If you set adminOnly to false, only the item will become non admin only, not the command. lobbyItems: leave: - material: BED + material: "BED" name: "&cLeave Lobby" - lore: ["Go back to server hub"] + lore: [ + "Go back to server hub" + ] position: 8 model-data: 0 enabled: true start: - material: CLOCK + material: "CLOCK" name: "&bStart Game" lore: [] position: 0 @@ -241,15 +223,19 @@ lobbyItems: # and position of the item. You can also change the model data if your server is running 1.14 or above. spectatorItems: flight: - material: FEATHER + material: "FEATHER" name: "&bToggle Flight" - lore: [ "Turns flying on and off" ] + lore: [ + "Turns flying on and off" + ] position: 3 model-data: 0 teleport: - material: COMPASS + material: "COMPASS" name: "&bTeleport to Others" - lore: [ "Allows you to teleport to all other players in game" ] + lore: [ + "Allows you to teleport to all other players in game" + ] position: 5 model-data: 0 @@ -265,8 +251,8 @@ seekerPing: leadingVolume: 0.5 volume: 0.3 pitch: 1 - heartbeatNoise: BLOCK_NOTE_BLOCK_BASEDRUM - ringingNoise: BLOCK_NOTE_BLOCK_PLING + heartbeatNoise: "BLOCK_NOTE_BLOCK_BASEDRUM" + ringingNoise: "BLOCK_NOTE_BLOCK_PLING" enabled: true # Changes the default plugin language. Currently, Supported localizations are: @@ -275,26 +261,37 @@ seekerPing: locale: "en-US" # Stop commands being run by any user while playing the game. -# Can be usefull If you aren't using a permission plugin and want +# Can be usefull If you aren't using a permission plugin and don't want # to op people, but still want to block certain commands. # Not really usefully if using permission plugins. # You can add /kill for any use, but it's already blocked on those # playing the game. -blockedCommands: [msg, tp, gamemode, kill, give, effect] +blockedCommands: [ + "msg", + "tp", + "gamemode", + "kill", + "give", + "effect" +] # Stop interactions with any block by any user while playing the game. # If your map has things such as chests for aesthetic only, you can # block the use of clicking them. It shouldn't matter what version of # the block ID you enter, as the plugin will automatically switch to the # block ID of your current Minecraft server version. -blockedInteracts: [FURNACE, CRAFTING_TABLE, ANVIL, CHEST, BARREL] -# ---------------------------------------------------------- # -# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # -# ---------------------------------------------------------- # +blockedInteracts: [ + "FURNACE", + "CRAFTING_TABLE", + "ANVIL", + "CHEST", + "BARREL" +] # Location where players are teleported when they exit (/hs leave) +# Auto filled by /hs setexit, so you don't need to touch this here exit: x: 0 y: 0 z: 0 - world: world \ No newline at end of file + world: "world" \ No newline at end of file diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 91d7abe..53f86be 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -10,6 +10,7 @@ Localization: COMMAND_PLAYER_ONLY: "This command can only be run as a player." COMMAND_NOT_ALLOWED: "You are not allowed to run this command." COMMAND_ERROR: "An internal error has occurred." + COMMAND_INVALID_ARG: "Invalid argument: {AMOUNT}" GAME_PLAYER_DEATH: "&c{PLAYER}&f was killed." GAME_PLAYER_FOUND: "&e{PLAYER}&f was found and became a seeker." GAME_PLAYER_FOUND_BY: "&e{PLAYER}&f was found by &c{PLAYER}&f and became a seeker." @@ -17,7 +18,7 @@ Localization: GAME_GAMEOVER_SEEKERS_QUIT: "All seekers have quit." GAME_GAMEOVER_HIDERS_QUIT: "All hiders have quit." GAME_GAMEOVER_TIME: "Seekers ran out of time. Hiders win!" - GAME_SETUP: "There are no setup maps! Run /hs setup on a map to see what you need to do." + GAME_SETUP: "There are no setup maps! Run /hs map status on a map to see what you need to do." GAME_INGAME: "You are already in the lobby/game." GAME_NOT_INGAME: "You are not in a lobby/game." GAME_INPROGRESS: "There is currently a game in progress." @@ -32,6 +33,9 @@ Localization: MAPSAVE_END: "Map save complete." MAPSAVE_ERROR: "Couldn't find current map." MAPSAVE_DISABLED: "Mapsave is disabled in config.yml." + MAPSAVE_FAIL_WORLD: "Mapsave failed. Failed to load current world." + MAPSAVE_INVALID: "Invalid world to save: {AMOUNT}" + MAPSAVE_FAIL_DIR: "Failed to rename directory: {AMOUNT}" WORLDBORDER_DISABLE: "Disabled world border." WORLDBORDER_INVALID_INPUT: "Invalid integer {AMOUNT}." WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks." @@ -58,6 +62,7 @@ Localization: SEEKER_SPAWN: "Set seeker lobby position to current location" START_MIN_PLAYERS: "You must have at least {AMOUNT} players to start." START_INVALID_NAME: "Invalid player: {PLAYER}." + START_FAILED_SEEKER: "Failed to select random seeker." START_COUNTDOWN: "Hiders have {AMOUNT} seconds to hide!" START_COUNTDOWN_LAST: "Hiders have {AMOUNT} second to hide!" START: "Attention SEEKERS, its time to find the hiders!" @@ -77,9 +82,9 @@ Localization: FLYING_ENABLED: "&l&bFlying Enabled" FLYING_DISABLED: "&l&bFlying Disabled" RESPAWN_NOTICE: "You will respawn in {AMOUNT} seconds." - INVALID_MAP: "That is an invalid map name!!" + INVALID_MAP: "That is an invalid map name!" MAP_ALREADY_EXISTS: "This map already exists!" - INVALID_MAP_NAME: "A map name can only contain numbers or letters" + INVALID_MAP_NAME: "A map name can only contain numbers or letters." MAP_CREATED: "Created new map: {AMOUNT}" MAP_FAIL_DELETE: "Failed to delete map: {AMOUNT}" MAP_DELETED: "Deleted map: {AMOUNT}" @@ -88,9 +93,11 @@ Localization: LIST_MAPS: "The current maps are:" ARGUMENT_COUNT: "This command requires more arguments to run." GAME_SPAWN_NEEDED: "Game spawn must be set before seeker spawn." - SEEKER_LOBBY_SPAWN_RESET: "Seeker lobby spawn reset since the game spawn was moved to a new world" - SEEKER_LOBBY_INVALID: "Seeker lobby must be in the same world as game spawn" + SEEKER_LOBBY_SPAWN_RESET: "Seeker lobby spawn reset since the game spawn was moved to a new world." + SEEKER_LOBBY_INVALID: "Seeker lobby must be in the same world as game spawn." + CONFIG_ERROR: "Error reloading config. Check server logs." + BLOCKHUNT_DISABLED: "Please enable blockhunt in this map inside maps.yml to enable disguises. Blockhunt does not work on 1.8" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE -version: 3 +version: 4 type: "en-US" \ No newline at end of file diff --git a/src/main/resources/leaderboard.yml b/src/main/resources/leaderboard.yml index 9c7a777..cd958a3 100644 --- a/src/main/resources/leaderboard.yml +++ b/src/main/resources/leaderboard.yml @@ -16,6 +16,7 @@ # {COUNT} - The amount of player currently in the lobby. # {SEEKER%} - The chance that a player will be selected to be a seeker. # {HIDER%} - The chance that a player will be selected to be a hider. +# {MAP} - The current map the player is on # # GAME BOARD PLACEHOLDERS # @@ -38,6 +39,7 @@ # only Hiders will be able to see its effects though. # {#SEEKER} - Number of current seekers. # {#HIDER} - Number of current hiders. +# {MAP} - The current map the player is on # # YOU CANNOT USE TWO PLACEHOLDERS ON THE SAME LINE. ONLY THE FIRST ONE WILL # BE CHANGED, AND THE SECOND ONE WILL SAY A PLACEHOLDER MARKER! @@ -50,12 +52,15 @@ lobby: "Players: {COUNT}", "", "&cSEEKER % &f{SEEKER%}", - "&6HIDER % &f{HIDER%}" + "&6HIDER % &f{HIDER%}", + "", + "Map: {MAP}", ] game: title: "&eHIDE AND SEEK" content: [ + "Map: {MAP}", "Team: {TEAM}", "", "Time Left: &a{TIME}", -- cgit v1.2.3-freya