From 1617bfe44ab2fc2112ee5cc6fa082b7981222c64 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 26 Dec 2021 16:58:18 -0600 Subject: 1.3.3 beta 3 --- .../net/tylermurphy/hideAndSeek/command/About.java | 2 +- .../net/tylermurphy/hideAndSeek/command/Help.java | 10 ++--- .../tylermurphy/hideAndSeek/command/ICommand.java | 10 ++--- .../net/tylermurphy/hideAndSeek/command/Join.java | 28 +++++++------- .../net/tylermurphy/hideAndSeek/command/Leave.java | 24 ++++++------ .../tylermurphy/hideAndSeek/command/Reload.java | 6 +-- .../tylermurphy/hideAndSeek/command/SaveMap.java | 14 +++++-- .../tylermurphy/hideAndSeek/command/SetBorder.java | 11 +++--- .../tylermurphy/hideAndSeek/command/SetBounds.java | 6 +-- .../hideAndSeek/command/SetExitLocation.java | 16 ++++---- .../hideAndSeek/command/SetLobbyLocation.java | 16 ++++---- .../hideAndSeek/command/SetSpawnLocation.java | 22 +++++++---- .../net/tylermurphy/hideAndSeek/command/Setup.java | 10 ++--- .../net/tylermurphy/hideAndSeek/command/Start.java | 43 ++++++++-------------- .../net/tylermurphy/hideAndSeek/command/Stop.java | 15 ++++---- .../net/tylermurphy/hideAndSeek/command/Top.java | 13 ++++--- .../net/tylermurphy/hideAndSeek/command/Wins.java | 15 +++++--- 17 files changed, 135 insertions(+), 126 deletions(-) (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command') diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 6256f69..9286922 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -7,7 +7,7 @@ public class About implements ICommand { public void execute(CommandSender sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(1.3.3%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(%s1.3.3%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 0c6b253..c09545c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -3,17 +3,17 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.util.CommandHandler; +import net.tylermurphy.hideAndSeek.game.CommandHandler; public class Help implements ICommand { public void execute(CommandSender sender, String[] args) { - String message = ""; + StringBuilder message = new StringBuilder(); for(ICommand command : CommandHandler.COMMAND_REGISTER.values()) { - message += 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.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 = message.substring(0, message.length()-1); - sender.sendMessage(message); + 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 index 928787e..91d1298 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java @@ -4,12 +4,12 @@ import org.bukkit.command.CommandSender; public interface ICommand { - public void execute(CommandSender sender, String[] args); + void execute(CommandSender sender, String[] args); - public String getLabel(); - - public String getUsage(); + String getLabel(); + + String getUsage(); - public String getDescription(); + String getDescription(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 31660b2..7a305f6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -2,7 +2,9 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import net.tylermurphy.hideAndSeek.game.Status; +import net.tylermurphy.hideAndSeek.game.Board; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -10,14 +12,14 @@ import org.bukkit.attribute.Attribute; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Util; +import java.util.Objects; + import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class Join implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -26,7 +28,7 @@ public class Join implements ICommand { sender.sendMessage(errorPrefix + message("COMMAND_ERROR")); return; } - if(Main.plugin.board.isPlayer(player)){ + if(Board.isPlayer(player)){ sender.sendMessage(errorPrefix + message("GAME_INGAME")); return; } @@ -35,25 +37,25 @@ public class Join implements ICommand { } public static void join(Player player){ - if(Main.plugin.status == Status.STANDBY) { + if(Game.status == Status.STANDBY) { player.getInventory().clear(); - Main.plugin.board.addHider(player); + Board.addHider(player); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); - else Util.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); + else Game.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); player.setGameMode(GameMode.ADVENTURE); - Main.plugin.board.createLobbyBoard(player); - Main.plugin.board.reloadLobbyBoards(); + Board.createLobbyBoard(player); + Board.reloadLobbyBoards(); } else { - Main.plugin.board.addSpectator(player); + Board.addSpectator(player); player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); player.setGameMode(GameMode.SPECTATOR); - Main.plugin.board.createGameBoard(player); + Board.createGameBoard(player); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); } player.setFoodLevel(20); - player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue()); + player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue()); } 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 1568a9b..6c65714 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -2,20 +2,20 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import net.tylermurphy.hideAndSeek.game.Status; +import net.tylermurphy.hideAndSeek.game.Board; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class Leave implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } @@ -24,20 +24,20 @@ public class Leave implements ICommand { sender.sendMessage(errorPrefix + message("COMMAND_ERROR")); return; } - if(!Main.plugin.board.isPlayer(player)) { + if(!Board.isPlayer(player)) { sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); return; } if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); - else Util.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); - Main.plugin.board.removeBoard(player); - Main.plugin.board.remove(player); + else Game.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); + Board.removeBoard(player); + Board.remove(player); player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); - if(Main.plugin.status == Status.STANDBY) { - Main.plugin.board.reloadLobbyBoards(); + if(Game.status == Status.STANDBY) { + Board.reloadLobbyBoards(); } else { - Main.plugin.board.reloadGameBoards(); - Main.plugin.board.reloadBoardTeams(); + Board.reloadGameBoards(); + Board.reloadBoardTeams(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index dffbb10..3cc92a4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -3,10 +3,10 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.game.Status; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; -import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Localization; @@ -16,7 +16,7 @@ public class Reload implements ICommand { public void execute(CommandSender sender, String[] args) { - if(Main.plugin.status != Status.STANDBY) { + if(Game.status != 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 2e8b4f8..1ce2aa4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -2,8 +2,10 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import net.tylermurphy.hideAndSeek.game.Status; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; @@ -15,7 +17,7 @@ public class SaveMap implements ICommand { public static boolean runningBackup = false; public void execute(CommandSender sender, String[] args) { - if(Main.plugin.status != Status.STANDBY) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -25,11 +27,15 @@ public class SaveMap implements ICommand { } sender.sendMessage(messagePrefix + message("MAPSAVE_START")); sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); - Bukkit.getServer().getWorld(spawnWorld).save(); + World world = Bukkit.getServer().getWorld(spawnWorld); + if(world == null){ + throw new RuntimeException("Unable to get world: " + spawnWorld); + } + world.save(); BukkitRunnable runnable = new BukkitRunnable() { public void run() { sender.sendMessage( - Main.plugin.worldLoader.save() + Game.worldLoader.save() ); runningBackup = false; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index f7fb8e9..c510335 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -2,19 +2,18 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import net.tylermurphy.hideAndSeek.game.Status; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.events.Worldborder; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetBorder implements ICommand { public void execute(CommandSender sender, String[] args) { - if(Main.plugin.status != Status.STANDBY) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -27,7 +26,7 @@ public class SetBorder implements ICommand { addToConfig("worldBorder.enabled",false); saveConfig(); sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); - Worldborder.resetWorldborder(spawnWorld); + Game.resetWorldborder(spawnWorld); return; } int num,delay; @@ -63,7 +62,7 @@ public class SetBorder implements ICommand { addToConfig("worldBorder.enabled", true); sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); saveConfig(); - Worldborder.resetWorldborder(spawnWorld); + Game.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 bbf099d..ca21908 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -2,17 +2,17 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import net.tylermurphy.hideAndSeek.game.Status; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.tylermurphy.hideAndSeek.Main; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetBounds implements ICommand { public void execute(CommandSender sender, String[] args) { - if(Main.plugin.status != Status.STANDBY) { + if(Game.status != 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 index ea0144d..8938939 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -2,21 +2,19 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.HashMap; -import java.util.Map; - -import net.tylermurphy.hideAndSeek.game.Status; +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 net.tylermurphy.hideAndSeek.Main; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetExitLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(Main.plugin.status != Status.STANDBY) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -29,7 +27,11 @@ public class SetExitLocation implements ICommand { newExitPosition.setX(player.getLocation().getBlockX()); newExitPosition.setY(player.getLocation().getBlockY()); newExitPosition.setZ(player.getLocation().getBlockZ()); - exitWorld = player.getLocation().getWorld().getName(); + 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()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index 4002bee..df5d512 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -2,21 +2,19 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.HashMap; -import java.util.Map; - -import net.tylermurphy.hideAndSeek.game.Status; +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 net.tylermurphy.hideAndSeek.Main; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetLobbyLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(Main.plugin.status != Status.STANDBY) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -29,7 +27,11 @@ public class SetLobbyLocation implements ICommand { newLobbyPosition.setX(player.getLocation().getBlockX()); newLobbyPosition.setY(player.getLocation().getBlockY()); newLobbyPosition.setZ(player.getLocation().getBlockZ()); - lobbyWorld = player.getLocation().getWorld().getName(); + 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()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index c854b60..eb03625 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -2,23 +2,21 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.HashMap; -import java.util.Map; - -import net.tylermurphy.hideAndSeek.game.Status; +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 net.tylermurphy.hideAndSeek.Main; - import static net.tylermurphy.hideAndSeek.configuration.Config.addToConfig; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetSpawnLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(Main.plugin.status != Status.STANDBY) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -35,7 +33,15 @@ public class SetSpawnLocation implements ICommand { sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); return; } - spawnWorld = player.getLocation().getWorld().getName(); + World world = player.getLocation().getWorld(); + if(world == null){ + throw new RuntimeException("Unable to get world: " + spawnWorld); + } + if(!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()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index f47503a..5cde727 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -17,24 +17,24 @@ public class Setup implements ICommand { int count = 0; if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_GAME").toString(); + msg = msg + "\n" + message("SETUP_GAME"); count++; } if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_LOBBY").toString(); + msg = msg + "\n" + message("SETUP_LOBBY"); count++; } if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) { - msg = msg + "\n" + message("SETUP_EXIT").toString(); + msg = msg + "\n" + message("SETUP_EXIT"); count++; } if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) { - msg = msg + "\n" + message("SETUP_BOUNDS").toString(); + msg = msg + "\n" + message("SETUP_BOUNDS"); count++; } File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); if(!destenation.exists()) { - msg = msg + "\n" + message("SETUP_SAVEMAP").toString(); + msg = msg + "\n" + message("SETUP_SAVEMAP"); count++; } if(count < 1) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 31f04d1..4abda2b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -1,66 +1,55 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; -import net.tylermurphy.hideAndSeek.game.Status; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import net.tylermurphy.hideAndSeek.game.Board; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; -import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.events.Glow; -import net.tylermurphy.hideAndSeek.events.Taunt; -import net.tylermurphy.hideAndSeek.events.Worldborder; -import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.ArrayList; -import java.util.List; +import java.util.Optional; import java.util.Random; public class Start implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } - if(Main.plugin.status != Status.STANDBY) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - if(!Main.plugin.board.isPlayer(sender)) { + if(!Board.isPlayer(sender)) { sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); return; } - if(Main.plugin.board.size() < minPlayers) { + if(Board.size() < minPlayers) { sender.sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers)); return; } String seekerName; if(args.length < 1) { - seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName(); + Optional rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst(); + if(!rand.isPresent()){ + Main.plugin.getLogger().warning("Failed to select random seeker."); + return; + } + seekerName = rand.get().getName(); } else { seekerName = args[0]; } - Player seeker = Main.plugin.board.getPlayer(seekerName); + Player seeker = Board.getPlayer(seekerName); if(seeker == null) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; } - Main.plugin.game.start(seeker); + Game.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 2fef77c..0a81793 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -2,26 +2,25 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import net.tylermurphy.hideAndSeek.game.Status; -import net.tylermurphy.hideAndSeek.game.WinType; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.util.WinType; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class Stop implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } - if(Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING) { + if(Game.status == Status.STARTING || Game.status == Status.PLAYING) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP")); - else Util.broadcastMessage(abortPrefix + message("STOP")); - Main.plugin.game.stop(WinType.NONE); + else Game.broadcastMessage(abortPrefix + message("STOP")); + Game.stop(WinType.NONE); } 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 c394378..8ac71fc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -1,6 +1,7 @@ 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; @@ -25,10 +26,10 @@ public class Top implements ICommand { sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(page)); return; } - String message = String.format( + StringBuilder message = new StringBuilder(String.format( "%s------- %sLEADERBOARD %s(Page %s) %s-------\n", - ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE); - List infos = Main.plugin.database.playerInfo.getInfoPage(page); + ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE)); + List infos = Database.playerInfo.getInfoPage(page); int i = 1 + (page-1)*10; for(PlayerInfo info : infos){ String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName(); @@ -39,11 +40,11 @@ public class Top implements ICommand { case 3: color = ChatColor.GOLD; break; default: color = ChatColor.WHITE; break; } - message = message + String.format("%s%s. %s%s %s%s\n", - color, i, ChatColor.RED, info.wins, ChatColor.WHITE, name); + message.append(String.format("%s%s. %s%s %s%s\n", + color, i, ChatColor.RED, info.wins, ChatColor.WHITE, name)); i++; } - sender.sendMessage(message); + sender.sendMessage(message.toString()); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index d99229d..20d1e64 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -1,14 +1,12 @@ package net.tylermurphy.hideAndSeek.command; -import com.comphenix.protocol.PacketType; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.database.PlayerInfo; -import net.tylermurphy.hideAndSeek.util.CommandHandler; import net.tylermurphy.hideAndSeek.util.UUIDFetcher; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.util.UUID; @@ -23,7 +21,12 @@ public class Wins implements ICommand { UUID uuid; String name; if(args.length == 0) { - uuid = Main.plugin.getServer().getPlayer(sender.getName()).getUniqueId(); + Player player = Main.plugin.getServer().getPlayer(sender.getName()); + if(player == null){ + sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(sender.getName())); + return; + } + uuid = player.getUniqueId(); name = sender.getName(); } else { @@ -35,7 +38,7 @@ public class Wins implements ICommand { return; } } - PlayerInfo info = Main.plugin.database.playerInfo.getInfo(uuid); + PlayerInfo info = Database.playerInfo.getInfo(uuid); if(info == null){ sender.sendMessage(errorPrefix + message("NO_GAME_INFO")); return; -- cgit v1.2.3-freya