diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command')
20 files changed, 303 insertions, 286 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index d773e60..11b0b0a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -20,7 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.game.CommandHandler; +import net.tylermurphy.hideAndSeek.util.CommandHandler; import org.bukkit.command.CommandSender; public class Help implements ICommand { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 446fb2d..eb8fd82 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -19,8 +19,7 @@ package net.tylermurphy.hideAndSeek.command; -import net.tylermurphy.hideAndSeek.game.Board; -import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.Main; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,7 +30,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Join implements ICommand { public void execute(CommandSender sender, String[] args) { - if (Game.isNotSetup()) { + if (Main.getInstance().getGame().isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -40,12 +39,12 @@ public class Join implements ICommand { sender.sendMessage(errorPrefix + message("COMMAND_ERROR")); return; } - if (Board.contains(player)) { + if (Main.getInstance().getBoard().contains(player)) { sender.sendMessage(errorPrefix + message("GAME_INGAME")); return; } - Game.join(player); + Main.getInstance().getGame().join(player); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index f508498..0b895b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -19,8 +19,7 @@ package net.tylermurphy.hideAndSeek.command; -import net.tylermurphy.hideAndSeek.game.Board; -import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.Main; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,7 +30,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Leave implements ICommand { public void execute(CommandSender sender, String[] args) { - if (Game.isNotSetup()) { + if (Main.getInstance().getGame().isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -40,11 +39,11 @@ public class Leave implements ICommand { sender.sendMessage(errorPrefix + message("COMMAND_ERROR")); return; } - if (!Board.contains(player)) { + if (!Main.getInstance().getBoard().contains(player)) { sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); return; } - Game.leave(player); + Main.getInstance().getGame().leave(player); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index d2ed069..0f959f2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -19,11 +19,11 @@ package net.tylermurphy.hideAndSeek.command; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Localization; -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.command.CommandSender; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; @@ -34,7 +34,7 @@ public class Reload implements ICommand { public void execute(CommandSender sender, String[] args) { - if (Game.status != Status.STANDBY) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index 83f2580..e69c882 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -20,8 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -39,7 +38,7 @@ public class SaveMap implements ICommand { sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); return; } - if (Game.status != Status.STANDBY) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -57,12 +56,12 @@ public class SaveMap implements ICommand { BukkitRunnable runnable = new BukkitRunnable() { public void run() { sender.sendMessage( - Game.worldLoader.save() + Main.getInstance().getGame().getWorldLoader().save() ); runningBackup = false; } }; - runnable.runTaskAsynchronously(Main.plugin); + runnable.runTaskAsynchronously(Main.getInstance()); runningBackup = true; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index e049a8e..8114838 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -19,8 +19,8 @@ package net.tylermurphy.hideAndSeek.command; -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -31,7 +31,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetBorder implements ICommand { public void execute(CommandSender sender, String[] args) { - if (Game.status != Status.STANDBY) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -44,7 +44,7 @@ public class SetBorder implements ICommand { addToConfig("worldBorder.enabled",false); saveConfig(); sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); - Game.resetWorldBorder(spawnWorld); + Main.getInstance().getGame().getBorder().resetWorldBorder(spawnWorld); return; } int num,delay,change; @@ -90,7 +90,7 @@ public class SetBorder implements ICommand { addToConfig("worldBorder.move", worldborderChange); sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); saveConfig(); - Game.resetWorldBorder(spawnWorld); + Main.getInstance().getGame().getBorder().resetWorldBorder(spawnWorld); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index 719d675..7d2da96 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -19,8 +19,8 @@ package net.tylermurphy.hideAndSeek.command; -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -30,7 +30,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetBounds implements ICommand { public void execute(CommandSender sender, String[] args) { - if (Game.status != Status.STANDBY) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java deleted file mode 100644 index de33b93..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ /dev/null @@ -1,74 +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 <http://www.gnu.org/licenses/>. - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetExitLocation implements ICommand { - - public void execute(CommandSender sender, String[] args) { - if (Game.status != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Vector newExitPosition = new Vector(); - Player player = (Player) sender; - if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0) { - sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - newExitPosition.setX(player.getLocation().getBlockX()); - newExitPosition.setY(player.getLocation().getBlockY()); - newExitPosition.setZ(player.getLocation().getBlockZ()); - World world = player.getLocation().getWorld(); - if (world == null) { - throw new RuntimeException("Unable to get world: " + spawnWorld); - } - exitWorld = world.getName(); - exitPosition = newExitPosition; - sender.sendMessage(messagePrefix + message("EXIT_SPAWN")); - addToConfig("spawns.exit.x", exitPosition.getX()); - addToConfig("spawns.exit.y", exitPosition.getY()); - addToConfig("spawns.exit.z", exitPosition.getZ()); - addToConfig("spawns.exit.world", player.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"; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java deleted file mode 100644 index a9351fd..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ /dev/null @@ -1,74 +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 <http://www.gnu.org/licenses/>. - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetLobbyLocation implements ICommand { - - public void execute(CommandSender sender, String[] args) { - if (Game.status != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Vector newLobbyPosition = new Vector(); - Player player = (Player) sender; - if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0) { - sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - newLobbyPosition.setX(player.getLocation().getBlockX()); - newLobbyPosition.setY(player.getLocation().getBlockY()); - newLobbyPosition.setZ(player.getLocation().getBlockZ()); - World world = player.getLocation().getWorld(); - if (world == null) { - throw new RuntimeException("Unable to get world: " + spawnWorld); - } - lobbyWorld = world.getName(); - lobbyPosition = newLobbyPosition; - sender.sendMessage(messagePrefix + message("LOBBY_SPAWN")); - addToConfig("spawns.lobby.x", lobbyPosition.getX()); - addToConfig("spawns.lobby.y", lobbyPosition.getY()); - addToConfig("spawns.lobby.z", lobbyPosition.getZ()); - addToConfig("spawns.lobby.world", player.getLocation().getWorld().getName()); - saveConfig(); - } - - public String getLabel() { - return "setlobby"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets hide and seeks lobby location to current position"; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java deleted file mode 100644 index 6a9b572..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ /dev/null @@ -1,83 +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 <http://www.gnu.org/licenses/>. - * - */ - -package net.tylermurphy.hideAndSeek.command; - -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; -import net.tylermurphy.hideAndSeek.world.WorldLoader; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import static net.tylermurphy.hideAndSeek.configuration.Localization.message; - -public class SetSpawnLocation implements ICommand { - - public void execute(CommandSender sender, String[] args) { - if (Game.status != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Vector newSpawnPosition = new Vector(); - Player player = (Player) sender; - if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0) { - sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return; - } - newSpawnPosition.setX(player.getLocation().getBlockX()); - newSpawnPosition.setY(player.getLocation().getBlockY()); - newSpawnPosition.setZ(player.getLocation().getBlockZ()); - if (worldborderEnabled && newSpawnPosition.distance(worldborderPosition) > 100) { - sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); - return; - } - World world = player.getLocation().getWorld(); - if (world == null) { - throw new RuntimeException("Unable to get world: " + spawnWorld); - } - if (mapSaveEnabled && !world.getName().equals(spawnWorld)) { - Game.worldLoader.unloadMap(); - Game.worldLoader = new WorldLoader(world.getName()); - } - spawnWorld = world.getName(); - spawnPosition = newSpawnPosition; - sender.sendMessage(messagePrefix + message("GAME_SPAWN")); - addToConfig("spawns.game.x", spawnPosition.getX()); - addToConfig("spawns.game.y", spawnPosition.getY()); - addToConfig("spawns.game.z", spawnPosition.getZ()); - addToConfig("spawns.game.world", player.getLocation().getWorld().getName()); - saveConfig(); - } - - public String getLabel() { - return "setspawn"; - } - - public String getUsage() { - return ""; - } - - public String getDescription() { - return "Sets hide and seeks spawn location to current position"; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index ec932d8..0bedcb5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -20,7 +20,6 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.game.Game; import org.bukkit.command.CommandSender; import java.io.File; @@ -52,7 +51,7 @@ public class Setup implements ICommand { count++; } if (mapSaveEnabled) { - File destenation = new File(Main.root + File.separator + Game.getGameWorld()); + File destenation = new File(Main.getInstance().getWorldContainer() + File.separator + Main.getInstance().getGame().getGameWorld()); if (!destenation.exists()) { msg = msg + "\n" + message("SETUP_SAVEMAP"); count++; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 78f9a64..b1e5895 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -20,9 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.game.Board; -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -37,27 +35,27 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Start implements ICommand { public void execute(CommandSender sender, String[] args) { - if (Game.isNotSetup()) { + if (Main.getInstance().getGame().isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } - if (Game.status != Status.STANDBY) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - if (!Board.contains(sender)) { + if (!Main.getInstance().getBoard().contains(sender)) { sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); return; } - if (Board.size() < minPlayers) { + if (Main.getInstance().getBoard().size() < minPlayers) { sender.sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers)); return; } String seekerName; if (args.length < 1) { - Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst(); + Optional<Player> rand = Main.getInstance().getBoard().getPlayers().stream().skip(new Random().nextInt(Main.getInstance().getBoard().size())).findFirst(); if (!rand.isPresent()) { - Main.plugin.getLogger().warning("Failed to select random seeker."); + Main.getInstance().getLogger().warning("Failed to select random seeker."); return; } seekerName = rand.get().getName(); @@ -69,12 +67,12 @@ public class Start implements ICommand { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; } - Player seeker = Board.getPlayer(temp.getUniqueId()); + Player seeker = Main.getInstance().getBoard().getPlayer(temp.getUniqueId()); if (seeker == null) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; } - Game.start(seeker); + Main.getInstance().getGame().start(seeker); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 2a310e8..b5f0c17 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -19,8 +19,8 @@ package net.tylermurphy.hideAndSeek.command; -import net.tylermurphy.hideAndSeek.game.Game; -import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.command.CommandSender; import static net.tylermurphy.hideAndSeek.configuration.Config.abortPrefix; @@ -30,13 +30,13 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Stop implements ICommand { public void execute(CommandSender sender, String[] args) { - if (Game.isNotSetup()) { + if (Main.getInstance().getGame().isNotSetup()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } - if (Game.status == Status.STARTING || Game.status == Status.PLAYING) { - Game.broadcastMessage(abortPrefix + message("STOP")); - Game.end(); + if (Main.getInstance().getGame().getStatus() == Status.STARTING || Main.getInstance().getGame().getStatus() == Status.PLAYING) { + Main.getInstance().getGame().broadcastMessage(abortPrefix + message("STOP")); + Main.getInstance().getGame().end(); } else { sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS")); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 916656d..31f814c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -20,7 +20,6 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.database.PlayerInfo; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -48,14 +47,14 @@ public class Top implements ICommand { StringBuilder message = new StringBuilder(String.format( "%s------- %sLEADERBOARD %s(Page %s) %s-------\n", ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE)); - List<PlayerInfo> infos = Database.playerInfo.getInfoPage(page); + List<PlayerInfo> infos = Main.getInstance().getDatabase().getGameData().getInfoPage(page); int i = 1 + (page-1)*10; if (infos == null) { sender.sendMessage(errorPrefix + message("NO_GAME_INFO")); return; } for(PlayerInfo info : infos) { - String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName(); + String name = Main.getInstance().getServer().getOfflinePlayer(info.uuid).getName(); ChatColor color; switch (i) { case 1: color = ChatColor.YELLOW; break; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index 1366f07..0c0f5eb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -20,9 +20,7 @@ package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.database.PlayerInfo; -import net.tylermurphy.hideAndSeek.util.UUIDFetcher; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -35,12 +33,12 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Wins implements ICommand { public void execute(CommandSender sender, String[] args) { - Main.plugin.getServer().getScheduler().runTaskAsynchronously(Main.plugin, () -> { + Main.getInstance().getServer().getScheduler().runTaskAsynchronously(Main.getInstance(), () -> { UUID uuid; String name; if (args.length == 0) { - Player player = Main.plugin.getServer().getPlayer(sender.getName()); + Player player = Main.getInstance().getServer().getPlayer(sender.getName()); if (player == null) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(sender.getName())); return; @@ -51,13 +49,13 @@ public class Wins implements ICommand { else { try { name = args[0]; - uuid = UUIDFetcher.getUUID(args[0]); + uuid = Main.getInstance().getServer().getOfflinePlayer(args[0]).getUniqueId(); } catch (Exception e) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0])); return; } } - PlayerInfo info = Database.playerInfo.getInfo(uuid); + PlayerInfo info = Main.getInstance().getDatabase().getGameData().getInfo(uuid); if (info == null) { sender.sendMessage(errorPrefix + message("NO_GAME_INFO")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java new file mode 100644 index 0000000..abe6f69 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -0,0 +1,53 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + * + */ + +package net.tylermurphy.hideAndSeek.command.location; + +import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class SetExitLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) return; + Player player = (Player) sender; + + LocationUtils.setLocation(player, Locations.EXIT, vector -> { + exitWorld = player.getLocation().getWorld().getName(); + exitPosition = vector; + }); + } + + public String getLabel() { + return "setexit"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks exit location to current position and world"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java new file mode 100644 index 0000000..fab7076 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -0,0 +1,54 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + * + */ + +package net.tylermurphy.hideAndSeek.command.location; + +import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class SetLobbyLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) return; + Player player = (Player) sender; + + LocationUtils.setLocation(player, Locations.LOBBY, vector -> { + lobbyWorld = player.getLocation().getWorld().getName(); + lobbyPosition = vector; + }); + } + + public String getLabel() { + return "setlobby"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks lobby location to current position"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java new file mode 100644 index 0000000..d96252d --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -0,0 +1,66 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + * + */ + +package net.tylermurphy.hideAndSeek.command.location; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.ICommand; +import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.util.Locations; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SetSpawnLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) return; + Player player = (Player) sender; + + LocationUtils.setLocation(player, Locations.GAME, vector -> { + if (worldborderEnabled && vector.distance(worldborderPosition) > 100) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); + throw new RuntimeException("World border not enabled or not in valid position!"); + } + + if (!player.getLocation().getWorld().getName().equals(spawnWorld)) { + Main.getInstance().getGame().getWorldLoader().unloadMap(); + Main.getInstance().getGame().getWorldLoader().setNewMap(player.getLocation().getWorld().getName()); + } + + spawnWorld = player.getLocation().getWorld().getName(); + spawnPosition = vector; + }); + } + + public String getLabel() { + return "setspawn"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks spawn location to current position"; + } + +} 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 new file mode 100644 index 0000000..e0fc033 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java @@ -0,0 +1,57 @@ +package net.tylermurphy.hideAndSeek.command.location.util; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Consumer; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class LocationUtils { + + /** + * Provides a vector for a player + * @param player the player to create the vector for + * @return the vector + */ + private static @Nullable Vector vector(Player player) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + player.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return null; + } + + if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ + player.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return null; + } + + Location loc = player.getLocation(); + return new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + } + + public static void setLocation(Player player, Locations place, @Nullable Consumer<Vector> consumer) { + Vector vec = vector(player); + + World world = player.getLocation().getWorld(); + if(world == null) { + throw new RuntimeException("Unable to get world: " + spawnWorld); + } + + consumer.accept(vec); + + player.sendMessage(messagePrefix + message(place.message())); + addToConfig(place.path("x"), vec.getX()); + addToConfig(place.path("y"), vec.getY()); + addToConfig(place.path("z"), vec.getZ()); + addToConfig(place.path("world"), player.getLocation().getWorld().getName()); + saveConfig(); + } + +}
\ 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 new file mode 100644 index 0000000..bde5456 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java @@ -0,0 +1,27 @@ +package net.tylermurphy.hideAndSeek.command.location.util; + +public enum Locations { + + GAME("spawns.game", "GAME_SPAWN"), + LOBBY("spawns.lobby", "LOBBY_SPAWN"), + EXIT("spawns.exit", "EXIT_SPAWN"); + + private final String path, message; + Locations(String path, String message) { + this.path = path; + this.message = message; + } + + public String message() { + return message; + } + + public String path() { + return path; + } + + public String path(String additive) { + return path + "." + additive; + } + +}
\ No newline at end of file |