From 6239acb08a43d6bfef51f6abc8b7cc65687c51c7 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 25 Dec 2021 08:16:03 -0600 Subject: [PATCH] 1.3.3 beta 2 --- pom.xml | 10 +- .../net/tylermurphy/hideAndSeek/Main.java | 38 ++- .../tylermurphy/hideAndSeek/bukkit/Tick.java | 85 ------- .../tylermurphy/hideAndSeek/command/Help.java | 2 +- .../tylermurphy/hideAndSeek/command/Join.java | 3 +- .../hideAndSeek/command/Leave.java | 3 +- .../hideAndSeek/command/Reload.java | 3 +- .../hideAndSeek/command/SaveMap.java | 3 +- .../hideAndSeek/command/SetBorder.java | 6 +- .../hideAndSeek/command/SetBounds.java | 3 +- .../hideAndSeek/command/SetExitLocation.java | 3 +- .../hideAndSeek/command/SetLobbyLocation.java | 3 +- .../hideAndSeek/command/SetSpawnLocation.java | 3 +- .../hideAndSeek/command/Start.java | 80 +----- .../tylermurphy/hideAndSeek/command/Stop.java | 38 +-- .../hideAndSeek/configuration/Config.java | 18 +- .../configuration/Localization.java | 2 +- .../tylermurphy/hideAndSeek/events/Glow.java | 4 +- .../tylermurphy/hideAndSeek/events/Taunt.java | 4 +- .../hideAndSeek/events/Worldborder.java | 2 +- .../{bukkit => game}/EventListener.java | 12 +- .../tylermurphy/hideAndSeek/game/Game.java | 227 ++++++++++++++++++ .../tylermurphy/hideAndSeek/game/Status.java | 7 + .../tylermurphy/hideAndSeek/util/Board.java | 64 ++--- .../{bukkit => util}/CommandHandler.java | 2 +- .../{bukkit => util}/TabCompleter.java | 2 +- .../tylermurphy/hideAndSeek/util/Util.java | 2 +- src/main/resources/config.yml | 16 +- 28 files changed, 351 insertions(+), 294 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java rename src/main/java/net/tylermurphy/hideAndSeek/{bukkit => game}/EventListener.java (95%) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/game/Game.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/game/Status.java rename src/main/java/net/tylermurphy/hideAndSeek/{bukkit => util}/CommandHandler.java (98%) rename src/main/java/net/tylermurphy/hideAndSeek/{bukkit => util}/TabCompleter.java (96%) diff --git a/pom.xml b/pom.xml index 544d3bb..be5659b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 net.tylermurphy - HideAndSeek - 1.3.2 + KenshinsHideAndSeek + 1.3.3 Hide and Seek Plugin @@ -39,5 +39,11 @@ ProtocolLib 4.7.0 + + org.jetbrains + annotations + RELEASE + compile + \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index f92bf15..3aa456b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -16,45 +17,33 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -import net.tylermurphy.hideAndSeek.bukkit.CommandHandler; -import net.tylermurphy.hideAndSeek.bukkit.EventListener; -import net.tylermurphy.hideAndSeek.bukkit.TabCompleter; -import net.tylermurphy.hideAndSeek.bukkit.Tick; +import net.tylermurphy.hideAndSeek.util.CommandHandler; +import net.tylermurphy.hideAndSeek.game.EventListener; +import net.tylermurphy.hideAndSeek.util.TabCompleter; +import net.tylermurphy.hideAndSeek.game.Game; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.events.Glow; -import net.tylermurphy.hideAndSeek.events.Taunt; -import net.tylermurphy.hideAndSeek.events.Worldborder; import net.tylermurphy.hideAndSeek.util.Board; import net.tylermurphy.hideAndSeek.world.WorldLoader; +import org.jetbrains.annotations.NotNull; public class Main extends JavaPlugin implements Listener { public static Main plugin; public static File root, data; - public Taunt taunt; - public Glow glow; - public Worldborder worldborder; - + public Game game; public Board board; - public WorldLoader worldLoader; - - public Map playerList = new HashMap(); - - public String status = "Standby"; - - public int timeLeft = 0, gameId = 0;; - + public Status status = Status.STANDBY; private BukkitTask onTickTask; - + public void onEnable() { plugin = this; - // Setup Initial Player Count + // Setup Event Listener getServer().getPluginManager().registerEvents(new EventListener(), this); // Get Data Folder @@ -79,7 +68,8 @@ public class Main extends JavaPlugin implements Listener { // Start Tick Timer onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> { try{ - Tick.onTick(); + game = new Game(); + game.onTick(); } catch (Exception e) { e.printStackTrace(); } @@ -92,11 +82,11 @@ public class Main extends JavaPlugin implements Listener { onTickTask.cancel(); } - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { return CommandHandler.handleCommand(sender, cmd, label, args); } - public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { return TabCompleter.handleTabComplete(sender, command, label, args); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java deleted file mode 100644 index 8efbe80..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java +++ /dev/null @@ -1,85 +0,0 @@ -package net.tylermurphy.hideAndSeek.bukkit; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import org.bukkit.Bukkit; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.Stop; -import net.tylermurphy.hideAndSeek.util.Packet; -import net.tylermurphy.hideAndSeek.util.Util; -import static net.tylermurphy.hideAndSeek.configuration.Localization.*; - -public class Tick { - - static int tick = 0; - - public static void onTick() { - - if(Main.plugin.status.equals("Standby")) tick = 0; - else if(Main.plugin.status.equals("Playing")) onPlaying(); - - if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeHider() < 1) { - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); - else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); - Stop.onStop(); - } - if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeSeeker() < 1) { - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); - else Util.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); - Stop.onStop(); - } - - } - - private static void onPlaying() { - - if(tick<1000000) tick++; - else tick = 1; - - for(Player hider : Main.plugin.board.getHiders()) { - int distance = 100, temp = 100; - for(Player seeker : Main.plugin.board.getSeekers()) { - try { - temp = (int) hider.getLocation().distance(seeker.getLocation()); - } catch (Exception e){ - //Players in different worlds, NOT OK!!! - } - if(distance > temp) { - distance = temp; - } - } - switch(tick%10) { - case 0: - if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f); - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); - break; - case 3: - if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f); - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); - break; - case 6: - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); - break; - case 9: - if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); - break; - } - - } - - if(tick%20 == 0) { - if(gameLength > 0) { - Main.plugin.board.reloadGameBoards(); - Main.plugin.timeLeft--; - if(Main.plugin.timeLeft < 1) { - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); - else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); - Stop.onStop(); - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index e38c19a..0c6b253 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -3,7 +3,7 @@ package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.bukkit.CommandHandler; +import net.tylermurphy.hideAndSeek.util.CommandHandler; 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 17b8f7a..31660b2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -34,7 +35,7 @@ public class Join implements ICommand { } public static void join(Player player){ - if(Main.plugin.status.equals("Standby")) { + if(Main.plugin.status == Status.STANDBY) { player.getInventory().clear(); Main.plugin.board.addHider(player); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index 8809b5d..1568a9b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -32,7 +33,7 @@ public class Leave implements ICommand { Main.plugin.board.removeBoard(player); Main.plugin.board.remove(player); player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); - if(Main.plugin.status.equals("Standby")) { + if(Main.plugin.status == Status.STANDBY) { Main.plugin.board.reloadLobbyBoards(); } else { Main.plugin.board.reloadGameBoards(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 971cd13..dffbb10 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -3,6 +3,7 @@ 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 org.bukkit.command.CommandSender; import net.tylermurphy.hideAndSeek.Main; @@ -15,7 +16,7 @@ public class Reload implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Main.plugin.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 2befd73..2e8b4f8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; @@ -14,7 +15,7 @@ public class SaveMap implements ICommand { public static boolean runningBackup = false; public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Main.plugin.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index 472396c..f7fb8e9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -2,9 +2,7 @@ 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 org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -16,7 +14,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetBorder implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Main.plugin.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index c94a0d1..bbf099d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -11,7 +12,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetBounds implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Main.plugin.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 aeaa89b..ea0144d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -5,6 +5,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; import java.util.HashMap; import java.util.Map; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -15,7 +16,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetExitLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Main.plugin.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index 2e96a9d..4002bee 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -5,6 +5,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; import java.util.HashMap; import java.util.Map; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -15,7 +16,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetLobbyLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Main.plugin.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index bb3de6d..c854b60 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -5,6 +5,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; import java.util.HashMap; import java.util.Map; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -17,7 +18,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetSpawnLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Main.plugin.status.equals("Standby")) { + if(Main.plugin.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 05565da..31f04d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -1,6 +1,7 @@ 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; @@ -36,7 +37,7 @@ public class Start implements ICommand { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } - if(!Main.plugin.status.equals("Standby")) { + if(Main.plugin.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } @@ -48,11 +49,6 @@ public class Start implements ICommand { sender.sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers)); return; } - if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { - Main.plugin.worldLoader.rollback(); - } else { - Main.plugin.worldLoader.loadMap(); - } String seekerName; if(args.length < 1) { seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName(); @@ -64,77 +60,7 @@ public class Start implements ICommand { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; } - Main.plugin.board.reload(); - for(Player temp : Main.plugin.board.getPlayers()) { - if(temp.getName().equals(seeker.getName())) - continue; - Main.plugin.board.addHider(temp); - } - Main.plugin.board.addSeeker(seeker); - currentWorldborderSize = worldborderSize; - for(Player player : Main.plugin.board.getPlayers()) { - player.getInventory().clear(); - player.setGameMode(GameMode.ADVENTURE); - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); - for(PotionEffect effect : player.getActivePotionEffects()){ - player.removePotionEffect(effect.getType()); - } - } - for(Player player : Main.plugin.board.getSeekers()) { - player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); - player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20); - } - for(Player player : Main.plugin.board.getHiders()) { - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); - player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20); - } - Worldborder.resetWorldborder("hideandseek_"+spawnWorld); - for(Player player : Main.plugin.board.getPlayers()){ - Main.plugin.board.createGameBoard(player); - } - Main.plugin.board.reloadGameBoards(); - Main.plugin.status = "Starting"; - int temp = Main.plugin.gameId; - Util.broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30)); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), Main.plugin.gameId, 20 * 10); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), Main.plugin.gameId, 20 * 20); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), Main.plugin.gameId, 20 * 25); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), Main.plugin.gameId, 20 * 27); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), Main.plugin.gameId, 20 * 28); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), Main.plugin.gameId, 20 * 29); - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != Main.plugin.gameId) return; - Util.broadcastMessage(messagePrefix + message("START")); - Main.plugin.status = "Playing"; - for(Player player : Main.plugin.board.getPlayers()) { - Util.resetPlayer(player); - } - Main.plugin.worldborder = null; - Main.plugin.taunt = null; - Main.plugin.glow = null; - - if(worldborderEnabled) { - Main.plugin.worldborder = new Worldborder(Main.plugin.gameId); - Main.plugin.worldborder.schedule(); - } - - if(tauntEnabled) { - Main.plugin.taunt = new Taunt(Main.plugin.gameId); - Main.plugin.taunt.schedule(); - } - - if (glowEnabled) { - Main.plugin.glow = new Glow(Main.plugin.gameId); - } - - if(gameLength > 0) { - Main.plugin.timeLeft = gameLength; - } - } - }, 20 * 30); - + Main.plugin.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 e4dd16e..f444f34 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -2,17 +2,11 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.events.Worldborder; -import net.tylermurphy.hideAndSeek.util.Packet; import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; @@ -23,14 +17,12 @@ public class Stop implements ICommand { sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do"); return; } - if(Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing")) { + if(Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP")); else Util.broadcastMessage(abortPrefix + message("STOP")); - onStop(); - + Main.plugin.game.stop(); } else { sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS")); - return; } } @@ -38,30 +30,6 @@ public class Stop implements ICommand { return "stop"; } - public static void onStop() { - if(Main.plugin.status.equals("Standby")) return; - Main.plugin.status = "Standby"; - Main.plugin.gameId++; - Main.plugin.timeLeft = 0; - Worldborder.resetWorldborder("hideandseek_"+spawnWorld); - for(Player player : Main.plugin.board.getPlayers()) { - Main.plugin.board.createLobbyBoard(player); - player.setGameMode(GameMode.ADVENTURE); - Main.plugin.board.addHider(player); - player.getInventory().clear(); - player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); - for(PotionEffect effect : player.getActivePotionEffects()){ - player.removePotionEffect(effect.getType()); - } - player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); - for(Player temp : Main.plugin.board.getPlayers()) { - Packet.setGlow(player, temp, false); - } - } - Main.plugin.worldLoader.unloadMap(); - Main.plugin.board.reloadLobbyBoards(); - } - public String getUsage() { return ""; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index ee9d88d..b83ee42 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -37,7 +37,8 @@ public class Config { glowStackable, pvpEnabled, autoJoin, - teleportToExit; + teleportToExit, + lobbyCountdownEnabled; public static int minPlayers, @@ -50,7 +51,11 @@ public class Config { saveMaxX, saveMaxZ, tauntDelay, - glowLength; + glowLength, + countdown, + changeCountdown, + lobbyMin, + lobbyMax; public static void loadConfig() { @@ -121,10 +126,17 @@ public class Config { glowStackable = manager.getBoolean("glow.stackable"); glowEnabled = manager.getBoolean("glow.enabled"); + //Lobby + minPlayers = Math.max(2, manager.getInt("minPlayers")); + countdown = Math.max(10,manager.getInt("lobby.countdown")); + changeCountdown = Math.max(minPlayers,manager.getInt("lobby.changeCountdown")); + lobbyMin = Math.max(minPlayers,manager.getInt("lobby.min")); + lobbyMax = manager.getInt("lobby.max"); + lobbyCountdownEnabled = manager.getBoolean("lobby.enabled"); + //Other nametagsVisible = manager.getBoolean("nametagsVisible"); permissionsRequired = manager.getBoolean("permissionsRequired"); - minPlayers = Math.max(2, manager.getInt("minPlayers")); gameLength = manager.getInt("gameLength"); pvpEnabled = manager.getBoolean("pvp"); autoJoin = manager.getBoolean("autoJoin"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 61dc5a4..05d7fb6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -48,7 +48,7 @@ public class Localization { public static LocalizationString message(String key) { LocalizationString temp = LOCAL.get(key); if(temp == null) { - return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + "is not found in localization.yml. This is a plugin issue, please report it."); + return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + " is not found in localization.yml. This is a plugin issue, please report it."); } return new LocalizationString(temp.toString()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java index a817df3..139d8b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java @@ -19,7 +19,7 @@ public class Glow { this.glowTime = 0; } - public void onProjectilve() { + public void onProjectile() { if(glowStackable) glowTime += glowLength; else glowTime = glowLength; if(!running) @@ -38,7 +38,7 @@ public class Glow { private void waitGlow() { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(temp != Main.plugin.gameId) return; + if(temp != Main.plugin.game.gameId) return; glowTime--; glowTime = Math.max(glowTime, 0); if(glowTime == 0) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java index d24c93f..af9097e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java @@ -44,7 +44,7 @@ public class Taunt { } private void executeTaunt() { - if(temp != Main.plugin.gameId) return; + if(temp != Main.plugin.game.gameId) return; Player taunted = null; int rand = (int) (Math.random()*Main.plugin.board.sizeHider()); for(Player player : Main.plugin.board.getPlayers()) { @@ -62,7 +62,7 @@ public class Taunt { Util.broadcastMessage(tauntPrefix + message("TAUNT")); tauntPlayer = taunted.getName(); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(temp != Main.plugin.gameId) return; + if(temp != Main.plugin.game.gameId) return; Player taunted1 = Main.plugin.board.getPlayer(tauntPlayer); if(taunted1 != null) { Firework fw = (Firework) taunted1.getLocation().getWorld().spawnEntity(taunted1.getLocation(), EntityType.FIREWORK); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java index 5d0e48c..a6f97f8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java @@ -36,7 +36,7 @@ public class Worldborder { } private void decreaceWorldborder() { - if(temp != Main.plugin.gameId) return; + if(temp != Main.plugin.game.gameId) return; if(currentWorldborderSize-100 > 100) { running = true; Util.broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java similarity index 95% rename from src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java rename to src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index ffad241..d7bb89b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.bukkit; +package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -57,7 +57,7 @@ public class EventListener implements Listener { @EventHandler public void onQuit(PlayerQuitEvent event) { Main.plugin.board.remove(event.getPlayer()); - if(Main.plugin.status.equals("Standby")) { + if(Main.plugin.status == Status.STANDBY) { Main.plugin.board.reloadLobbyBoards(); } else { Main.plugin.board.reloadGameBoards(); @@ -70,7 +70,7 @@ public class EventListener implements Listener { @EventHandler public void onKick(PlayerKickEvent event) { Main.plugin.board.remove(event.getPlayer()); - if(Main.plugin.status.equals("Standby")) { + if(Main.plugin.status == Status.STANDBY) { Main.plugin.board.reloadLobbyBoards(); } else { Main.plugin.board.reloadGameBoards(); @@ -86,7 +86,7 @@ public class EventListener implements Listener { if (event.getEntity() instanceof Player) { Player p = (Player) event.getEntity(); if (!Main.plugin.board.isPlayer(p)) return; - if (!Main.plugin.status.equals("Playing")) { + if (Main.plugin.status != Status.PLAYING) { event.setCancelled(true); return; } @@ -128,14 +128,14 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onProjectile(ProjectileLaunchEvent event) { - if(!Main.plugin.status.equals("Playing")) return; + if(Main.plugin.status != Status.PLAYING) return; if(event.getEntity() instanceof Snowball) { if(!glowEnabled) return; Snowball snowball = (Snowball) event.getEntity(); if(snowball.getShooter() instanceof Player) { Player player = (Player) snowball.getShooter(); if(Main.plugin.board.isHider(player)) { - Main.plugin.glow.onProjectilve(); + Main.plugin.game.glow.onProjectile(); snowball.remove(); player.getInventory().remove(Material.SNOWBALL); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java new file mode 100644 index 0000000..50e970e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -0,0 +1,227 @@ +package net.tylermurphy.hideAndSeek.game; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.events.Glow; +import net.tylermurphy.hideAndSeek.events.Taunt; +import net.tylermurphy.hideAndSeek.events.Worldborder; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.Packet; +import net.tylermurphy.hideAndSeek.util.Util; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.Random; + +import static net.tylermurphy.hideAndSeek.configuration.Localization.*; +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class Game { + + public Taunt taunt; + public Glow glow; + public Worldborder worldborder; + + private int tick = 0; + public int countdownTime = -1; + public int gameId = 0; + public int timeLeft = 0; + + public void start(Player seeker){ + if(Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING) return; + if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { + Main.plugin.worldLoader.rollback(); + } else { + Main.plugin.worldLoader.loadMap(); + } + Main.plugin.board.reload(); + for(Player temp : Main.plugin.board.getPlayers()) { + if(temp.getName().equals(seeker.getName())) + continue; + Main.plugin.board.addHider(temp); + } + Main.plugin.board.addSeeker(seeker); + currentWorldborderSize = worldborderSize; + for(Player player : Main.plugin.board.getPlayers()) { + player.getInventory().clear(); + player.setGameMode(GameMode.ADVENTURE); + player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + for(PotionEffect effect : player.getActivePotionEffects()){ + player.removePotionEffect(effect.getType()); + } + } + for(Player player : Main.plugin.board.getSeekers()) { + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); + player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20); + } + for(Player player : Main.plugin.board.getHiders()) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); + player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20); + } + Worldborder.resetWorldborder("hideandseek_"+spawnWorld); + for(Player player : Main.plugin.board.getPlayers()){ + Main.plugin.board.createGameBoard(player); + } + Main.plugin.board.reloadGameBoards(); + Main.plugin.status = Status.STARTING; + int temp = Main.plugin.game.gameId; + Util.broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30)); + Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), Main.plugin.game.gameId, 20 * 10); + Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), Main.plugin.game.gameId, 20 * 20); + Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), Main.plugin.game.gameId, 20 * 25); + Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), Main.plugin.game.gameId, 20 * 27); + Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), Main.plugin.game.gameId, 20 * 28); + Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), Main.plugin.game.gameId, 20 * 29); + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != Main.plugin.game.gameId) return; + Util.broadcastMessage(messagePrefix + message("START")); + Main.plugin.status = Status.PLAYING; + for(Player player : Main.plugin.board.getPlayers()) { + Util.resetPlayer(player); + } + + if(worldborderEnabled) { + worldborder = new Worldborder(Main.plugin.game.gameId); + worldborder.schedule(); + } + + if(tauntEnabled) { + taunt = new Taunt(Main.plugin.game.gameId); + taunt.schedule(); + } + + if (glowEnabled) { + glow = new Glow(Main.plugin.game.gameId); + } + + if(gameLength > 0) { + timeLeft = gameLength; + } + } + }, 20 * 30); + } + + public void stop(){ + if(Main.plugin.status == Status.STANDBY) return; + tick = 0; + countdownTime = -1; + Main.plugin.status = Status.STANDBY; + Main.plugin.game.gameId++; + timeLeft = 0; + Worldborder.resetWorldborder("hideandseek_"+spawnWorld); + for(Player player : Main.plugin.board.getPlayers()) { + Main.plugin.board.createLobbyBoard(player); + player.setGameMode(GameMode.ADVENTURE); + Main.plugin.board.addHider(player); + player.getInventory().clear(); + player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); + for(PotionEffect effect : player.getActivePotionEffects()){ + player.removePotionEffect(effect.getType()); + } + player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); + for(Player temp : Main.plugin.board.getPlayers()) { + Packet.setGlow(player, temp, false); + } + } + Main.plugin.worldLoader.unloadMap(); + Main.plugin.board.reloadLobbyBoards(); + } + + public void onTick() { + + if(!Util.isSetup()) return; + + if(Main.plugin.status == Status.STANDBY) whileWaiting(); + else if(Main.plugin.status == Status.PLAYING) whilePlaying(); + + if(( Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING ) && Main.plugin.board.sizeHider() < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); + else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); + stop(); + } + if(( Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING ) && Main.plugin.board.sizeSeeker() < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); + else Util.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); + stop(); + } + + tick++; + + } + + private void whileWaiting() { + if(lobbyCountdownEnabled){ + if(lobbyMin <= Main.plugin.board.size()){ + if(countdownTime == -1) + countdownTime = countdown; + if(Main.plugin.board.size() >= changeCountdown) + countdownTime = Math.min(countdownTime, 10); + if(tick % 20 == 0) + countdownTime--; + if(countdownTime == 0){ + String seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName(); + Player seeker = Main.plugin.board.getPlayer(seekerName); + start(seeker); + } + } else { + countdownTime = -1; + } + } + + } + + private void whilePlaying() { + + for(Player hider : Main.plugin.board.getHiders()) { + int distance = 100, temp = 100; + for(Player seeker : Main.plugin.board.getSeekers()) { + try { + temp = (int) hider.getLocation().distance(seeker.getLocation()); + } catch (Exception e){ + //Players in different worlds, NOT OK!!! + } + if(distance > temp) { + distance = temp; + } + } + switch(tick%10) { + case 0: + if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f); + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + break; + case 3: + if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f); + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + break; + case 6: + if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + break; + case 9: + if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + break; + } + + } + + if(tick%20 == 0) { + if(gameLength > 0) { + Main.plugin.board.reloadGameBoards(); + timeLeft--; + if(timeLeft < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); + else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); + stop(); + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Status.java new file mode 100644 index 0000000..92a16a6 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Status.java @@ -0,0 +1,7 @@ +package net.tylermurphy.hideAndSeek.game; + +public enum Status { + STANDBY, + STARTING, + PLAYING +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java index 9d856b5..6b0c7b5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import net.tylermurphy.hideAndSeek.game.Status; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -25,8 +26,8 @@ import net.tylermurphy.hideAndSeek.Main; public class Board { private List Hider, Seeker, Spectator; - private Map playerList = new HashMap(); - private Map customBoards = new HashMap(); + private Map playerList = new HashMap<>(); + private Map customBoards = new HashMap<>(); public boolean isPlayer(Player player) { return playerList.containsKey(player.getName()); @@ -120,31 +121,9 @@ public class Board { } public void reload() { - Hider = new ArrayList(); - Seeker = new ArrayList(); - Spectator = new ArrayList(); - } - - public void reset() { - Hider.clear(); - Seeker.clear(); - Spectator.clear(); - } - - private void createTeamsForBoard(Scoreboard board) { - Team hiderTeam = board.registerNewTeam("Hider"); - for(String name : Hider) - hiderTeam.addEntry(name); - Team seekerTeam = board.registerNewTeam("Seeker"); - for(String name : Seeker) - seekerTeam.addEntry(name); - if(nametagsVisible) { - hiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM); - seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS); - } else { - hiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - } + Hider = new ArrayList<>(); + Seeker = new ArrayList<>(); + Spectator = new ArrayList<>(); } public void createLobbyBoard(Player player) { @@ -157,12 +136,20 @@ public class Board { board = new CustomBoard(player, "&l&eHIDE AND SEEK"); board.updateTeams(); } - board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER%" + ChatColor.WHITE + getHiderPercent()); - board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent()); + board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER %" + ChatColor.WHITE + getHiderPercent()); + board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER %" + ChatColor.WHITE + getSeekerPercent()); board.addBlank(); board.setLine("players", "Players: " + playerList.values().size()); board.addBlank(); - board.setLine("waiting", "Waiting to start..."); + if(lobbyCountdownEnabled){ + if(Main.plugin.game.countdownTime == -1){ + board.setLine("waiting", "Waiting for players..."); + } else { + board.setLine("waiting", "Starting in: "+ChatColor.GREEN + Main.plugin.game.countdownTime+"s"); + } + } else { + board.setLine("waiting", "Waiting for gamemaster..."); + } board.display(); customBoards.put(player.getName(), board); } @@ -175,38 +162,39 @@ public class Board { CustomBoard board = customBoards.get(player.getName()); if(recreate) { board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + board.updateTeams(); } board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); board.addBlank(); if(glowEnabled){ - if(Main.plugin.glow == null || Main.plugin.status.equals("Starting") || !Main.plugin.glow.isRunning()) + if(Main.plugin.game.glow == null || Main.plugin.status == Status.STARTING || !Main.plugin.game.glow.isRunning()) board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); else board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); } if(tauntEnabled && tauntCountdown){ - if(Main.plugin.taunt == null || Main.plugin.status.equals("Starting")) + if(Main.plugin.game.taunt == null || Main.plugin.status == Status.STARTING) board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); else if(!tauntLast && Hider.size() == 1){ board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); - } else if(!Main.plugin.taunt.isRunning()) - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.taunt.getDelay()/60 + "m" + Main.plugin.taunt.getDelay()%60 + "s"); + } else if(!Main.plugin.game.taunt.isRunning()) + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.game.taunt.getDelay()/60 + "m" + Main.plugin.game.taunt.getDelay()%60 + "s"); else board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); } if(worldborderEnabled){ - if(Main.plugin.worldborder == null || Main.plugin.status.equals("Starting")){ + if(Main.plugin.game.worldborder == null || Main.plugin.status == Status.STARTING){ board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); - } else if(!Main.plugin.worldborder.isRunning()) { - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Main.plugin.worldborder.getDelay()/60 + "m" + Main.plugin.worldborder.getDelay()%60 + "s"); + } else if(!Main.plugin.game.worldborder.isRunning()) { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Main.plugin.game.worldborder.getDelay()/60 + "m" + Main.plugin.game.worldborder.getDelay()%60 + "s"); } else { board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing"); } } if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled) board.addBlank(); - board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); + board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.game.timeLeft/60 + "m" + Main.plugin.game.timeLeft%60 + "s"); board.addBlank(); board.setLine("team", "Team: " + getTeam(player)); board.display(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java similarity index 98% rename from src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java rename to src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java index 1efb505..56084dd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.bukkit; +package net.tylermurphy.hideAndSeek.util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java similarity index 96% rename from src/main/java/net/tylermurphy/hideAndSeek/bukkit/TabCompleter.java rename to src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java index 2f7dbd4..667f597 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/TabCompleter.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.bukkit; +package net.tylermurphy.hideAndSeek.util; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index c24936b..f3bee71 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -45,7 +45,7 @@ public class Util { public static void sendDelayedMessage(String message, int gameId, int delay) { Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, new Runnable() { public void run() { - if(gameId == Main.plugin.gameId) + if(gameId == Main.plugin.game.gameId) Util.broadcastMessage(message); } }, delay); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7366476..ae130f8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -79,9 +79,21 @@ prefix: gameover: '&aGame Over > &f' warning: '&cWarning > &f' +# This is the section if you want a standard "waiting for players" lobby. You can specify +# the standard countdown length under [countdown] (min 10 seconds). Then once the lobby gets to a size specified +# by [changeCountdown], the timer will automatically go to 10 seconds. [min] is the minimum players +# to start the countdown. [max] is the lobby cap, set to -1 to remove maximum cap. +lobby: + countdown: 60 + changeCountdown: 5 + min: 3 + max: 10 + enabled: true + + # Changes the default plugin language. Currently, Supported localizations are: -# en-US (United States) -# de-DE (German) +# en-US (English - United States) +# de-DE (German - Germany) local: "en-US" # ---------------------------------------------------------- #