From 06b31297d3d83a0c7b76230be1b089bdfd8e4afa Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Fri, 24 Dec 2021 22:40:21 -0500 Subject: [PATCH 01/16] 1.3.3 beta 1 --- pom.xml | 2 +- .../hideAndSeek/bukkit/CommandHandler.java | 8 ++--- .../hideAndSeek/bukkit/EventListener.java | 32 +++++++++++++------ .../hideAndSeek/command/About.java | 2 +- .../hideAndSeek/configuration/Items.java | 1 + .../tylermurphy/hideAndSeek/util/Util.java | 10 ++++++ src/main/resources/plugin.yml | 6 +++- 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 544d3bb..de10b5b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 net.tylermurphy HideAndSeek - 1.3.2 + 1.3.3 Hide and Seek Plugin diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java index 1efb505..5d4fc76 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java @@ -41,7 +41,7 @@ public class CommandHandler { } public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { - if(sender instanceof Player == false) { + if(!(sender instanceof Player)) { sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); } else if(args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) { if(permissionsRequired && !sender.hasPermission("hideandseek.about")) { @@ -50,7 +50,7 @@ public class CommandHandler { COMMAND_REGISTER.get("about").execute(sender, null); } } else { - if(!args[0].toLowerCase().equals("about") && !args[0].toLowerCase().equals("help") && SaveMap.runningBackup) { + if(!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) { sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); } else if(permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) { sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); @@ -65,9 +65,5 @@ public class CommandHandler { } return true; } - - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - return CommandHandler.handleCommand(sender, command, label, args); - } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index ffad241..a425f99 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -3,11 +3,7 @@ package net.tylermurphy.hideAndSeek.bukkit; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import net.tylermurphy.hideAndSeek.command.Join; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -21,9 +17,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.*; import net.tylermurphy.hideAndSeek.util.Packet; import net.tylermurphy.hideAndSeek.util.Util; @@ -36,8 +30,8 @@ public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - event.getPlayer().setLevel(0); Main.plugin.board.remove(event.getPlayer()); + Util.removeItems(event.getPlayer()); if(!Util.isSetup()) return; if(autoJoin){ Join.join(event.getPlayer()); @@ -65,6 +59,7 @@ public class EventListener implements Listener { for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ event.getPlayer().removePotionEffect(effect.getType()); } + Util.removeItems(event.getPlayer()); } @EventHandler @@ -78,6 +73,25 @@ public class EventListener implements Listener { for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ event.getPlayer().removePotionEffect(effect.getType()); } + Util.removeItems(event.getPlayer()); + } + + @EventHandler + public void onChat(AsyncPlayerChatEvent event){ + if(Main.plugin.board.isSeeker(event.getPlayer())){ + event.setCancelled(true); + Main.plugin.board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage())); + } + } + + @EventHandler + public void onMove(PlayerMoveEvent event){ + if(!event.getPlayer().getWorld().equals("hideandseek_" + spawnWorld)) return; + if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return; + if(!event.getTo().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; + if(event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMinX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){ + event.setCancelled(true); + } } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index c341666..6256f69 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.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(1.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/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index e5470af..3651a41 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -78,6 +78,7 @@ public class Items { if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){ PotionMeta meta = getPotionMeta(stack, item); stack.setItemMeta(meta); + } else { ConfigurationSection enchantments = item.getConfigurationSection("enchantments"); if (enchantments != null) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index c24936b..a1ae4e0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -4,6 +4,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; import java.io.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import net.md_5.bungee.api.ChatColor; @@ -82,4 +83,13 @@ public class Util { } } } + + public static void removeItems(Player player){ + for(ItemStack si : Items.SEEKER_ITEMS) + for(ItemStack i : player.getInventory().getContents()) + if(si.isSimilar(i)) player.getInventory().remove(i); + for(ItemStack hi : Items.HIDER_ITEMS) + for(ItemStack i : player.getInventory().getContents()) + if(hi.isSimilar(i)) player.getInventory().remove(i); + } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ce62925..bd391c9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: HideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.3.2 +version: 1.3.3 author: KenshinEto load: STARTUP api-version: 1.14 @@ -28,6 +28,7 @@ permissions: hideandseek.savemap: true hideandseek.join: true hideandseek.leave: true + hideandseek.leavebounds: true hideandseek.about: description: Allows you to run the about command default: true @@ -70,3 +71,6 @@ permissions: hideandseek.leave: description: Allows you to leave the game manual lobby default: true + hideandseek.leavebounds: + description: Allows players to leave specified game bounderies + default: op From 6239acb08a43d6bfef51f6abc8b7cc65687c51c7 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 25 Dec 2021 08:16:03 -0600 Subject: [PATCH 02/16] 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" # ---------------------------------------------------------- # From 35d9e912d593164d6520bbeb5cfa69cdf5b530d8 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 25 Dec 2021 08:21:06 -0600 Subject: [PATCH 03/16] Pre merge --- src/main/resources/plugin.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ce62925..bd391c9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: HideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.3.2 +version: 1.3.3 author: KenshinEto load: STARTUP api-version: 1.14 @@ -28,6 +28,7 @@ permissions: hideandseek.savemap: true hideandseek.join: true hideandseek.leave: true + hideandseek.leavebounds: true hideandseek.about: description: Allows you to run the about command default: true @@ -70,3 +71,6 @@ permissions: hideandseek.leave: description: Allows you to leave the game manual lobby default: true + hideandseek.leavebounds: + description: Allows players to leave specified game bounderies + default: op From d8da188f024aa705ff285dfbf35d8c5e4b917af9 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 25 Dec 2021 08:23:19 -0600 Subject: [PATCH 04/16] Rebase pom.xml --- pom.xml | 8 +++-- .../hideAndSeek/command/About.java | 2 +- .../hideAndSeek/configuration/Items.java | 1 + .../hideAndSeek/game/EventListener.java | 32 +++++++++++++------ .../hideAndSeek/util/CommandHandler.java | 8 ++--- .../tylermurphy/hideAndSeek/util/Util.java | 10 ++++++ 6 files changed, 43 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index be5659b..5d49f1f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,10 @@ -4.0.0 +4.0.0 net.tylermurphy +<<<<<<< HEAD KenshinsHideAndSeek +======= + HideAndSeek +>>>>>>> 06b31297d3d83a0c7b76230be1b089bdfd8e4afa 1.3.3 Hide and Seek Plugin @@ -46,4 +50,4 @@ compile - \ No newline at end of file + diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index c341666..6256f69 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.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(1.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/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index e5470af..3651a41 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -78,6 +78,7 @@ public class Items { if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){ PotionMeta meta = getPotionMeta(stack, item); stack.setItemMeta(meta); + } else { ConfigurationSection enchantments = item.getConfigurationSection("enchantments"); if (enchantments != null) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index d7bb89b..60c7132 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -3,11 +3,7 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import net.tylermurphy.hideAndSeek.command.Join; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -21,9 +17,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.*; import net.tylermurphy.hideAndSeek.util.Packet; import net.tylermurphy.hideAndSeek.util.Util; @@ -36,8 +30,8 @@ public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - event.getPlayer().setLevel(0); Main.plugin.board.remove(event.getPlayer()); + Util.removeItems(event.getPlayer()); if(!Util.isSetup()) return; if(autoJoin){ Join.join(event.getPlayer()); @@ -65,6 +59,7 @@ public class EventListener implements Listener { for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ event.getPlayer().removePotionEffect(effect.getType()); } + Util.removeItems(event.getPlayer()); } @EventHandler @@ -78,6 +73,25 @@ public class EventListener implements Listener { for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ event.getPlayer().removePotionEffect(effect.getType()); } + Util.removeItems(event.getPlayer()); + } + + @EventHandler + public void onChat(AsyncPlayerChatEvent event){ + if(Main.plugin.board.isSeeker(event.getPlayer())){ + event.setCancelled(true); + Main.plugin.board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage())); + } + } + + @EventHandler + public void onMove(PlayerMoveEvent event){ + if(!event.getPlayer().getWorld().equals("hideandseek_" + spawnWorld)) return; + if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return; + if(!event.getTo().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; + if(event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMinX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){ + event.setCancelled(true); + } } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java index 56084dd..18a2c8c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java @@ -41,7 +41,7 @@ public class CommandHandler { } public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { - if(sender instanceof Player == false) { + if(!(sender instanceof Player)) { sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); } else if(args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) { if(permissionsRequired && !sender.hasPermission("hideandseek.about")) { @@ -50,7 +50,7 @@ public class CommandHandler { COMMAND_REGISTER.get("about").execute(sender, null); } } else { - if(!args[0].toLowerCase().equals("about") && !args[0].toLowerCase().equals("help") && SaveMap.runningBackup) { + if(!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) { sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS")); } else if(permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) { sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED")); @@ -65,9 +65,5 @@ public class CommandHandler { } return true; } - - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - return CommandHandler.handleCommand(sender, command, label, args); - } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index f3bee71..513ac16 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -4,6 +4,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; import java.io.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import net.md_5.bungee.api.ChatColor; @@ -82,4 +83,13 @@ public class Util { } } } + + public static void removeItems(Player player){ + for(ItemStack si : Items.SEEKER_ITEMS) + for(ItemStack i : player.getInventory().getContents()) + if(si.isSimilar(i)) player.getInventory().remove(i); + for(ItemStack hi : Items.HIDER_ITEMS) + for(ItemStack i : player.getInventory().getContents()) + if(hi.isSimilar(i)) player.getInventory().remove(i); + } } \ No newline at end of file From 82fdc20d77c6c6e8bc49b829a4a6dd416956d6d7 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 25 Dec 2021 08:24:25 -0600 Subject: [PATCH 05/16] Rebase pom --- pom.xml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 5d49f1f..de10b5b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,6 @@ -4.0.0 +4.0.0 net.tylermurphy -<<<<<<< HEAD - KenshinsHideAndSeek -======= HideAndSeek ->>>>>>> 06b31297d3d83a0c7b76230be1b089bdfd8e4afa 1.3.3 Hide and Seek Plugin @@ -43,11 +39,5 @@ ProtocolLib 4.7.0 - - org.jetbrains - annotations - RELEASE - compile - - + \ No newline at end of file From 8cf4d881dce1c168b19097b6798ff5e737762615 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 25 Dec 2021 08:29:31 -0600 Subject: [PATCH 06/16] fix @NotNull --- src/main/java/net/tylermurphy/hideAndSeek/Main.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 3aa456b..050d96b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -26,7 +26,6 @@ import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.util.Board; import net.tylermurphy.hideAndSeek.world.WorldLoader; -import org.jetbrains.annotations.NotNull; public class Main extends JavaPlugin implements Listener { @@ -82,11 +81,11 @@ public class Main extends JavaPlugin implements Listener { onTickTask.cancel(); } - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { + public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) { return CommandHandler.handleCommand(sender, cmd, label, args); } - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { return TabCompleter.handleTabComplete(sender, command, label, args); } From 6e09da9150bb8b178a168f463136759d95a2f8d4 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 25 Dec 2021 22:46:22 -0600 Subject: [PATCH 07/16] 1.3.3 beta 2 --- pom.xml | 5 + .../net/tylermurphy/hideAndSeek/Main.java | 17 ++- .../tylermurphy/hideAndSeek/command/Stop.java | 3 +- .../tylermurphy/hideAndSeek/command/Top.java | 60 ++++++++++ .../tylermurphy/hideAndSeek/command/Wins.java | 66 +++++++++++ .../configuration/ConfigManager.java | 1 - .../hideAndSeek/database/Database.java | 30 +++++ .../hideAndSeek/database/PlayerInfo.java | 18 +++ .../hideAndSeek/database/PlayerInfoTable.java | 109 ++++++++++++++++++ .../tylermurphy/hideAndSeek/game/Game.java | 73 +++++++----- .../tylermurphy/hideAndSeek/game/WinType.java | 7 ++ .../tylermurphy/hideAndSeek/util/Board.java | 4 + .../hideAndSeek/util/CommandHandler.java | 6 +- .../hideAndSeek/util/UUIDFetcher.java | 84 ++++++++++++++ .../tylermurphy/hideAndSeek/util/Util.java | 21 ++++ .../resources/lang/localization_de-DE.yml | 3 +- .../resources/lang/localization_en-US.yml | 2 + 17 files changed, 473 insertions(+), 36 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Top.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/database/Database.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/game/WinType.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java diff --git a/pom.xml b/pom.xml index de10b5b..7c10eb1 100644 --- a/pom.xml +++ b/pom.xml @@ -39,5 +39,10 @@ ProtocolLib 4.7.0 + + org.xerial + sqlite-jdbc + 3.36.0.3 + \ 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 050d96b..b9aaa94 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -7,7 +7,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.game.Status; +import net.tylermurphy.hideAndSeek.util.UUIDFetcher; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -36,6 +38,7 @@ public class Main extends JavaPlugin implements Listener { public Board board; public WorldLoader worldLoader; public Status status = Status.STANDBY; + public Database database; private BukkitTask onTickTask; public void onEnable() { @@ -63,11 +66,20 @@ public class Main extends JavaPlugin implements Listener { //Board board = new Board(); board.reload(); - + + //Database + database = new Database(); + database.init(); + + //UUIDFetcher Cache + UUIDFetcher.init(); + + //Init game + game = new Game(); + // Start Tick Timer onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> { try{ - game = new Game(); game.onTick(); } catch (Exception e) { e.printStackTrace(); @@ -79,6 +91,7 @@ public class Main extends JavaPlugin implements Listener { public void onDisable() { if(onTickTask != null) onTickTask.cancel(); + UUIDFetcher.cleanup(); } public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index f444f34..2fef77c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -3,6 +3,7 @@ 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 org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -20,7 +21,7 @@ public class Stop implements ICommand { if(Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP")); else Util.broadcastMessage(abortPrefix + message("STOP")); - Main.plugin.game.stop(); + Main.plugin.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 new file mode 100644 index 0000000..c394378 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -0,0 +1,60 @@ +package net.tylermurphy.hideAndSeek.command; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.database.PlayerInfo; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import java.util.List; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.*; + +public class Top implements ICommand { + + public void execute(CommandSender sender, String[] args) { + int page; + if(args.length == 0) page = 1; + else try{ + page = Integer.parseInt(args[0]); + } catch(Exception e){ + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + if(page < 1){ + sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(page)); + return; + } + String message = 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); + int i = 1 + (page-1)*10; + for(PlayerInfo info : infos){ + String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName(); + ChatColor color; + switch (i){ + case 1: color = ChatColor.YELLOW; break; + case 2: color = ChatColor.GRAY; break; + 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); + i++; + } + sender.sendMessage(message); + } + + public String getLabel() { + return "top"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Gets the top players in the server."; + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java new file mode 100644 index 0000000..d99229d --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -0,0 +1,66 @@ +package net.tylermurphy.hideAndSeek.command; + +import com.comphenix.protocol.PacketType; +import net.tylermurphy.hideAndSeek.Main; +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 java.util.UUID; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.*; + +public class Wins implements ICommand { + + public void execute(CommandSender sender, String[] args) { + Main.plugin.getServer().getScheduler().runTaskAsynchronously(Main.plugin, () -> { + + UUID uuid; + String name; + if(args.length == 0) { + uuid = Main.plugin.getServer().getPlayer(sender.getName()).getUniqueId(); + name = sender.getName(); + } + else { + try { + name = args[0]; + uuid = UUIDFetcher.getUUID(args[0]); + } catch (Exception e){ + sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0])); + return; + } + } + PlayerInfo info = Main.plugin.database.playerInfo.getInfo(uuid); + if(info == null){ + sender.sendMessage(errorPrefix + message("NO_GAME_INFO")); + return; + } + String message = ChatColor.WHITE + "" + ChatColor.BOLD + "==============================\n"; + message = message + message("INFORMATION_FOR").addPlayer(name) + "\n"; + message = message + "==============================\n"; + message = message + String.format("%sTOTAL WINS: %s%s\n%sHIDER WINS: %s%s\n%sSEEKER WINS: %s%s\n%sGAMES PLAYED: %s", + ChatColor.YELLOW, ChatColor.WHITE, info.wins, ChatColor.GOLD, ChatColor.WHITE, info.hider_wins, + ChatColor.RED, ChatColor.WHITE, info.seeker_wins, ChatColor.WHITE, info.games_played); + message = message + ChatColor.WHITE + "" + ChatColor.BOLD + "\n=============================="; + sender.sendMessage(message); + + }); + } + + public String getLabel() { + return "wins"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Get the win information for yourself or another player."; + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index c1757d1..11caa96 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -173,7 +173,6 @@ public class ConfigManager { if(entry.getValue() instanceof String){ replace = "\"" + replace + "\""; } - System.out.println(entry.getKey() + " " + index + " " + start + " " + end); StringBuilder builder = new StringBuilder(yamlString); builder.replace(start+1, end, replace); yamlString = builder.toString(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java new file mode 100644 index 0000000..2254ec2 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -0,0 +1,30 @@ +package net.tylermurphy.hideAndSeek.database; + +import net.tylermurphy.hideAndSeek.Main; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class Database { + + private final File databaseFile = new File(Main.data, "database.db"); + + public PlayerInfoTable playerInfo; + + protected Connection connect() { + Connection conn = null; + try { + String url = "jdbc:sqlite:"+databaseFile; + conn = DriverManager.getConnection(url); + } catch (SQLException e) { + System.out.println(e.getMessage()); + } + return conn; + } + + public void init(){ + playerInfo = new PlayerInfoTable(); + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java new file mode 100644 index 0000000..c1e0070 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java @@ -0,0 +1,18 @@ +package net.tylermurphy.hideAndSeek.database; + +import java.util.UUID; + +public class PlayerInfo { + + public UUID uuid; + public int wins, hider_wins, seeker_wins, games_played; + + public PlayerInfo(UUID uuid, int wins, int hider_wins, int seeker_wins, int games_played){ + this.uuid = uuid; + this.wins = wins; + this.hider_wins = hider_wins; + this.seeker_wins = seeker_wins; + this.games_played = games_played; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java new file mode 100644 index 0000000..07fb2ee --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java @@ -0,0 +1,109 @@ +package net.tylermurphy.hideAndSeek.database; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.WinType; +import net.tylermurphy.hideAndSeek.util.Util; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class PlayerInfoTable { + + protected PlayerInfoTable(){ + + String sql = "CREATE TABLE IF NOT EXISTS player_info (\n" + + " uuid BINARY(16) PRIMARY KEY,\n" + + " wins int NOT NULL,\n" + + " seeker_wins int NOT NULL,\n" + + " hider_wins int NOT NULL,\n" + + " games_played int NOT NULL\n" + + ");"; + + try(Connection connection = Main.plugin.database.connect(); Statement statement = connection.createStatement()){ + statement.execute(sql); + } catch (SQLException e){ + Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); + } + } + + public PlayerInfo getInfo(UUID uuid){ + String sql = "SELECT * FROM player_info WHERE uuid = ?;"; + try(Connection connection = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + InputStream is = Util.convertUniqueId(uuid); + byte[] bytes = new byte[is.available()]; + is.read(bytes); + statement.setBytes(1, bytes); + ResultSet rs = statement.executeQuery(); + if(rs.next()){ + PlayerInfo info = new PlayerInfo( + uuid, + rs.getInt("wins"), + rs.getInt("seeker_wins"), + rs.getInt("hider_wins"), + rs.getInt("games_played") + ); + return info; + } + } catch (SQLException e){ + Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); + } catch (IOException e) { + Main.plugin.getLogger().severe("IO Error: " + e.getMessage()); + e.printStackTrace(); + } + return new PlayerInfo(uuid, 0, 0, 0, 0); + } + + public List getInfoPage(int page){ + String sql = "SELECT * FROM player_info ORDER BY wins DESC LIMIT 10 OFFSET ?;"; + try(Connection connection = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + statement.setInt(1, (page-1)*10); + ResultSet rs = statement.executeQuery(); + List infoList = new ArrayList<>(); + while(rs.next()){ + PlayerInfo info = new PlayerInfo( + Util.convertBinaryStream(rs.getBinaryStream("uuid")), + rs.getInt("wins"), + rs.getInt("seeker_wins"), + rs.getInt("hider_wins"), + rs.getInt("games_played") + ); + infoList.add(info); + } + return infoList; + } catch (SQLException e){ + Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); + } + return null; + } + + public boolean addWins(List uuids, List winners, WinType type){ + for(UUID uuid : uuids){ + String sql = "INSERT OR REPLACE INTO player_info (uuid, wins, seeker_wins, hider_wins, games_played) VALUES (?,?,?,?,?)"; + PlayerInfo info = getInfo(uuid); + try(Connection connection = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + InputStream is = Util.convertUniqueId(uuid); + byte[] bytes = new byte[is.available()]; + is.read(bytes); + statement.setBytes(1, bytes); + statement.setInt(2, info.wins + (winners.contains(uuid) ? 1 : 0)); + statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0)); + statement.setInt(4, info.hider_wins + (winners.contains(uuid) && type == WinType.HIDER_WIN ? 1 : 0)); + statement.setInt(5, info.games_played + 1); + statement.execute(); + } catch (SQLException e){ + Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); + e.printStackTrace(); + return false; + } catch (IOException e) { + Main.plugin.getLogger().severe("IO Error: " + e.getMessage()); + e.printStackTrace(); + } + } + return true; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 50e970e..5af8063 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -10,6 +10,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Sound; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import net.tylermurphy.hideAndSeek.Main; @@ -18,7 +19,11 @@ import net.tylermurphy.hideAndSeek.util.Util; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import java.util.ArrayList; +import java.util.List; import java.util.Random; +import java.util.UUID; +import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -80,43 +85,51 @@ public class Game { 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(gameLength > 0) { + timeLeft = gameLength; + } + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> { + if(temp != Main.plugin.game.gameId) return; + Util.broadcastMessage(messagePrefix + message("START")); - 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; - } + 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); + } + + Main.plugin.status = Status.PLAYING; }, 20 * 30); } - public void stop(){ + public void stop(WinType type){ if(Main.plugin.status == Status.STANDBY) return; tick = 0; countdownTime = -1; Main.plugin.status = Status.STANDBY; Main.plugin.game.gameId++; timeLeft = 0; + List players = Main.plugin.board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList()); + if(type == WinType.HIDER_WIN){ + List winners = Main.plugin.board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList()); + Main.plugin.database.playerInfo.addWins(players, winners, type); + } else if(type == WinType.SEEKER_WIN){ + List winners = new ArrayList<>(); + winners.add(Main.plugin.board.getFirstSeeker().getUniqueId()); + Main.plugin.database.playerInfo.addWins(players, winners, type); + } Worldborder.resetWorldborder("hideandseek_"+spawnWorld); for(Player player : Main.plugin.board.getPlayers()) { Main.plugin.board.createLobbyBoard(player); @@ -146,12 +159,12 @@ public class Game { 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(); + stop(WinType.SEEKER_WIN); } 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(); + stop(WinType.NONE); } tick++; @@ -209,7 +222,7 @@ public class Game { if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; } - + } if(tick%20 == 0) { @@ -219,7 +232,7 @@ public class Game { if(timeLeft < 1) { if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); - stop(); + stop(WinType.HIDER_WIN); } } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/WinType.java b/src/main/java/net/tylermurphy/hideAndSeek/game/WinType.java new file mode 100644 index 0000000..3e01f21 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/WinType.java @@ -0,0 +1,7 @@ +package net.tylermurphy.hideAndSeek.game; + +public enum WinType { + HIDER_WIN, + SEEKER_WIN, + NONE +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java index 6b0c7b5..6b61f16 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java @@ -72,6 +72,10 @@ public class Board { public List getSeekers(){ return Seeker.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); } + + public Player getFirstSeeker(){ + return playerList.get(Seeker.get(0)); + } public List getSpectators(){ return Spectator.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java index 18a2c8c..e66f7ed 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java @@ -3,6 +3,8 @@ package net.tylermurphy.hideAndSeek.util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; @@ -38,6 +40,8 @@ public class CommandHandler { registerCommand(new SetBounds()); registerCommand(new Join()); registerCommand(new Leave()); + registerCommand(new Top()); + registerCommand(new Wins()); } public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { @@ -65,5 +69,5 @@ public class CommandHandler { } return true; } - + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java new file mode 100644 index 0000000..8a5406a --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java @@ -0,0 +1,84 @@ +package net.tylermurphy.hideAndSeek.util; + +import net.tylermurphy.hideAndSeek.Main; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public final class UUIDFetcher { + + private static final Map CACHE = new HashMap<>(); + + private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/"; + private static int cacheTask; + + public static void init(){ + cacheTask = Main.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, CACHE::clear,600*20, 600*20); + } + + public static void cleanup(){ + Main.plugin.getServer().getScheduler().cancelTask(cacheTask); + } + + public static UUID getUUID(String playername) { + + if(CACHE.containsKey(playername)) return CACHE.get(playername); + + String output = callURL(UUID_URL + playername); + StringBuilder result = new StringBuilder(); + readData(output, result); + String u = result.toString(); + StringBuilder uuid = new StringBuilder(); + for (int i = 0; i <= 31; i++) { + uuid.append(u.charAt(i)); + if (i == 7 || i == 11 || i == 15 || i == 19) { + uuid.append('-'); + } + } + return UUID.fromString(uuid.toString()); + } + + private static void readData(String toRead, StringBuilder result) { + for (int i = toRead.length() - 3; i >= 0; i--) { + if (toRead.charAt(i) != '"') { + result.insert(0, toRead.charAt(i)); + } else { + break; + } + } + } + + private static String callURL(String urlStr) { + StringBuilder sb = new StringBuilder(); + URLConnection urlConn; + InputStreamReader in; + try { + URL url = new URL(urlStr); + urlConn = url.openConnection(); + if (urlConn != null) { + urlConn.setReadTimeout(60 * 1000); + } + if (urlConn != null && urlConn.getInputStream() != null) { + in = new InputStreamReader(urlConn.getInputStream(), + Charset.defaultCharset()); + BufferedReader bufferedReader = new BufferedReader(in); + int cp; + while ((cp = bufferedReader.read()) != -1) { + sb.append((char) cp); + } + bufferedReader.close(); + in.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sb.toString(); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index 513ac16..8112f74 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -3,10 +3,13 @@ package net.tylermurphy.hideAndSeek.util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import java.io.*; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.UUID; +import com.google.common.io.ByteStreams; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.LocalizationString; @@ -92,4 +95,22 @@ public class Util { for(ItemStack i : player.getInventory().getContents()) if(hi.isSimilar(i)) player.getInventory().remove(i); } + + public static InputStream convertUniqueId(UUID uuid) { + byte[] bytes = new byte[16]; + ByteBuffer.wrap(bytes) + .putLong(uuid.getMostSignificantBits()) + .putLong(uuid.getLeastSignificantBits()); + return new ByteArrayInputStream(bytes); + } + + public static UUID convertBinaryStream(InputStream stream) { + ByteBuffer buffer = ByteBuffer.allocate(16); + try { + buffer.put(ByteStreams.toByteArray(stream)); + buffer.flip(); + return new UUID(buffer.getLong(), buffer.getLong()); + } catch (IOException e) {} + return null; + } } \ No newline at end of file diff --git a/src/main/resources/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index c5b0b72..c17fafe 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -60,7 +60,8 @@ Localization: BOUNDS_WRONG_WORLD: "Führe diesen Befehl bitte in der Spielwelt aus." BOUNDS: "Grenzen erfolgreich an dieser Position gesetzt. ({AMOUNT}/2)" NOT_AT_ZERO: "Bitte nicht an einer Position setzen, die eine Koordinate bei 0 enthält." - + NO_GAME_INFO: "Der Spieler hat keine Gameplay-Informationen." + INFORMATION_FOR: "Gewinninformationen für {PLAYER}" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 2 type: "de-DE" diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index af5b80c..977f69b 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -60,6 +60,8 @@ Localization: BOUNDS_WRONG_WORLD: "Please run this command in the game world." BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." + NO_GAME_INFO: "Player has no gameplay information." + INFORMATION_FOR: "Win information for {PLAYER}:" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 2 From 1617bfe44ab2fc2112ee5cc6fa082b7981222c64 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 26 Dec 2021 16:58:18 -0600 Subject: [PATCH 08/16] 1.3.3 beta 3 --- .../net/tylermurphy/hideAndSeek/Main.java | 56 +- .../hideAndSeek/command/About.java | 2 +- .../tylermurphy/hideAndSeek/command/Help.java | 10 +- .../hideAndSeek/command/ICommand.java | 10 +- .../tylermurphy/hideAndSeek/command/Join.java | 28 +- .../hideAndSeek/command/Leave.java | 24 +- .../hideAndSeek/command/Reload.java | 6 +- .../hideAndSeek/command/SaveMap.java | 14 +- .../hideAndSeek/command/SetBorder.java | 11 +- .../hideAndSeek/command/SetBounds.java | 6 +- .../hideAndSeek/command/SetExitLocation.java | 16 +- .../hideAndSeek/command/SetLobbyLocation.java | 16 +- .../hideAndSeek/command/SetSpawnLocation.java | 22 +- .../hideAndSeek/command/Setup.java | 10 +- .../hideAndSeek/command/Start.java | 43 +- .../tylermurphy/hideAndSeek/command/Stop.java | 15 +- .../tylermurphy/hideAndSeek/command/Top.java | 13 +- .../tylermurphy/hideAndSeek/command/Wins.java | 15 +- .../configuration/ConfigManager.java | 42 +- .../configuration/Localization.java | 2 +- .../configuration/LocalizationString.java | 75 ++- .../hideAndSeek/database/Database.java | 32 +- .../hideAndSeek/database/PlayerInfoTable.java | 33 +- .../tylermurphy/hideAndSeek/events/Glow.java | 65 --- .../tylermurphy/hideAndSeek/events/Taunt.java | 101 ---- .../hideAndSeek/events/Worldborder.java | 74 --- .../tylermurphy/hideAndSeek/game/Board.java | 351 +++++++++++++ .../{util => game}/CommandHandler.java | 9 +- .../hideAndSeek/game/EventListener.java | 72 +-- .../tylermurphy/hideAndSeek/game/Game.java | 492 +++++++++++++----- .../tylermurphy/hideAndSeek/util/Board.java | 249 --------- .../hideAndSeek/util/CustomBoard.java | 121 ----- .../tylermurphy/hideAndSeek/util/Packet.java | 2 +- .../hideAndSeek/{game => util}/Status.java | 2 +- .../hideAndSeek/util/TabCompleter.java | 8 +- .../hideAndSeek/util/UUIDFetcher.java | 3 + .../tylermurphy/hideAndSeek/util/Util.java | 116 ----- .../hideAndSeek/{game => util}/WinType.java | 2 +- .../hideAndSeek/world/WorldLoader.java | 41 +- 39 files changed, 1056 insertions(+), 1153 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/game/Board.java rename src/main/java/net/tylermurphy/hideAndSeek/{util => game}/CommandHandler.java (88%) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Board.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java rename src/main/java/net/tylermurphy/hideAndSeek/{game => util}/Status.java (60%) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Util.java rename src/main/java/net/tylermurphy/hideAndSeek/{game => util}/WinType.java (60%) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index b9aaa94..12b4f77 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -1,91 +1,55 @@ package net.tylermurphy.hideAndSeek; -import static net.tylermurphy.hideAndSeek.configuration.Config.spawnWorld; - import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; import net.tylermurphy.hideAndSeek.database.Database; -import net.tylermurphy.hideAndSeek.game.Status; import net.tylermurphy.hideAndSeek.util.UUIDFetcher; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -import net.tylermurphy.hideAndSeek.util.CommandHandler; +import net.tylermurphy.hideAndSeek.game.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.util.Board; -import net.tylermurphy.hideAndSeek.world.WorldLoader; +import net.tylermurphy.hideAndSeek.game.Board; public class Main extends JavaPlugin implements Listener { public static Main plugin; public static File root, data; - - public Game game; - public Board board; - public WorldLoader worldLoader; - public Status status = Status.STANDBY; - public Database database; private BukkitTask onTickTask; public void onEnable() { - plugin = this; - - // Setup Event Listener - getServer().getPluginManager().registerEvents(new EventListener(), this); - - // Get Data Folder root = this.getServer().getWorldContainer(); data = this.getDataFolder(); - - // Init Configuration + getServer().getPluginManager().registerEvents(new EventListener(), this); + Config.loadConfig(); Localization.loadLocalization(); Items.loadItems(); - - // Create World Loader - worldLoader = new WorldLoader(spawnWorld); - - // Register Commands + CommandHandler.registerCommands(); - - //Board - board = new Board(); - board.reload(); - - //Database - database = new Database(); - database.init(); - - //UUIDFetcher Cache + Board.reload(); + Database.init(); UUIDFetcher.init(); - //Init game - game = new Game(); - - // Start Tick Timer onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> { try{ - game.onTick(); + Game.onTick(); } catch (Exception e) { e.printStackTrace(); } },0,1); - } public void onDisable() { @@ -95,11 +59,11 @@ public class Main extends JavaPlugin implements Listener { } public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) { - return CommandHandler.handleCommand(sender, cmd, label, args); + return CommandHandler.handleCommand(sender, args); } public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { - return TabCompleter.handleTabComplete(sender, command, label, args); + return TabCompleter.handleTabComplete(sender, args); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java 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(); + String getLabel(); + + String getUsage(); - public 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; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 11caa96..669f729 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -11,17 +11,20 @@ import java.util.Map; public class ConfigManager { - private File file; + private final File file; private YamlConfiguration config,defaultConfig; private String defaultFilename; public ConfigManager(String filename){ - this.file = new File(Main.plugin.getDataFolder(), filename); + this.file = new File(Main.data, filename); this.defaultFilename = file.getName(); - File folder = Main.plugin.getDataFolder(); - if(!folder.exists()) - folder.mkdirs(); + File folder = Main.data; + if(!folder.exists()){ + if(!folder.mkdirs()){ + throw new RuntimeException("Failed to make directory: " + file.getPath()); + } + } if(!file.exists()){ saveDefaultConfiguration(); @@ -30,18 +33,21 @@ public class ConfigManager { this.config = YamlConfiguration.loadConfiguration(file); InputStream input = Main.plugin.getResource(file.getName()); + if(input == null){ + throw new RuntimeException("Could not create input stream for "+file.getPath()); + } InputStreamReader reader = new InputStreamReader(input); this.defaultConfig = YamlConfiguration.loadConfiguration(reader); try{ input.close(); reader.close(); - } catch (IOException e){} + } catch (IOException ignored){} } public ConfigManager(String filename, String defaultFilename){ this.defaultFilename = defaultFilename; - this.file = new File(Main.plugin.getDataFolder(), filename); + this.file = new File(Main.data, filename); if(!file.exists()){ saveDefaultConfiguration(); @@ -50,6 +56,9 @@ public class ConfigManager { this.config = YamlConfiguration.loadConfiguration(file); InputStream input = Main.plugin.getResource(defaultFilename); + if(input == null){ + throw new RuntimeException("Could not create input stream for "+defaultFilename); + } InputStreamReader reader = new InputStreamReader(input); this.defaultConfig = YamlConfiguration.loadConfiguration(reader); try{ @@ -65,6 +74,9 @@ public class ConfigManager { private void saveDefaultConfiguration(){ try{ InputStream input = Main.plugin.getResource(defaultFilename); + if(input == null){ + throw new RuntimeException("Could not create input stream for "+defaultFilename); + } java.nio.file.Files.copy(input, file.toPath()); input.close(); } catch(IOException e){ @@ -72,10 +84,6 @@ public class ConfigManager { } } - public void addToConfig(String path, Object value) { - config.set(path, value); - } - public double getDouble(String path){ double value = config.getDouble(path); if(value == 0.0D){ @@ -111,6 +119,9 @@ public class ConfigManager { this.defaultFilename = newDefaultFilename; InputStream input = Main.plugin.getResource(defaultFilename); + if(input == null){ + throw new RuntimeException("Could not create input stream for "+defaultFilename); + } InputStreamReader reader = new InputStreamReader(input); this.config = YamlConfiguration.loadConfiguration(reader); this.defaultConfig = YamlConfiguration.loadConfiguration(reader); @@ -119,7 +130,7 @@ public class ConfigManager { public boolean getBoolean(String path){ boolean value = config.getBoolean(path); - if(value == false){ + if(!value){ return defaultConfig.getBoolean(path); } else { return true; @@ -142,9 +153,12 @@ public class ConfigManager { public void saveConfig(){ try { InputStream is = Main.plugin.getResource(defaultFilename); + if(is == null){ + throw new RuntimeException("Could not create input stream for "+defaultFilename); + } StringBuilder textBuilder = new StringBuilder(); Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name()))); - int c = 0; + int c; while((c = reader.read()) != -1){ textBuilder.append((char) c); } @@ -165,7 +179,7 @@ public class ConfigManager { i++; if(index == -1) break; } - if(index < 10) continue;; + if(index < 10) continue; int start = yamlString.indexOf(' ', index); int end = yamlString.indexOf('\n', index); if(end == -1) end = yamlString.length(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 05d7fb6..327af24 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -10,7 +10,7 @@ public class Localization { public static final Map LOCAL = new HashMap<>(); - private static String[][] CHANGES = {{"WORLDBORDER_DECREASING"}}; + private static final String[][] CHANGES = {{"WORLDBORDER_DECREASING"}}; public static void loadLocalization() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java index fd0e020..b457622 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java @@ -1,48 +1,37 @@ package net.tylermurphy.hideAndSeek.configuration; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; public class LocalizationString { - - String message; - - public LocalizationString(String message) { - this.message = message; - } - - public LocalizationString addPlayer(Entity player) { - this.message = message.replaceFirst("\\{PLAYER\\}", player.getName()); - return this; - } - - public LocalizationString addPlayer(CommandSender player) { - this.message = message.replaceFirst("\\{PLAYER\\}", player.getName()); - return this; - } - - public LocalizationString addPlayer(String player) { - this.message = message.replaceFirst("\\{PLAYER\\}", player); - return this; - } - - public LocalizationString addAmount(Integer value) { - this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString()); - return this; - } - - public LocalizationString addAmount(String value) { - this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString()); - return this; - } - - public LocalizationString addAmount(Float value) { - this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString()); - return this; - } - - public String toString() { - return message; - } - -} + + String message; + + public LocalizationString(String message) { + this.message = message; + } + + public LocalizationString addPlayer(Entity player) { + this.message = message.replaceFirst("\\{PLAYER}", player.getName()); + return this; + } + + public LocalizationString addPlayer(String player) { + this.message = message.replaceFirst("\\{PLAYER}", player); + return this; + } + + public LocalizationString addAmount(Integer value) { + this.message = message.replaceFirst("\\{AMOUNT}", value.toString()); + return this; + } + + public LocalizationString addAmount(String value) { + this.message = message.replaceFirst("\\{AMOUNT}", value); + return this; + } + + public String toString() { + return message; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java index 2254ec2..9d3cc73 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -1,19 +1,25 @@ package net.tylermurphy.hideAndSeek.database; +import com.google.common.io.ByteStreams; import net.tylermurphy.hideAndSeek.Main; +import java.io.ByteArrayInputStream; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.util.UUID; public class Database { - private final File databaseFile = new File(Main.data, "database.db"); + private static final File databaseFile = new File(Main.data, "database.db"); - public PlayerInfoTable playerInfo; + public static PlayerInfoTable playerInfo; - protected Connection connect() { + protected static Connection connect() { Connection conn = null; try { String url = "jdbc:sqlite:"+databaseFile; @@ -24,7 +30,25 @@ public class Database { return conn; } - public void init(){ + protected static InputStream convertUniqueId(UUID uuid) { + byte[] bytes = new byte[16]; + ByteBuffer.wrap(bytes) + .putLong(uuid.getMostSignificantBits()) + .putLong(uuid.getLeastSignificantBits()); + return new ByteArrayInputStream(bytes); + } + + protected static UUID convertBinaryStream(InputStream stream) { + ByteBuffer buffer = ByteBuffer.allocate(16); + try { + buffer.put(ByteStreams.toByteArray(stream)); + buffer.flip(); + return new UUID(buffer.getLong(), buffer.getLong()); + } catch (IOException ignored) {} + return null; + } + + public static void init(){ playerInfo = new PlayerInfoTable(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java index 07fb2ee..0dba4b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java @@ -1,8 +1,7 @@ package net.tylermurphy.hideAndSeek.database; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.game.WinType; -import net.tylermurphy.hideAndSeek.util.Util; +import net.tylermurphy.hideAndSeek.util.WinType; import java.io.IOException; import java.io.InputStream; @@ -23,7 +22,7 @@ public class PlayerInfoTable { + " games_played int NOT NULL\n" + ");"; - try(Connection connection = Main.plugin.database.connect(); Statement statement = connection.createStatement()){ + try(Connection connection = Database.connect(); Statement statement = connection.createStatement()){ statement.execute(sql); } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); @@ -32,21 +31,22 @@ public class PlayerInfoTable { public PlayerInfo getInfo(UUID uuid){ String sql = "SELECT * FROM player_info WHERE uuid = ?;"; - try(Connection connection = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ - InputStream is = Util.convertUniqueId(uuid); + try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + InputStream is = Database.convertUniqueId(uuid); byte[] bytes = new byte[is.available()]; - is.read(bytes); + if(is.read(bytes) == -1){ + throw new IOException("Failed to read bytes from input stream"); + } statement.setBytes(1, bytes); ResultSet rs = statement.executeQuery(); if(rs.next()){ - PlayerInfo info = new PlayerInfo( + return new PlayerInfo( uuid, rs.getInt("wins"), rs.getInt("seeker_wins"), rs.getInt("hider_wins"), rs.getInt("games_played") ); - return info; } } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); @@ -59,13 +59,13 @@ public class PlayerInfoTable { public List getInfoPage(int page){ String sql = "SELECT * FROM player_info ORDER BY wins DESC LIMIT 10 OFFSET ?;"; - try(Connection connection = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ statement.setInt(1, (page-1)*10); ResultSet rs = statement.executeQuery(); List infoList = new ArrayList<>(); while(rs.next()){ PlayerInfo info = new PlayerInfo( - Util.convertBinaryStream(rs.getBinaryStream("uuid")), + Database.convertBinaryStream(rs.getBinaryStream("uuid")), rs.getInt("wins"), rs.getInt("seeker_wins"), rs.getInt("hider_wins"), @@ -80,14 +80,16 @@ public class PlayerInfoTable { return null; } - public boolean addWins(List uuids, List winners, WinType type){ + public void addWins(List uuids, List winners, WinType type){ for(UUID uuid : uuids){ String sql = "INSERT OR REPLACE INTO player_info (uuid, wins, seeker_wins, hider_wins, games_played) VALUES (?,?,?,?,?)"; PlayerInfo info = getInfo(uuid); - try(Connection connection = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ - InputStream is = Util.convertUniqueId(uuid); + try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){ + InputStream is = Database.convertUniqueId(uuid); byte[] bytes = new byte[is.available()]; - is.read(bytes); + if(is.read(bytes) == -1){ + throw new IOException("Failed to read bytes from input stream"); + } statement.setBytes(1, bytes); statement.setInt(2, info.wins + (winners.contains(uuid) ? 1 : 0)); statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0)); @@ -97,13 +99,12 @@ public class PlayerInfoTable { } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); e.printStackTrace(); - return false; + return; } catch (IOException e) { Main.plugin.getLogger().severe("IO Error: " + e.getMessage()); e.printStackTrace(); } } - return true; } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java deleted file mode 100644 index 139d8b4..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java +++ /dev/null @@ -1,65 +0,0 @@ -package net.tylermurphy.hideAndSeek.events; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Packet; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -public class Glow { - - private final int temp; - private int glowTime; - private boolean running; - - public Glow(int temp) { - this.temp = temp; - this.glowTime = 0; - } - - public void onProjectile() { - if(glowStackable) glowTime += glowLength; - else glowTime = glowLength; - if(!running) - startGlow(); - } - - private void startGlow() { - running = true; - for(Player hider : Main.plugin.board.getHiders()) { - for(Player seeker : Main.plugin.board.getSeekers()) { - Packet.setGlow(hider, seeker, true); - } - } - waitGlow(); - } - - private void waitGlow() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(temp != Main.plugin.game.gameId) return; - glowTime--; - glowTime = Math.max(glowTime, 0); - if(glowTime == 0) { - stopGlow(); - } else { - waitGlow(); - } - }, 20); - } - - private void stopGlow() { - running = false; - for(Player hider : Main.plugin.board.getHiders()) { - for (Player seeker : Main.plugin.board.getSeekers()) { - Packet.setGlow(hider, seeker, false); - } - } - } - - public boolean isRunning() { - return running; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java deleted file mode 100644 index af9097e..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java +++ /dev/null @@ -1,101 +0,0 @@ -package net.tylermurphy.hideAndSeek.events; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Firework; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.FireworkMeta; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Util; -import static net.tylermurphy.hideAndSeek.configuration.Localization.*; - -public class Taunt { - - private final int temp; - private String tauntPlayer; - private int delay; - private boolean running; - - public Taunt(int temp) { - this.temp = temp; - this.delay = 0; - } - - public void schedule() { - delay = tauntDelay; - waitTaunt(); - } - - private void waitTaunt() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(delay == 0) { - if(!tauntLast && Main.plugin.board.size() < 2) return; - else executeTaunt(); - } else { - delay--; - waitTaunt(); - } - },20); - } - - private void executeTaunt() { - 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()) { - if(Main.plugin.board.isHider(player)) { - rand--; - if(rand==0) { - taunted = player; - break; - } - } - } - if(taunted != null) { - running = true; - taunted.sendMessage(message("TAUNTED").toString()); - Util.broadcastMessage(tauntPrefix + message("TAUNT")); - tauntPlayer = taunted.getName(); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - 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); - FireworkMeta fwm = fw.getFireworkMeta(); - fwm.setPower(4); - fwm.addEffect(FireworkEffect.builder() - .withColor(Color.BLUE) - .withColor(Color.RED) - .withColor(Color.YELLOW) - .with(FireworkEffect.Type.STAR) - .with(FireworkEffect.Type.BALL) - .with(FireworkEffect.Type.BALL_LARGE) - .flicker(true) - .withTrail() - .build()); - fw.setFireworkMeta(fwm); - Util.broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); - } - tauntPlayer = ""; - running = false; - schedule(); - },20*30); - } else { - schedule(); - } - } - - public int getDelay(){ - return delay; - } - - public boolean isRunning() { - return running; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java deleted file mode 100644 index a6f97f8..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.tylermurphy.hideAndSeek.events; - -import static net.tylermurphy.hideAndSeek.configuration.Localization.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldBorder; - -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.Util; - -public class Worldborder { - - private final int temp; - private int delay; - private boolean running; - - public Worldborder(int temp) { - this.temp = temp; - } - - public void schedule() { - delay = 60*worldborderDelay; - running = false; - waitBorder(); - } - - private void waitBorder(){ - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { - if(delay == 0) decreaceWorldborder(); - else { - delay--; waitBorder(); - } - }, 20); - } - - private void decreaceWorldborder() { - if(temp != Main.plugin.game.gameId) return; - if(currentWorldborderSize-100 > 100) { - running = true; - Util.broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING")); - currentWorldborderSize -= 100; - World world = Bukkit.getWorld("hideandseek_"+spawnWorld); - WorldBorder border = world.getWorldBorder(); - border.setSize(border.getSize()-100,30); - schedule(); - } - } - - public static void resetWorldborder(String worldName) { - if(worldborderEnabled) { - World world = Bukkit.getWorld(worldName); - WorldBorder border = world.getWorldBorder(); - border.setSize(worldborderSize); - border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); - currentWorldborderSize = worldborderSize; - } else { - World world = Bukkit.getWorld(worldName); - WorldBorder border = world.getWorldBorder(); - border.setSize(30000000); - border.setCenter(0, 0); - } - } - - public int getDelay(){ - return delay; - } - - public boolean isRunning() { - return running; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java new file mode 100644 index 0000000..44e3f05 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -0,0 +1,351 @@ +package net.tylermurphy.hideAndSeek.game; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import net.tylermurphy.hideAndSeek.util.Status; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.*; + +public class Board { + + private static final List Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); + private static final Map playerList = new HashMap<>(); + private static final Map customBoards = new HashMap<>(); + + public static boolean isPlayer(Player player) { + return playerList.containsKey(player.getName()); + } + + public static boolean isPlayer(CommandSender sender) { + return playerList.containsKey(sender.getName()); + } + + public static boolean isHider(Player player) { + return Hider.contains(player.getName()); + } + + public static boolean isSeeker(Player player) { + return Seeker.contains(player.getName()); + } + + public static boolean isSpectator(Player player) { + return Spectator.contains(player.getName()); + } + + public static int sizeHider() { + return Hider.size(); + } + + public static int sizeSeeker() { + return Seeker.size(); + } + + public static int size() { + return playerList.values().size(); + } + + public static List getHiders(){ + return Hider.stream().map(playerList::get).collect(Collectors.toList()); + } + + public static List getSeekers(){ + return Seeker.stream().map(playerList::get).collect(Collectors.toList()); + } + + public static Player getFirstSeeker(){ + return playerList.get(Seeker.get(0)); + } + + public static List getSpectators(){ + return Spectator.stream().map(playerList::get).collect(Collectors.toList()); + } + + public static List getPlayers(){ + return new ArrayList<>(playerList.values()); + } + + public static Player getPlayer(String name) { + return playerList.get(name); + } + + public static void addHider(Player player) { + Hider.add(player.getName()); + Seeker.remove(player.getName()); + Spectator.remove(player.getName()); + playerList.put(player.getName(), player); + } + + public static void addSeeker(Player player) { + Hider.remove(player.getName()); + Seeker.add(player.getName()); + Spectator.remove(player.getName()); + playerList.put(player.getName(), player); + } + + public static void addSpectator(Player player) { + Hider.remove(player.getName()); + Seeker.remove(player.getName()); + Spectator.add(player.getName()); + playerList.put(player.getName(), player); + } + + public static void remove(Player player) { + Hider.remove(player.getName()); + Seeker.remove(player.getName()); + Spectator.remove(player.getName()); + playerList.remove(player.getName()); + } + + public static boolean onSameTeam(Player player1, Player player2) { + if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true; + else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true; + else return Spectator.contains(player1.getName()) && Spectator.contains(player2.getName()); + } + + public static void reload() { + Hider.clear(); + Seeker.clear(); + Spectator.clear(); + } + + public static void createLobbyBoard(Player player) { + createLobbyBoard(player, true); + } + + private static void createLobbyBoard(Player player, boolean recreate) { + 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 + "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(); + if(lobbyCountdownEnabled){ + if(Game.countdownTime == -1){ + board.setLine("waiting", "Waiting for players..."); + } else { + board.setLine("waiting", "Starting in: "+ChatColor.GREEN + Game.countdownTime+"s"); + } + } else { + board.setLine("waiting", "Waiting for gamemaster..."); + } + board.display(); + customBoards.put(player.getName(), board); + } + + public static void createGameBoard(Player player){ + createGameBoard(player, true); + } + + private static void createGameBoard(Player player, boolean recreate){ + 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(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) + board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); + else + board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); + } + if(tauntEnabled && tauntCountdown){ + if(Game.taunt == null || Game.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(!Game.taunt.isRunning()) + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Game.taunt.getDelay()/60 + "m" + Game.taunt.getDelay()%60 + "s"); + else + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); + } + if(worldborderEnabled){ + if(Game.worldBorder == null || Game.status == Status.STARTING){ + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); + } else if(!Game.worldBorder.isRunning()) { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Game.worldBorder.getDelay()/60 + "m" + 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 + Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s"); + board.addBlank(); + board.setLine("team", "Team: " + getTeam(player)); + board.display(); + customBoards.put(player.getName(), board); + } + + public static void removeBoard(Player player) { + ScoreboardManager manager = Bukkit.getScoreboardManager(); + assert manager != null; + player.setScoreboard(manager.getMainScoreboard()); + customBoards.remove(player.getName()); + } + + public static void reloadLobbyBoards() { + for(Player player : playerList.values()) + createLobbyBoard(player, false); + } + + public static void reloadGameBoards() { + for(Player player : playerList.values()) + createGameBoard(player, false); + } + + public static void reloadBoardTeams() { + for(CustomBoard board : customBoards.values()) + board.updateTeams(); + } + + private static String getSeekerPercent() { + if(playerList.values().size() < 2) + return " --"; + else + return " "+(int)(100*(1.0/playerList.size())); + } + + private static String getHiderPercent() { + if(playerList.size() < 2) + return " --"; + else + return " "+(int)(100-100*(1.0/playerList.size())); + } + + private static String getTeam(Player player) { + if(isHider(player)) return ChatColor.GOLD + "HIDER"; + else if(isSeeker(player)) return ChatColor.RED + "SEEKER"; + else if(isSpectator(player)) return ChatColor.GRAY + "SPECTATOR"; + else return ChatColor.WHITE + "UNKNOWN"; + } + +} + +class CustomBoard { + + private final Scoreboard board; + private final Objective obj; + private final Player player; + private final Map LINES; + private int blanks; + private boolean displayed; + + public CustomBoard(Player player, String title){ + ScoreboardManager manager = Bukkit.getScoreboardManager(); + assert manager != null; + this.board = manager.getNewScoreboard(); + this.LINES = new HashMap<>(); + this.player = player; + this.obj = board.registerNewObjective( + "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); + this.blanks = 0; + this.displayed = false; + this.updateTeams(); + } + + public void updateTeams() { + try{ board.registerNewTeam("Hider"); } catch (Exception ignored){} + try{ board.registerNewTeam("Seeker"); } catch (Exception ignored){} + Team hiderTeam = board.getTeam("Hider"); + assert hiderTeam != null; + for(String entry : hiderTeam.getEntries()) + hiderTeam.removeEntry(entry); + for(Player player : Board.getHiders()) + hiderTeam.addEntry(player.getName()); + Team seekerTeam = board.getTeam("Seeker"); + assert seekerTeam != null; + for(String entry : seekerTeam.getEntries()) + seekerTeam.removeEntry(entry); + for(Player player : Board.getSeekers()) + seekerTeam.addEntry(player.getName()); + if(nametagsVisible) { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS); + } else { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + } + hiderTeam.setColor(ChatColor.GOLD); + seekerTeam.setColor(ChatColor.RED); + } + + public void setLine(String key, String message){ + Line line = LINES.get(key); + if(line == null) + addLine(key, message); + else + updateLine(key, message); + } + + private void addLine(String key, String message){ + Score score = obj.getScore(message); + score.setScore(LINES.values().size()+1); + Line line = new Line(LINES.values().size()+1, message); + LINES.put(key, line); + } + + public void addBlank(){ + if(displayed) return; + StringBuilder temp = new StringBuilder(); + for(int i = 0; i <= blanks; i ++) + temp.append(ChatColor.RESET); + blanks++; + addLine("blank"+blanks, temp.toString()); + } + + private void updateLine(String key, String message){ + Line line = LINES.get(key); + board.resetScores(line.getMessage()); + line.setMessage(message); + Score newScore = obj.getScore(message); + + newScore.setScore(line.getScore()); + } + + public void display() { + displayed = true; + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + player.setScoreboard(board); + } + +} + +class Line { + + private final int score; + private String message; + + public Line(int score, String message){ + this.score = score; + this.message = message; + } + + public int getScore() { + return score; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java similarity index 88% rename from src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java rename to src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java index e66f7ed..6758908 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java @@ -1,15 +1,12 @@ -package net.tylermurphy.hideAndSeek.util; +package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -17,7 +14,7 @@ import net.tylermurphy.hideAndSeek.command.*; public class CommandHandler { - public static Map COMMAND_REGISTER = new LinkedHashMap(); + public static Map COMMAND_REGISTER = new LinkedHashMap<>(); private static void registerCommand(ICommand command) { if(!COMMAND_REGISTER.containsKey(command.getLabel())) { @@ -44,7 +41,7 @@ public class CommandHandler { registerCommand(new Wins()); } - public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { + public static boolean handleCommand(CommandSender sender, String[] args) { if(!(sender instanceof Player)) { sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY")); } else if(args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 60c7132..dc79732 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -3,6 +3,7 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import net.tylermurphy.hideAndSeek.command.Join; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Entity; @@ -20,19 +21,19 @@ import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.*; import net.tylermurphy.hideAndSeek.util.Packet; -import net.tylermurphy.hideAndSeek.util.Util; -import net.tylermurphy.hideAndSeek.Main; import org.bukkit.potion.PotionEffect; +import java.util.Objects; + import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - Main.plugin.board.remove(event.getPlayer()); - Util.removeItems(event.getPlayer()); - if(!Util.isSetup()) return; + Board.remove(event.getPlayer()); + Game.removeItems(event.getPlayer()); + if(Game.isNotSetup()) return; if(autoJoin){ Join.join(event.getPlayer()); } else if(teleportToExit) { @@ -50,44 +51,45 @@ public class EventListener implements Listener { @EventHandler public void onQuit(PlayerQuitEvent event) { - Main.plugin.board.remove(event.getPlayer()); - if(Main.plugin.status == Status.STANDBY) { - Main.plugin.board.reloadLobbyBoards(); + Board.remove(event.getPlayer()); + if(Game.status == Status.STANDBY) { + Board.reloadLobbyBoards(); } else { - Main.plugin.board.reloadGameBoards(); + Board.reloadGameBoards(); } for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ event.getPlayer().removePotionEffect(effect.getType()); } - Util.removeItems(event.getPlayer()); + Game.removeItems(event.getPlayer()); } @EventHandler public void onKick(PlayerKickEvent event) { - Main.plugin.board.remove(event.getPlayer()); - if(Main.plugin.status == Status.STANDBY) { - Main.plugin.board.reloadLobbyBoards(); + Board.remove(event.getPlayer()); + if(Game.status == Status.STANDBY) { + Board.reloadLobbyBoards(); } else { - Main.plugin.board.reloadGameBoards(); + Board.reloadGameBoards(); } for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ event.getPlayer().removePotionEffect(effect.getType()); } - Util.removeItems(event.getPlayer()); + Game.removeItems(event.getPlayer()); } @EventHandler public void onChat(AsyncPlayerChatEvent event){ - if(Main.plugin.board.isSeeker(event.getPlayer())){ + if(Board.isSeeker(event.getPlayer())){ event.setCancelled(true); - Main.plugin.board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage())); + Board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage())); } } @EventHandler public void onMove(PlayerMoveEvent event){ - if(!event.getPlayer().getWorld().equals("hideandseek_" + spawnWorld)) return; + if(!event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return; + if(event.getTo() == null || event.getTo().getWorld() == null) return; if(!event.getTo().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; if(event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMinX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){ event.setCancelled(true); @@ -99,8 +101,8 @@ public class EventListener implements Listener { try { if (event.getEntity() instanceof Player) { Player p = (Player) event.getEntity(); - if (!Main.plugin.board.isPlayer(p)) return; - if (Main.plugin.status != Status.PLAYING) { + if (!Board.isPlayer(p)) return; + if (Game.status != Status.PLAYING) { event.setCancelled(true); return; } @@ -109,30 +111,30 @@ public class EventListener implements Listener { Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); if (damager instanceof Player) { attacker = (Player) damager; - if (Main.plugin.board.onSameTeam(p, attacker)) event.setCancelled(true); - if (Main.plugin.board.isSpectator(p)) event.setCancelled(true); + if (Board.onSameTeam(p, attacker)) event.setCancelled(true); + if (Board.isSpectator(p)) event.setCancelled(true); } } Player player = (Player) event.getEntity(); if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) { if (spawnPosition == null) return; event.setCancelled(true); - player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()); player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); - if (Main.plugin.board.isSeeker(player)) { + if (Board.isSeeker(player)) { Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString()); } - if (Main.plugin.board.isHider(player)) { + if (Board.isHider(player)) { if (attacker == null) { - Util.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString()); + Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString()); } else { - Util.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString()); + Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString()); } - Main.plugin.board.addSeeker(player); + Board.addSeeker(player); } - Util.resetPlayer(player); - Main.plugin.board.reloadBoardTeams(); + Game.resetPlayer(player); + Board.reloadBoardTeams(); } } } catch (Exception e){ @@ -142,14 +144,14 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onProjectile(ProjectileLaunchEvent event) { - if(Main.plugin.status != Status.PLAYING) return; + if(Game.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.game.glow.onProjectile(); + if(Board.isHider(player)) { + Game.glow.onProjectile(); snowball.remove(); player.getInventory().remove(Material.SNOWBALL); } @@ -160,7 +162,7 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onFoodLevelChange(FoodLevelChangeEvent event) { if(event.getEntity() instanceof Player) { - if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return; + if(!Board.isPlayer((Player) event.getEntity())) return; event.setCancelled(true); } } @@ -169,7 +171,7 @@ public class EventListener implements Listener { public void onPlayerRegainHealth(EntityRegainHealthEvent event) { if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) { if(event.getEntity() instanceof Player) { - if(!Main.plugin.board.isPlayer((Player) event.getEntity())) return; + if(!Board.isPlayer((Player) event.getEntity())) return; event.setCancelled(true); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 5af8063..d04d32a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -3,58 +3,64 @@ 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 net.tylermurphy.hideAndSeek.configuration.Items; +import net.tylermurphy.hideAndSeek.database.Database; +import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.util.WinType; +import net.tylermurphy.hideAndSeek.world.WorldLoader; +import org.bukkit.*; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; 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.inventory.ItemStack; +import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.UUID; +import java.io.File; +import java.util.*; import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.game.Game.broadcastMessage; public class Game { - public Taunt taunt; - public Glow glow; - public Worldborder worldborder; + public static Taunt taunt; + public static Glow glow; + public static WorldBorder worldBorder; + public static WorldLoader worldLoader; + public static int tick = 0; + public static int countdownTime = -1; + public static int gameId = 0; + public static int timeLeft = 0; + public static Status status = Status.STANDBY; - private int tick = 0; - public int countdownTime = -1; - public int gameId = 0; - public int timeLeft = 0; + static { + worldLoader = new WorldLoader(spawnWorld); + } - 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(); + public static void start(Player seeker){ + if(status == Status.STARTING || status == Status.PLAYING) return; + if(worldLoader.getWorld() != null) { + worldLoader.rollback(); } else { - Main.plugin.worldLoader.loadMap(); + worldLoader.loadMap(); } - Main.plugin.board.reload(); - for(Player temp : Main.plugin.board.getPlayers()) { + Board.reload(); + for(Player temp : Board.getPlayers()) { if(temp.getName().equals(seeker.getName())) continue; - Main.plugin.board.addHider(temp); + Board.addHider(temp); } - Main.plugin.board.addSeeker(seeker); + Board.addSeeker(seeker); currentWorldborderSize = worldborderSize; - for(Player player : Main.plugin.board.getPlayers()) { + for(Player player : Board.getPlayers()) { player.getInventory().clear(); player.setGameMode(GameMode.ADVENTURE); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); @@ -62,141 +68,178 @@ public class Game { player.removePotionEffect(effect.getType()); } } - for(Player player : Main.plugin.board.getSeekers()) { + for(Player player : 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()) { + for(Player player : 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); - if(gameLength > 0) { - timeLeft = gameLength; + worldBorder.resetWorldborder("hideandseek_"+spawnWorld); + for(Player player : Board.getPlayers()){ + Board.createGameBoard(player); } + Board.reloadGameBoards(); + status = Status.STARTING; + int temp = gameId; + broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30)); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), gameId, 20 * 27); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28); + sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> { - if(temp != Main.plugin.game.gameId) return; - Util.broadcastMessage(messagePrefix + message("START")); - - 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); - } - - Main.plugin.status = Status.PLAYING; + if(temp != gameId) return; + if(gameLength > 0) timeLeft = gameLength; + broadcastMessage(messagePrefix + message("START")); + for(Player player : Board.getPlayers()) resetPlayer(player); + if(worldborderEnabled) worldBorder = new WorldBorder(); + if(tauntEnabled) taunt = new Taunt(); + if (glowEnabled) glow = new Glow(); + status = Status.PLAYING; }, 20 * 30); } - public void stop(WinType type){ - if(Main.plugin.status == Status.STANDBY) return; + public static void stop(WinType type){ + if(status == Status.STANDBY) return; tick = 0; countdownTime = -1; - Main.plugin.status = Status.STANDBY; - Main.plugin.game.gameId++; + status = Status.STANDBY; + gameId++; timeLeft = 0; - List players = Main.plugin.board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList()); + List players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList()); if(type == WinType.HIDER_WIN){ - List winners = Main.plugin.board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList()); - Main.plugin.database.playerInfo.addWins(players, winners, type); + List winners = Board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList()); + Database.playerInfo.addWins(players, winners, type); } else if(type == WinType.SEEKER_WIN){ List winners = new ArrayList<>(); - winners.add(Main.plugin.board.getFirstSeeker().getUniqueId()); - Main.plugin.database.playerInfo.addWins(players, winners, type); + winners.add(Board.getFirstSeeker().getUniqueId()); + Database.playerInfo.addWins(players, winners, type); } - Worldborder.resetWorldborder("hideandseek_"+spawnWorld); - for(Player player : Main.plugin.board.getPlayers()) { - Main.plugin.board.createLobbyBoard(player); + worldBorder.resetWorldborder("hideandseek_"+spawnWorld); + for(Player player : Board.getPlayers()) { + Board.createLobbyBoard(player); player.setGameMode(GameMode.ADVENTURE); - Main.plugin.board.addHider(player); + 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()) { + for(Player temp : Board.getPlayers()) { Packet.setGlow(player, temp, false); } } - Main.plugin.worldLoader.unloadMap(); - Main.plugin.board.reloadLobbyBoards(); + worldLoader.unloadMap(); + 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(WinType.SEEKER_WIN); - } - 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(WinType.NONE); - } + public static boolean isNotSetup() { + if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true; + if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true; + if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true; + File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); + if(!destenation.exists()) return true; + return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0; + } + public static void onTick() { + if(isNotSetup()) return; + if(status == Status.STANDBY) whileWaiting(); + else if(status == Status.STARTING) whileStarting(); + else if(status == Status.PLAYING) whilePlaying(); tick++; - } - private void whileWaiting() { + public static void resetWorldborder(String worldName){ + worldBorder.resetWorldborder(worldName); + } + + public static void broadcastMessage(String message) { + for(Player player : Board.getPlayers()) { + player.sendMessage(message); + } + } + + public static void resetPlayer(Player player) { + player.getInventory().clear(); + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); + } + if (Board.isSeeker(player)) { + if(pvpEnabled) + for(ItemStack item : Items.SEEKER_ITEMS) + player.getInventory().addItem(item); + for(PotionEffect effect : Items.SEEKER_EFFECTS) + player.addPotionEffect(effect); + } else if (Board.isHider(player)) { + if(pvpEnabled) + for(ItemStack item : Items.HIDER_ITEMS) + player.getInventory().addItem(item); + for(PotionEffect effect : Items.HIDER_EFFECTS) + player.addPotionEffect(effect); + if(glowEnabled) { + ItemStack snowball = new ItemStack(Material.SNOWBALL, 1); + ItemMeta snowballMeta = snowball.getItemMeta(); + assert snowballMeta != null; + snowballMeta.setDisplayName("Glow Powerup"); + List snowballLore = new ArrayList<>(); + snowballLore.add("Throw to make all seekers glow"); + snowballLore.add("Last 30s, all hiders can see it"); + snowballLore.add("Time stacks on multi use"); + snowballMeta.setLore(snowballLore); + snowball.setItemMeta(snowballMeta); + player.getInventory().addItem(snowball); + } + } + } + + public static void removeItems(Player player){ + for(ItemStack si : Items.SEEKER_ITEMS) + for(ItemStack i : player.getInventory().getContents()) + if(si.isSimilar(i)) player.getInventory().remove(i); + for(ItemStack hi : Items.HIDER_ITEMS) + for(ItemStack i : player.getInventory().getContents()) + if(hi.isSimilar(i)) player.getInventory().remove(i); + } + + private static void whileWaiting() { if(lobbyCountdownEnabled){ - if(lobbyMin <= Main.plugin.board.size()){ + if(lobbyMin <= Board.size()){ if(countdownTime == -1) countdownTime = countdown; - if(Main.plugin.board.size() >= changeCountdown) + if(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); + 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; + } + String seekerName = rand.get().getName(); + Player seeker = Board.getPlayer(seekerName); start(seeker); } } else { countdownTime = -1; } } + } + private static void whileStarting(){ + checkWinConditions(); } - private void whilePlaying() { - - for(Player hider : Main.plugin.board.getHiders()) { + private static void whilePlaying() { + for(Player hider : Board.getHiders()) { int distance = 100, temp = 100; - for(Player seeker : Main.plugin.board.getSeekers()) { + for(Player seeker : Board.getSeekers()) { try { temp = (int) hider.getLocation().distance(seeker.getLocation()); } catch (Exception e){ @@ -222,19 +265,226 @@ public class Game { 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(); + Board.reloadGameBoards(); timeLeft--; - if(timeLeft < 1) { - if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); - else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); - stop(WinType.HIDER_WIN); - } + } + if(worldborderEnabled) worldBorder.update(); + if(tauntEnabled) taunt.update(); + if (glowEnabled) glow.update(); + } + checkWinConditions(); + } + + private static void checkWinConditions(){ + if(Board.sizeHider() < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); + else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND")); + stop(WinType.SEEKER_WIN); + } else if(Board.sizeSeeker() < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); + else broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT")); + stop(WinType.NONE); + } else if(timeLeft < 1) { + if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); + else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME")); + stop(WinType.HIDER_WIN); + } + } + + private static void sendDelayedMessage(String message, int gameId, int delay) { + Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, () -> { + if(gameId == Game.gameId) + broadcastMessage(message); + }, delay); + } + +} + +class Glow { + + private int glowTime; + private boolean running; + + public Glow() { + this.glowTime = 0; + } + + public void onProjectile() { + if(glowStackable) glowTime += glowLength; + else glowTime = glowLength; + if(!running) + startGlow(); + } + + private void startGlow() { + running = true; + for(Player hider : Board.getHiders()) { + for(Player seeker : Board.getSeekers()) { + Packet.setGlow(hider, seeker, true); } } } + + protected void update() { + if(running) { + glowTime--; + glowTime = Math.max(glowTime, 0); + if (glowTime == 0) { + stopGlow(); + } + } + } + + private void stopGlow() { + running = false; + for(Player hider : Board.getHiders()) { + for (Player seeker : Board.getSeekers()) { + Packet.setGlow(hider, seeker, false); + } + } + } + + public boolean isRunning() { + return running; + } + +} + +class Taunt { + + private String tauntPlayer; + private int delay; + private boolean running; + + public Taunt() { + this.delay = tauntDelay; + } + + protected void update() { + if(delay == 0) { + if(running) launchTaunt(); + else if(tauntLast || Board.size() > 1) executeTaunt(); + } else { + delay--; + delay = Math.max(delay, 0); + } + } + + private void executeTaunt() { + Player taunted = null; + int rand = (int) (Math.random()*Board.sizeHider()); + for(Player player : Board.getPlayers()) { + if(Board.isHider(player)) { + rand--; + if(rand==0) { + taunted = player; + break; + } + } + } + if(taunted != null) { + taunted.sendMessage(message("TAUNTED").toString()); + broadcastMessage(tauntPrefix + message("TAUNT")); + tauntPlayer = taunted.getName(); + running = true; + delay = 30; + } else { + this.delay = tauntDelay; + } + } + + private void launchTaunt(){ + Player taunted1 = Board.getPlayer(tauntPlayer); + if(taunted1 != null) { + World world = taunted1.getLocation().getWorld(); + assert world != null; + Firework fw = (Firework) world.spawnEntity(taunted1.getLocation(), EntityType.FIREWORK); + FireworkMeta fwm = fw.getFireworkMeta(); + fwm.setPower(4); + fwm.addEffect(FireworkEffect.builder() + .withColor(Color.BLUE) + .withColor(Color.RED) + .withColor(Color.YELLOW) + .with(FireworkEffect.Type.STAR) + .with(FireworkEffect.Type.BALL) + .with(FireworkEffect.Type.BALL_LARGE) + .flicker(true) + .withTrail() + .build()); + fw.setFireworkMeta(fwm); + broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); + } + tauntPlayer = ""; + running = false; + delay = tauntDelay; + } + + public int getDelay(){ + return delay; + } + + public boolean isRunning() { + return running; + } + +} + +class WorldBorder { + + private int delay; + private boolean running; + + public WorldBorder() { + delay = 60 * worldborderDelay; + } + + void update(){ + if(delay == 0){ + if(running){ + delay = 60 * worldborderDelay; + running = false; + } + else decreaceWorldborder(); + } + delay--; + } + + private void decreaceWorldborder() { + if(currentWorldborderSize-100 > 100) { + running = true; + broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING")); + currentWorldborderSize -= 100; + World world = Bukkit.getWorld("hideandseek_"+spawnWorld); + assert world != null; + org.bukkit.WorldBorder border = world.getWorldBorder(); + border.setSize(border.getSize()-100,30); + delay = 30; + } + } + + public void resetWorldborder(String worldName) { + World world = Bukkit.getWorld(worldName); + assert world != null; + org.bukkit.WorldBorder border = world.getWorldBorder(); + if(worldborderEnabled) { + border.setSize(worldborderSize); + border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); + currentWorldborderSize = worldborderSize; + } else { + border.setSize(30000000); + border.setCenter(0, 0); + } + } + + public int getDelay(){ + return delay; + } + + public boolean isRunning() { + return running; + } + } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java deleted file mode 100644 index 6b61f16..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ /dev/null @@ -1,249 +0,0 @@ -package net.tylermurphy.hideAndSeek.util; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import java.util.ArrayList; -import java.util.HashMap; -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; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Score; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; -import org.bukkit.scoreboard.Team.Option; -import org.bukkit.scoreboard.Team.OptionStatus; - -import net.tylermurphy.hideAndSeek.Main; - -public class Board { - - private List Hider, Seeker, Spectator; - private Map playerList = new HashMap<>(); - private Map customBoards = new HashMap<>(); - - public boolean isPlayer(Player player) { - return playerList.containsKey(player.getName()); - } - - public boolean isPlayer(CommandSender sender) { - return playerList.containsKey(sender.getName()); - } - - public boolean isHider(Player player) { - return Hider.contains(player.getName()); - } - - public boolean isSeeker(Player player) { - return Seeker.contains(player.getName()); - } - - public boolean isSpectator(Player player) { - return Spectator.contains(player.getName()); - } - - public int sizeHider() { - return Hider.size(); - } - - public int sizeSeeker() { - return Seeker.size(); - } - - public int sizeSpectator() { - return Spectator.size(); - } - - public int size() { - return playerList.values().size(); - } - - public List getHiders(){ - return Hider.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); - } - - public List getSeekers(){ - return Seeker.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); - } - - public Player getFirstSeeker(){ - return playerList.get(Seeker.get(0)); - } - - public List getSpectators(){ - return Spectator.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList()); - } - - public List getPlayers(){ - return new ArrayList(playerList.values()); - } - - public Player getPlayer(String name) { - return playerList.get(name); - } - - public void addHider(Player player) { - Hider.add(player.getName()); - Seeker.remove(player.getName()); - Spectator.remove(player.getName()); - playerList.put(player.getName(), player); - } - - public void addSeeker(Player player) { - Hider.remove(player.getName()); - Seeker.add(player.getName()); - Spectator.remove(player.getName()); - playerList.put(player.getName(), player); - } - - public void addSpectator(Player player) { - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - Spectator.add(player.getName()); - playerList.put(player.getName(), player); - } - - public void remove(Player player) { - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - Spectator.remove(player.getName()); - playerList.remove(player.getName()); - } - - public boolean onSameTeam(Player player1, Player player2) { - if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true; - else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true; - else if(Spectator.contains(player1.getName()) && Spectator.contains(player2.getName())) return true; - else return false; - } - - public void reload() { - Hider = new ArrayList<>(); - Seeker = new ArrayList<>(); - Spectator = new ArrayList<>(); - } - - public void createLobbyBoard(Player player) { - createLobbyBoard(player, true); - } - - private void createLobbyBoard(Player player, boolean recreate) { - 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 + "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(); - 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); - } - - public void createGameBoard(Player player){ - createGameBoard(player, true); - } - - private void createGameBoard(Player player, boolean recreate){ - 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.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.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.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.game.worldborder == null || Main.plugin.status == Status.STARTING){ - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); - } 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.game.timeLeft/60 + "m" + Main.plugin.game.timeLeft%60 + "s"); - board.addBlank(); - board.setLine("team", "Team: " + getTeam(player)); - board.display(); - customBoards.put(player.getName(), board); - } - - public void removeBoard(Player player) { - player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); - customBoards.remove(player.getName()); - } - - public void reloadLobbyBoards() { - for(Player player : playerList.values()) - createLobbyBoard(player, false); - } - - public void reloadGameBoards() { - for(Player player : playerList.values()) - createGameBoard(player, false); - } - - public void reloadBoardTeams() { - for(CustomBoard board : customBoards.values()) - board.updateTeams(); - } - - private String getSeekerPercent() { - if(playerList.values().size() < 2) - return " --"; - else - return " "+(int)(100*(1.0/playerList.size())); - } - - private String getHiderPercent() { - if(playerList.size() < 2) - return " --"; - else - return " "+(int)(100-100*(1.0/playerList.size())); - } - - private String getTeam(Player player) { - if(isHider(player)) return ChatColor.GOLD + "HIDER"; - else if(isSeeker(player)) return ChatColor.RED + "SEEKER"; - else if(isSpectator(player)) return ChatColor.GRAY + "SPECTATOR"; - else return ChatColor.WHITE + "UNKNOWN"; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java deleted file mode 100644 index 69d865a..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java +++ /dev/null @@ -1,121 +0,0 @@ -package net.tylermurphy.hideAndSeek.util; - -import net.tylermurphy.hideAndSeek.Main; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.*; - -import java.util.HashMap; -import java.util.Map; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -public class CustomBoard { - - private final Scoreboard board; - private final Objective obj; - private final Player player; - private final Map LINES; - private int blanks; - private boolean displayed; - - public CustomBoard(Player player, String title){ - this.board = Bukkit.getScoreboardManager().getNewScoreboard(); - this.LINES = new HashMap(); - this.player = player; - this.obj = board.registerNewObjective( - "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); - this.blanks = 0; - this.displayed = false; - this.updateTeams(); - } - - public void updateTeams() { - try{ board.registerNewTeam("Hider"); } catch (Exception e){} - try{ board.registerNewTeam("Seeker"); } catch (Exception e){} - Team hiderTeam = board.getTeam("Hider"); - for(String entry : hiderTeam.getEntries()) - hiderTeam.removeEntry(entry); - for(Player player : Main.plugin.board.getHiders()) - hiderTeam.addEntry(player.getName()); - Team seekerTeam = board.getTeam("Seeker"); - for(String entry : seekerTeam.getEntries()) - seekerTeam.removeEntry(entry); - for(Player player : Main.plugin.board.getSeekers()) - seekerTeam.addEntry(player.getName()); - if(nametagsVisible) { - hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); - seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS); - } else { - hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); - seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); - } - hiderTeam.setColor(ChatColor.GOLD); - seekerTeam.setColor(ChatColor.RED); - } - - public void setLine(String key, String message){ - Line line = LINES.get(key); - if(line == null) - addLine(key, message); - else - updateLine(key, message); - } - - private void addLine(String key, String message){ - Score score = obj.getScore(message); - score.setScore(LINES.values().size()+1); - Line line = new Line(LINES.values().size()+1, message); - LINES.put(key, line); - } - - public void addBlank(){ - if(displayed) return; - String temp = ""; - for(int i = 0; i <= blanks; i ++) - temp += ChatColor.RESET; - blanks++; - addLine("blank"+blanks, temp); - } - - private void updateLine(String key, String message){ - Line line = LINES.get(key); - board.resetScores(line.getMessage()); - line.setMessage(message); - Score newScore = obj.getScore(message); - - newScore.setScore(line.getScore()); - } - - public void display() { - displayed = true; - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - player.setScoreboard(board); - } - -} - -class Line { - - private int score; - private String message; - - public Line(int score, String message){ - this.score = score; - this.message = message; - } - - public int getScore() { - return score; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java index 564916a..43a358c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java @@ -16,7 +16,7 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; public class Packet { - private static ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); + private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); public static void playSound(Player player, Sound sound, float volume, float pitch) { PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java similarity index 60% rename from src/main/java/net/tylermurphy/hideAndSeek/game/Status.java rename to src/main/java/net/tylermurphy/hideAndSeek/util/Status.java index 92a16a6..76c691f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.game; +package net.tylermurphy.hideAndSeek.util; public enum Status { STANDBY, diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java index 667f597..21fe555 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java @@ -5,14 +5,14 @@ import java.util.List; import java.util.Locale; import java.util.stream.Collectors; -import org.bukkit.command.Command; +import net.tylermurphy.hideAndSeek.game.CommandHandler; import org.bukkit.command.CommandSender; public class TabCompleter{ - public static List handleTabComplete(CommandSender sender, Command command, String label, String[] args) { + public static List handleTabComplete(CommandSender sender, String[] args) { if(args.length == 1) { - return new ArrayList(CommandHandler.COMMAND_REGISTER.keySet()) + return new ArrayList<>(CommandHandler.COMMAND_REGISTER.keySet()) .stream() .filter(handle -> sender.hasPermission("hideandseek."+handle.toLowerCase()) && handle.toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT))) .collect(Collectors.toList()); @@ -26,7 +26,7 @@ public class TabCompleter{ if(parameter.equals("")) { return null; } else { - List temp = new ArrayList(); + List temp = new ArrayList<>(); temp.add(parameter.replace("<", "").replace(">", "")); return temp; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java index 8a5406a..193ec32 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java @@ -41,6 +41,9 @@ public final class UUIDFetcher { uuid.append('-'); } } + + CACHE.put(playername, UUID.fromString(uuid.toString())); + return UUID.fromString(uuid.toString()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java deleted file mode 100644 index 8112f74..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ /dev/null @@ -1,116 +0,0 @@ -package net.tylermurphy.hideAndSeek.util; - -import static net.tylermurphy.hideAndSeek.configuration.Config.*; - -import java.io.*; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import com.google.common.io.ByteStreams; -import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.configuration.LocalizationString; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; - -import net.tylermurphy.hideAndSeek.Main; -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; - -public class Util { - - public static void broadcastMessage(String message) { - for(Player player : Main.plugin.board.getPlayers()) { - player.sendMessage(message); - } - } - - public static boolean isSetup() { - if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return false; - if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return false; - if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return false; - File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); - if(!destenation.exists()) return false; - if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) return false; - return true; - } - - public static void sendDelayedMessage(String message, int gameId, int delay) { - Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, new Runnable() { - public void run() { - if(gameId == Main.plugin.game.gameId) - Util.broadcastMessage(message); - } - }, delay); - } - - public static void resetPlayer(Player player) { - player.getInventory().clear(); - for (PotionEffect effect : player.getActivePotionEffects()) { - player.removePotionEffect(effect.getType()); - } - if (Main.plugin.board.isSeeker(player)) { - if(pvpEnabled) - for(ItemStack item : Items.SEEKER_ITEMS) - player.getInventory().addItem(item); - for(PotionEffect effect : Items.SEEKER_EFFECTS) - player.addPotionEffect(effect); - } else if (Main.plugin.board.isHider(player)) { - if(pvpEnabled) - for(ItemStack item : Items.HIDER_ITEMS) - player.getInventory().addItem(item); - for(PotionEffect effect : Items.HIDER_EFFECTS) - player.addPotionEffect(effect); - if(glowEnabled) { - ItemStack snowball = new ItemStack(Material.SNOWBALL, 1); - ItemMeta snowballMeta = snowball.getItemMeta(); - snowballMeta.setDisplayName("Glow Powerup"); - List snowballLore = new ArrayList(); - snowballLore.add("Throw to make all seekers glow"); - snowballLore.add("Last 30s, all hiders can see it"); - snowballLore.add("Time stacks on multi use"); - snowballMeta.setLore(snowballLore); - snowball.setItemMeta(snowballMeta); - player.getInventory().addItem(snowball); - } - } - } - - public static void removeItems(Player player){ - for(ItemStack si : Items.SEEKER_ITEMS) - for(ItemStack i : player.getInventory().getContents()) - if(si.isSimilar(i)) player.getInventory().remove(i); - for(ItemStack hi : Items.HIDER_ITEMS) - for(ItemStack i : player.getInventory().getContents()) - if(hi.isSimilar(i)) player.getInventory().remove(i); - } - - public static InputStream convertUniqueId(UUID uuid) { - byte[] bytes = new byte[16]; - ByteBuffer.wrap(bytes) - .putLong(uuid.getMostSignificantBits()) - .putLong(uuid.getLeastSignificantBits()); - return new ByteArrayInputStream(bytes); - } - - public static UUID convertBinaryStream(InputStream stream) { - ByteBuffer buffer = ByteBuffer.allocate(16); - try { - buffer.put(ByteStreams.toByteArray(stream)); - buffer.flip(); - return new UUID(buffer.getLong(), buffer.getLong()); - } catch (IOException e) {} - return null; - } -} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/WinType.java b/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java similarity index 60% rename from src/main/java/net/tylermurphy/hideAndSeek/game/WinType.java rename to src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java index 3e01f21..1a1eb74 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/WinType.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java @@ -1,4 +1,4 @@ -package net.tylermurphy.hideAndSeek.game; +package net.tylermurphy.hideAndSeek.util; public enum WinType { HIDER_WIN, diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 5a8c324..b744b9d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -11,6 +11,7 @@ import java.io.InputStream; import java.io.OutputStream; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.WorldCreator; import net.tylermurphy.hideAndSeek.Main; @@ -25,8 +26,17 @@ public class WorldLoader { this.savename = "hideandseek_"+mapname; } + public World getWorld(){ + return Bukkit.getServer().getWorld(savename); + } + public void unloadMap(){ - if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(savename), false)){ + World world = Bukkit.getServer().getWorld(savename); + if(world == null){ + Main.plugin.getLogger().warning(savename + " already unloaded."); + return; + } + if(Bukkit.getServer().unloadWorld(world, false)){ Main.plugin.getLogger().info("Successfully unloaded " + savename); }else{ Main.plugin.getLogger().severe("COULD NOT UNLOAD " + savename); @@ -35,7 +45,12 @@ public class WorldLoader { public void loadMap(){ Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator())); - Bukkit.getServer().getWorld(savename).setAutoSave(false); + World world = Bukkit.getServer().getWorld(savename); + if(world == null){ + Main.plugin.getLogger().severe("COULD NOT LOAD " + savename); + return; + } + world.setAutoSave(false); } public void rollback(){ @@ -57,9 +72,13 @@ public class WorldLoader { copyFile(srcFile,destFile); if(destenation.exists()) { deleteDirectory(destenation); - destenation.mkdir(); + if(!destenation.mkdir()){ + throw new RuntimeException("Failed to create directory: "+destenation.getPath()); + } + } + if(!temp_destenation.renameTo(destenation)){ + throw new RuntimeException("Failed to rename directory: "+temp_destenation.getPath()); } - temp_destenation.renameTo(destenation); } catch(IOException e) { e.printStackTrace(); return errorPrefix + message("COMMAND_ERROR"); @@ -77,7 +96,11 @@ public class WorldLoader { if(!temp.exists()) if(!temp.mkdirs()) throw new IOException("Couldn't create region directory!"); - String files[] = region.list(); + String[] files = region.list(); + if(files == null){ + Main.plugin.getLogger().severe("Region directory is null or cannot be accessed"); + return; + } for (String file : files) { if(isMca) { @@ -86,7 +109,7 @@ public class WorldLoader { int maxX = (int)Math.floor(saveMaxX / 32.0); int maxZ = (int)Math.floor(saveMaxZ / 32.0); - String[] parts = file.split("."); + String[] parts = file.split("\\."); if(parts.length > 1) { Main.plugin.getLogger().info(file); if( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX ||Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ ) @@ -116,14 +139,16 @@ public class WorldLoader { out.close(); } - private boolean deleteDirectory(File directoryToBeDeleted) { + private void deleteDirectory(File directoryToBeDeleted) { File[] allContents = directoryToBeDeleted.listFiles(); if (allContents != null) { for (File file : allContents) { deleteDirectory(file); } } - return directoryToBeDeleted.delete(); + if(!directoryToBeDeleted.delete()){ + throw new RuntimeException("Failed to delete directory: "+directoryToBeDeleted.getPath()); + } } } From 7f9def05fb88441520bd95f0d5cf20f7162b72dd Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 27 Dec 2021 13:01:39 -0600 Subject: [PATCH 09/16] fix ClassNotFound and add Licence headers --- .../net/tylermurphy/hideAndSeek/Main.java | 19 ++++++++ .../hideAndSeek/command/SetBounds.java | 19 ++++++++ .../hideAndSeek/command/SetExitLocation.java | 19 ++++++++ .../hideAndSeek/command/SetLobbyLocation.java | 19 ++++++++ .../hideAndSeek/command/SetSpawnLocation.java | 19 ++++++++ .../hideAndSeek/command/Setup.java | 19 ++++++++ .../hideAndSeek/command/Start.java | 20 +++++++++ .../tylermurphy/hideAndSeek/command/Stop.java | 19 ++++++++ .../tylermurphy/hideAndSeek/command/Top.java | 19 ++++++++ .../tylermurphy/hideAndSeek/command/Wins.java | 19 ++++++++ .../hideAndSeek/configuration/Config.java | 19 ++++++++ .../configuration/ConfigManager.java | 19 ++++++++ .../hideAndSeek/configuration/Items.java | 19 ++++++++ .../configuration/Localization.java | 19 ++++++++ .../configuration/LocalizationString.java | 19 ++++++++ .../hideAndSeek/database/Database.java | 19 ++++++++ .../hideAndSeek/database/PlayerInfo.java | 19 ++++++++ .../hideAndSeek/database/PlayerInfoTable.java | 19 ++++++++ .../tylermurphy/hideAndSeek/game/Board.java | 19 ++++++++ .../hideAndSeek/game/CommandHandler.java | 19 ++++++++ .../hideAndSeek/game/EventListener.java | 19 ++++++++ .../tylermurphy/hideAndSeek/game/Game.java | 43 ++++++++++++++----- .../tylermurphy/hideAndSeek/util/Packet.java | 19 ++++++++ .../tylermurphy/hideAndSeek/util/Status.java | 19 ++++++++ .../hideAndSeek/util/TabCompleter.java | 19 ++++++++ .../hideAndSeek/util/UUIDFetcher.java | 19 ++++++++ .../tylermurphy/hideAndSeek/util/WinType.java | 19 ++++++++ .../hideAndSeek/world/VoidGenerator.java | 19 ++++++++ .../hideAndSeek/world/WorldLoader.java | 19 ++++++++ .../resources/lang/localization_de-DE.yml | 1 + .../resources/lang/localization_en-US.yml | 1 + 31 files changed, 568 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 12b4f77..3e2daf3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek; import java.io.File; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index ca21908..d5f8a64 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index 8938939..6f3364b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index df5d512..af9c2de 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index eb03625..f68fda5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index 5cde727..49d1cde 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 4abda2b..5a59650 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -1,4 +1,24 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; + import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import net.tylermurphy.hideAndSeek.game.Board; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 0a81793..329048f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 8ac71fc..10df4bd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index 20d1e64..304762e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index b83ee42..6998ffd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import org.bukkit.util.Vector; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 669f729..c950468 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index 3651a41..26c4991 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import org.bukkit.ChatColor; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 327af24..dbf7915 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import java.io.File; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java index b457622..228bb08 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.configuration; import org.bukkit.entity.Entity; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java index 9d3cc73..5681f33 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.database; import com.google.common.io.ByteStreams; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java index c1e0070..b59f434 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.database; import java.util.UUID; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java index 0dba4b4..f3daa62 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.database; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 44e3f05..9df39be 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java index 6758908..7ff7c74 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index dc79732..4dba35a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index d04d32a..6ee4cf6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -1,3 +1,22 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2020-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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; @@ -33,7 +52,7 @@ public class Game { public static Taunt taunt; public static Glow glow; - public static WorldBorder worldBorder; + public static Border worldBorder; public static WorldLoader worldLoader; public static int tick = 0; public static int countdownTime = -1; @@ -77,10 +96,16 @@ public class Game { 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); } + if(tauntEnabled) + taunt = new Taunt(); + if (glowEnabled) + glow = new Glow(); + worldBorder = new Border(); worldBorder.resetWorldborder("hideandseek_"+spawnWorld); - for(Player player : Board.getPlayers()){ + if(gameLength > 0) + timeLeft = gameLength; + for(Player player : Board.getPlayers()) Board.createGameBoard(player); - } Board.reloadGameBoards(); status = Status.STARTING; int temp = gameId; @@ -93,12 +118,8 @@ public class Game { sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29); Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> { if(temp != gameId) return; - if(gameLength > 0) timeLeft = gameLength; broadcastMessage(messagePrefix + message("START")); for(Player player : Board.getPlayers()) resetPlayer(player); - if(worldborderEnabled) worldBorder = new WorldBorder(); - if(tauntEnabled) taunt = new Taunt(); - if (glowEnabled) glow = new Glow(); status = Status.PLAYING; }, 20 * 30); } @@ -432,17 +453,19 @@ class Taunt { } -class WorldBorder { +class Border { private int delay; private boolean running; - public WorldBorder() { + public Border() { delay = 60 * worldborderDelay; } void update(){ - if(delay == 0){ + if(delay == 30 && !running){ + broadcastMessage(worldborderPrefix + message("WORLDBORDER_WARN")); + } else if(delay == 0){ if(running){ delay = 60 * worldborderDelay; running = false; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java index 43a358c..9d863f8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.util; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java index 76c691f..305da9f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.util; public enum Status { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java index 21fe555..d793d9e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.util; import java.util.ArrayList; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java index 193ec32..c79f335 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.util; import net.tylermurphy.hideAndSeek.Main; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java b/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java index 1a1eb74..f633d1b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.util; public enum WinType { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java index 46636cf..1e75be7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.world; import java.util.Collections; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index b744b9d..5d84ceb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.world; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/resources/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index c17fafe..49e5f5e 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -36,6 +36,7 @@ Localization: WORLDBORDER_POSITION: "Spawn muss mindestens 100 Blöcke vom Zentrum der World Border entfernt sein." WORLDBORDER_ENABLE: "Setze World Border zentriert von dieser Position aus. Größe: {AMOUNT}. Verzögerung: {AMOUNT}." WORLDBORDER_DECREASING: "World Norder schrumpoft 100 Blöcke über die nächsten 30 Sekunden!" + WORLDBORDER_WARN: "Die Weltgrenze wird in den nächsten 30er Jahren schrumpfen!" TAUNTED: "$c$oOh nein! Du wurdest geärgert!" TAUNT: "Ein zufälliger Hider wird in den nächsten 30 Sekunden geärgert." TAUNT_ACTIVATE: "Ärgern wurde aktiviert" diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 977f69b..1a2a25a 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -36,6 +36,7 @@ Localization: WORLDBORDER_POSITION: "Spawn position must be 100 from world border center." WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s." + WORLDBORDER_WARN: "World border will shrink in the next 30s!" TAUNTED: "$c$oOh no! You have been chosen to be taunted." TAUNT: "A random hider will be taunted in the next 30s." TAUNT_ACTIVATE: "Taunt has been activated." From 4ef8f170cc43c8bb5208fcb8d66004467200ac2f Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 27 Dec 2021 13:03:08 -0600 Subject: [PATCH 10/16] 1.3.3 beta 3 --- .../hideAndSeek/command/About.java | 19 +++++++++++++++++++ .../tylermurphy/hideAndSeek/command/Help.java | 19 +++++++++++++++++++ .../hideAndSeek/command/ICommand.java | 19 +++++++++++++++++++ .../tylermurphy/hideAndSeek/command/Join.java | 19 +++++++++++++++++++ .../hideAndSeek/command/Leave.java | 19 +++++++++++++++++++ .../hideAndSeek/command/Reload.java | 19 +++++++++++++++++++ .../hideAndSeek/command/SaveMap.java | 19 +++++++++++++++++++ .../hideAndSeek/command/SetBorder.java | 19 +++++++++++++++++++ 8 files changed, 152 insertions(+) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 9286922..4882af2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import org.bukkit.ChatColor; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index c09545c..379301c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java index 91d1298..edadca9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 7a305f6..c7d5fc2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index 6c65714..2954f1d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 3cc92a4..183377f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index 1ce2aa4..5878035 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index c510335..ecbdbef 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -1,3 +1,22 @@ +/* + * 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, either version 3 of the License. + * + * Kenshins Hide and Seek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; From 56e6cac28f0ed7bf02b974cca85c88faa78b1479 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 27 Dec 2021 13:14:32 -0600 Subject: [PATCH 11/16] 1.3.3 rc1 --- .../net/tylermurphy/hideAndSeek/Main.java | 2 +- .../hideAndSeek/command/About.java | 2 +- .../tylermurphy/hideAndSeek/command/Help.java | 2 +- .../hideAndSeek/command/ICommand.java | 2 +- .../tylermurphy/hideAndSeek/command/Join.java | 32 ++----------------- .../hideAndSeek/command/Leave.java | 2 +- .../hideAndSeek/command/Reload.java | 2 +- .../hideAndSeek/command/SaveMap.java | 2 +- .../hideAndSeek/command/SetBorder.java | 2 +- .../hideAndSeek/command/SetBounds.java | 2 +- .../hideAndSeek/command/SetExitLocation.java | 2 +- .../hideAndSeek/command/SetLobbyLocation.java | 2 +- .../hideAndSeek/command/SetSpawnLocation.java | 2 +- .../hideAndSeek/command/Setup.java | 2 +- .../hideAndSeek/command/Start.java | 2 +- .../tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../tylermurphy/hideAndSeek/command/Top.java | 2 +- .../tylermurphy/hideAndSeek/command/Wins.java | 2 +- .../hideAndSeek/configuration/Config.java | 2 +- .../configuration/ConfigManager.java | 2 +- .../hideAndSeek/configuration/Items.java | 2 +- .../configuration/Localization.java | 2 +- .../configuration/LocalizationString.java | 2 +- .../hideAndSeek/database/Database.java | 2 +- .../hideAndSeek/database/PlayerInfo.java | 2 +- .../hideAndSeek/database/PlayerInfoTable.java | 2 +- .../tylermurphy/hideAndSeek/game/Board.java | 2 +- .../hideAndSeek/game/CommandHandler.java | 2 +- .../hideAndSeek/game/EventListener.java | 12 ++++--- .../tylermurphy/hideAndSeek/game/Game.java | 26 ++++++++++++++- .../tylermurphy/hideAndSeek/util/Packet.java | 2 +- .../tylermurphy/hideAndSeek/util/Status.java | 2 +- .../hideAndSeek/util/TabCompleter.java | 2 +- .../hideAndSeek/util/UUIDFetcher.java | 2 +- .../tylermurphy/hideAndSeek/util/WinType.java | 2 +- .../hideAndSeek/world/VoidGenerator.java | 2 +- .../hideAndSeek/world/WorldLoader.java | 2 +- .../resources/lang/localization_de-DE.yml | 1 + .../resources/lang/localization_en-US.yml | 1 + 39 files changed, 71 insertions(+), 69 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 3e2daf3..f1b3364 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 4882af2..de1062b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java index 379301c..c1934a9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java index edadca9..6404c22 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index c7d5fc2..0ca21d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 @@ -23,16 +23,10 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; 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; -import org.bukkit.attribute.Attribute; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.Objects; - import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class Join implements ICommand { @@ -52,29 +46,7 @@ public class Join implements ICommand { return; } - join(player); - } - - public static void join(Player player){ - if(Game.status == Status.STANDBY) { - player.getInventory().clear(); - Board.addHider(player); - if(announceMessagesToNonPlayers) Bukkit.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); - Board.createLobbyBoard(player); - Board.reloadLobbyBoards(); - } else { - Board.addSpectator(player); - player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); - player.setGameMode(GameMode.SPECTATOR); - Board.createGameBoard(player); - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); - } - - player.setFoodLevel(20); - player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue()); + Game.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 2954f1d..cc4f0b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 183377f..fc2592b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index 5878035..c48e1c6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index ecbdbef..5f14b20 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index d5f8a64..9f4101a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index 6f3364b..7461767 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index af9c2de..69e5e52 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index f68fda5..7afe861 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index 49d1cde..74c29bf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 5a59650..b82e3b5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 329048f..b41277b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java index 10df4bd..760bb2c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java index 304762e..dfa5338 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 6998ffd..524eeac 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index c950468..84ad5b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index 26c4991..569cae6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index dbf7915..d5ae01d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java index 228bb08..3d8bc0f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/LocalizationString.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java index 5681f33..602c948 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java index b59f434..8464b54 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfo.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java index f3daa62..e859687 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 9df39be..d81e310 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java index 7ff7c74..8df3cf2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 4dba35a..4911d5f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 @@ -54,7 +54,7 @@ public class EventListener implements Listener { Game.removeItems(event.getPlayer()); if(Game.isNotSetup()) return; if(autoJoin){ - Join.join(event.getPlayer()); + Game.join(event.getPlayer()); } else if(teleportToExit) { if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)) { event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); @@ -62,8 +62,12 @@ public class EventListener implements Listener { } } else { if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) { - event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); - event.getPlayer().setGameMode(GameMode.ADVENTURE); + if(Game.status != Status.STANDBY){ + Game.join(event.getPlayer()); + } else { + event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + event.getPlayer().setGameMode(GameMode.ADVENTURE); + } } } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 6ee4cf6..39d6376 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 @@ -28,6 +28,7 @@ import net.tylermurphy.hideAndSeek.util.Status; import net.tylermurphy.hideAndSeek.util.WinType; import net.tylermurphy.hideAndSeek.world.WorldLoader; import org.bukkit.*; +import org.bukkit.attribute.Attribute; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Firework; @@ -219,6 +220,29 @@ public class Game { } } + public static void join(Player player){ + if(Game.status == Status.STANDBY) { + player.getInventory().clear(); + Board.addHider(player); + if(announceMessagesToNonPlayers) Bukkit.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); + Board.createLobbyBoard(player); + Board.reloadLobbyBoards(); + } else { + Board.addSpectator(player); + player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); + player.setGameMode(GameMode.SPECTATOR); + Board.createGameBoard(player); + player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + player.sendTitle(ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString(), 10, 70, 20); + } + + player.setFoodLevel(20); + player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue()); + } + public static void removeItems(Player player){ for(ItemStack si : Items.SEEKER_ITEMS) for(ItemStack i : player.getInventory().getContents()) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java index 9d863f8..18913da 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java index 305da9f..44a3e42 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Status.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java index d793d9e..4c949e1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java index c79f335..ef65af3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/UUIDFetcher.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java b/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java index f633d1b..3c555cc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/WinType.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java index 1e75be7..7f29d6a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 5d84ceb..5d6e377 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -5,7 +5,7 @@ * * 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, either version 3 of the License. + * 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 diff --git a/src/main/resources/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index 49e5f5e..b48aa4e 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -58,6 +58,7 @@ Localization: STOP: "Das Spiel wurde gestoppt." HIDERS_SUBTITLE: "Verstecke dich gut vor den Seekern!" SEEKERS_SUBTITLE: "Finde alle Hider!" + SPECTATOR_SUBTITLE: "Du bist mitten im spiel beigetreten." BOUNDS_WRONG_WORLD: "Führe diesen Befehl bitte in der Spielwelt aus." BOUNDS: "Grenzen erfolgreich an dieser Position gesetzt. ({AMOUNT}/2)" NOT_AT_ZERO: "Bitte nicht an einer Position setzen, die eine Koordinate bei 0 enthält." diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 1a2a25a..93cbd4e 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -58,6 +58,7 @@ Localization: STOP: "Game has been force stopped." HIDERS_SUBTITLE: "Hide away from the seekers" SEEKERS_SUBTITLE: "Eliminate all hiders" + SPECTATOR_SUBTITLE: "You joined mid-game." BOUNDS_WRONG_WORLD: "Please run this command in the game world." BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." From 3c10cf735d49e62cabef5180248748b06f9de287 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 28 Dec 2021 11:53:55 -0500 Subject: [PATCH 12/16] 1.3.3 rc2 --- pom.xml | 5 ++ .../net/tylermurphy/hideAndSeek/Main.java | 7 +-- .../hideAndSeek/game/EventListener.java | 1 - .../tylermurphy/hideAndSeek/game/Game.java | 47 +++++++++---------- .../hideAndSeek/world/VoidGenerator.java | 12 +++-- src/main/resources/config.yml | 1 - 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index 7c10eb1..7e48a1c 100644 --- a/pom.xml +++ b/pom.xml @@ -44,5 +44,10 @@ sqlite-jdbc 3.36.0.3 + + org.jetbrains + annotations + 23.0.0 + \ 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 f1b3364..e486cda 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -40,6 +40,7 @@ import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.game.Board; +import org.jetbrains.annotations.NotNull; public class Main extends JavaPlugin implements Listener { @@ -77,12 +78,12 @@ public class Main extends JavaPlugin implements Listener { UUIDFetcher.cleanup(); } - 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, 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, args); } -} +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 4911d5f..7db663c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -21,7 +21,6 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import net.tylermurphy.hideAndSeek.command.Join; import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.*; import org.bukkit.attribute.Attribute; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 39d6376..f8284ca 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -411,7 +411,7 @@ class Taunt { protected void update() { if(delay == 0) { if(running) launchTaunt(); - else if(tauntLast || Board.size() > 1) executeTaunt(); + else if(tauntLast || Board.sizeHider() > 1) executeTaunt(); } else { delay--; delay = Math.max(delay, 0); @@ -419,34 +419,31 @@ class Taunt { } private void executeTaunt() { - Player taunted = null; - int rand = (int) (Math.random()*Board.sizeHider()); - for(Player player : Board.getPlayers()) { - if(Board.isHider(player)) { - rand--; - if(rand==0) { - taunted = player; - break; - } - } - } - if(taunted != null) { - taunted.sendMessage(message("TAUNTED").toString()); - broadcastMessage(tauntPrefix + message("TAUNT")); - tauntPlayer = taunted.getName(); - running = true; - delay = 30; - } else { - this.delay = tauntDelay; + Optional rand = Board.getHiders().stream().skip(new Random().nextInt(Board.size())).findFirst(); + if(!rand.isPresent()){ + Main.plugin.getLogger().warning("Failed to select random seeker."); + return; } + Player taunted = rand.get(); + taunted.sendMessage(message("TAUNTED").toString()); + broadcastMessage(tauntPrefix + message("TAUNT")); + tauntPlayer = taunted.getName(); + running = true; + delay = 30; } private void launchTaunt(){ - Player taunted1 = Board.getPlayer(tauntPlayer); - if(taunted1 != null) { - World world = taunted1.getLocation().getWorld(); - assert world != null; - Firework fw = (Firework) world.spawnEntity(taunted1.getLocation(), EntityType.FIREWORK); + Player taunted = Board.getPlayer(tauntPlayer); + if(taunted != null) { + World world = taunted.getLocation().getWorld(); + if(world == null){ + Main.plugin.getLogger().severe("Game world is null while trying to launch taunt."); + tauntPlayer = ""; + running = false; + delay = tauntDelay; + return; + } + Firework fw = (Firework) world.spawnEntity(taunted.getLocation(), EntityType.FIREWORK); FireworkMeta fwm = fw.getFireworkMeta(); fwm.setPower(4); fwm.addEffect(FireworkEffect.builder() diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java index 7f29d6a..7b12767 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java @@ -26,11 +26,12 @@ import java.util.Random; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; +import org.jetbrains.annotations.NotNull; public class VoidGenerator extends ChunkGenerator{ - public List getDefaultPopulators(World world) { - return Collections.emptyList(); + public @NotNull List getDefaultPopulators(@NotNull World world) { + return Collections.emptyList(); } public boolean shouldGenerateNoise() { @@ -61,10 +62,11 @@ public class VoidGenerator extends ChunkGenerator{ return false; } - public boolean canSpawn(World world, int x, int z) { + public boolean canSpawn(@NotNull World world, int x, int z) { return true; } - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { return createChunkData(world); } - + // Backwards compatibility + public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { return createChunkData(world); } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ae130f8..778e3b4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -90,7 +90,6 @@ lobby: max: 10 enabled: true - # Changes the default plugin language. Currently, Supported localizations are: # en-US (English - United States) # de-DE (German - Germany) From 7eb18751260425e13337ffd3ccac0f2c0064ee54 Mon Sep 17 00:00:00 2001 From: HerrMelodious <88331632+HerrMelodious@users.noreply.github.com> Date: Tue, 28 Dec 2021 23:31:57 +0100 Subject: [PATCH 13/16] Update localization_de-DE.yml * SETUP_BOUNDS * NO_GAME_INFO * INFORMATION_FOR --- src/main/resources/lang/localization_de-DE.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/resources/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index b48aa4e..d2dcc1e 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -47,7 +47,7 @@ Localization: SETUP_EXIT: "&c&l- &fTeleport-Position für das Spielende festlegen mit /hs setexit" SETUP_SAVEMAP: "&c&l- &fHide and Seek Weltkarte speichern mit /hs savemap (nach /hs setspawn)" SETUP_COMPLETE: "Alles eingerichtet! Hide and Seek ist spielbereit." - SETUP_BOUNDS: "&c&l- &fBitte legen Sie Spielgrenzen in 2 gegenüberliegenden Ecken der Spielkarte fest, /hs setbounds" + SETUP_BOUNDS: "&c&l- &fSpielgrenze in 2 gegenüberliegenden Ecken der Welt festlegen mit /hs setbounds" GAME_SPAWN: "Teleport-Position für Spielbeginn festgelegt" LOBBY_SPAWN: "Teleport-Position für Lobby festgelegt" EXIT_SPAWN: "Teleport-Position für Spielende festgelegt" @@ -62,8 +62,9 @@ Localization: BOUNDS_WRONG_WORLD: "Führe diesen Befehl bitte in der Spielwelt aus." BOUNDS: "Grenzen erfolgreich an dieser Position gesetzt. ({AMOUNT}/2)" NOT_AT_ZERO: "Bitte nicht an einer Position setzen, die eine Koordinate bei 0 enthält." - NO_GAME_INFO: "Der Spieler hat keine Gameplay-Informationen." - INFORMATION_FOR: "Gewinninformationen für {PLAYER}" + NO_GAME_INFO: "Keine Informationen zum Gameplay für diesen Spieler vorhanden." + INFORMATION_FOR: "Gewinninformationen für {PLAYER}:" + # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 2 type: "de-DE" From 5291f3df2af98435565930d3561c96f9ba20ca18 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 28 Dec 2021 21:39:40 -0500 Subject: [PATCH 14/16] 1.3.3 rc3 --- .../java/net/tylermurphy/hideAndSeek/game/EventListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 7db663c..0a087e0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -113,7 +113,7 @@ public class EventListener implements Listener { if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return; if(event.getTo() == null || event.getTo().getWorld() == null) return; if(!event.getTo().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; - if(event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMinX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){ + if(event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMaxX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){ event.setCancelled(true); } } From a20f78b37e5014ff1859b840c777449fd464f870 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 28 Dec 2021 23:37:54 -0500 Subject: [PATCH 15/16] 1.3.3 rc4 --- .../tylermurphy/hideAndSeek/game/Board.java | 4 + .../hideAndSeek/game/EventListener.java | 110 ++++++++++++++---- .../tylermurphy/hideAndSeek/game/Game.java | 7 ++ 3 files changed, 97 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index d81e310..936f7ac 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -44,6 +44,10 @@ public class Board { return playerList.containsKey(player.getName()); } + public static boolean isPlayer(String name){ + return playerList.containsKey(name); + } + public static boolean isPlayer(CommandSender sender) { return playerList.containsKey(sender.getName()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 0a087e0..474d3be 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -21,33 +21,35 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.*; import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; +import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Snowball; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.*; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.*; import net.tylermurphy.hideAndSeek.util.Packet; import org.bukkit.potion.PotionEffect; +import org.bukkit.projectiles.ProjectileSource; -import java.util.Objects; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class EventListener implements Listener { - - @EventHandler + + @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(PlayerJoinEvent event) { Board.remove(event.getPlayer()); Game.removeItems(event.getPlayer()); @@ -70,8 +72,8 @@ public class EventListener implements Listener { } } } - - @EventHandler + + @EventHandler(priority = EventPriority.MONITOR) public void onQuit(PlayerQuitEvent event) { Board.remove(event.getPlayer()); if(Game.status == Status.STANDBY) { @@ -84,8 +86,8 @@ public class EventListener implements Listener { } Game.removeItems(event.getPlayer()); } - - @EventHandler + + @EventHandler(priority = EventPriority.MONITOR) public void onKick(PlayerKickEvent event) { Board.remove(event.getPlayer()); if(Game.status == Status.STANDBY) { @@ -99,7 +101,7 @@ public class EventListener implements Listener { Game.removeItems(event.getPlayer()); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onChat(AsyncPlayerChatEvent event){ if(Board.isSeeker(event.getPlayer())){ event.setCancelled(true); @@ -107,7 +109,7 @@ public class EventListener implements Listener { } } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onMove(PlayerMoveEvent event){ if(!event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return; @@ -117,13 +119,44 @@ public class EventListener implements Listener { event.setCancelled(true); } } + + Map temp_loc = new HashMap<>(); + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerDeath(PlayerDeathEvent event){ + Player player = event.getEntity(); + if(!Board.isPlayer(player)) return; + event.setKeepInventory(true); + event.setDeathMessage(""); + temp_loc.put(player.getUniqueId(), player.getLocation()); + Main.plugin.getLogger().severe("Player "+player.getName() + " died when not supposed to. Attempting to roll back death."); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerRespawn(PlayerRespawnEvent event){ + Player player = event.getPlayer(); + if(!Board.isPlayer(player)) return; + if(temp_loc.containsKey(player.getUniqueId())){ + player.teleport(temp_loc.get(player.getUniqueId())); + } + } @EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamage(EntityDamageEvent event) { try { if (event.getEntity() instanceof Player) { - Player p = (Player) event.getEntity(); - if (!Board.isPlayer(p)) return; + Player player = (Player) event.getEntity(); + if (!Board.isPlayer(player)) { + if (event instanceof EntityDamageByEntityEvent) { + Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); + if (damager instanceof Player) { + if(Board.isPlayer(damager)){ + event.setCancelled(true); + return; + } + } + } + } if (Game.status != Status.PLAYING) { event.setCancelled(true); return; @@ -133,25 +166,33 @@ public class EventListener implements Listener { Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); if (damager instanceof Player) { attacker = (Player) damager; - if (Board.onSameTeam(p, attacker)) event.setCancelled(true); - if (Board.isSpectator(p)) event.setCancelled(true); + if (Board.onSameTeam(player, attacker)) event.setCancelled(true); + if (Board.isSpectator(player)) event.setCancelled(true); + } else if(damager instanceof Arrow){ + ProjectileSource source = ((Arrow) damager).getShooter(); + if(source instanceof Player){ + attacker = (Player) source; + if (Board.onSameTeam(player, attacker)) event.setCancelled(true); + if (Board.isSpectator(player)) event.setCancelled(true); + } } } - Player player = (Player) event.getEntity(); if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) { if (spawnPosition == null) return; event.setCancelled(true); - player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()); + AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); + if(attribute != null) + player.setHealth(attribute.getValue()); player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); if (Board.isSeeker(player)) { - Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString()); + Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString()); } if (Board.isHider(player)) { if (attacker == null) { - Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString()); + Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(player).toString()); } else { - Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString()); + Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(player).addPlayer(attacker).toString()); } Board.addSeeker(player); } @@ -160,7 +201,7 @@ public class EventListener implements Listener { } } } catch (Exception e){ - //Has shown to cause problems, so ignore if exception + Main.plugin.getLogger().severe("Entity Damage Event Error: " + e.getMessage()); } } @@ -198,4 +239,25 @@ public class EventListener implements Listener { } } } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerCommand(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + String message = event.getMessage(); + String[] array = message.split(" "); + if(array[0].equalsIgnoreCase("/kill")){ + if(Board.isPlayer(player)){ + Main.plugin.getLogger().info("Blocking "+player.getName()+ "from running /kill with anyone associated in the lobby"); + event.setCancelled(true); + } else if(array.length > 1){ + for(int i=1; i Date: Thu, 30 Dec 2021 12:04:47 -0500 Subject: [PATCH 16/16] 1.3.3 rc5 --- .../java/net/tylermurphy/hideAndSeek/game/EventListener.java | 5 +++-- src/main/java/net/tylermurphy/hideAndSeek/game/Game.java | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 474d3be..42589bc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -120,7 +120,7 @@ public class EventListener implements Listener { } } - Map temp_loc = new HashMap<>(); + public static final Map temp_loc = new HashMap<>(); @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerDeath(PlayerDeathEvent event){ @@ -138,6 +138,7 @@ public class EventListener implements Listener { if(!Board.isPlayer(player)) return; if(temp_loc.containsKey(player.getUniqueId())){ player.teleport(temp_loc.get(player.getUniqueId())); + temp_loc.remove(player.getUniqueId()); } } @@ -260,4 +261,4 @@ public class EventListener implements Listener { } } } -} +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index a51b86e..225eab0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -42,6 +42,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import java.beans.EventHandler; import java.io.File; import java.util.*; import java.util.stream.Collectors; @@ -156,6 +157,7 @@ public class Game { Packet.setGlow(player, temp, false); } } + EventListener.temp_loc.clear(); worldLoader.unloadMap(); Board.reloadLobbyBoards(); }