From 19488e62bf01ff1d9abe9aa149141d58aed801cf Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 13 Apr 2022 13:47:59 -0400 Subject: [PATCH] 1.4.0 rc3 --- .../net/tylermurphy/hideAndSeek/Main.java | 8 +- .../hideAndSeek/command/Start.java | 8 +- .../tylermurphy/hideAndSeek/game/Board.java | 87 +++++++++++-------- .../hideAndSeek/game/EventListener.java | 15 ---- .../tylermurphy/hideAndSeek/game/Game.java | 21 +++-- src/main/resources/config.yml | 3 +- 6 files changed, 77 insertions(+), 65 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index e486cda..cdba285 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -46,7 +46,7 @@ public class Main extends JavaPlugin implements Listener { public static Main plugin; public static File root, data; - private BukkitTask onTickTask; + private int onTickTask; public void onEnable() { plugin = this; @@ -69,13 +69,13 @@ public class Main extends JavaPlugin implements Listener { } catch (Exception e) { e.printStackTrace(); } - },0,1); + },0,1).getTaskId(); } public void onDisable() { - if(onTickTask != null) - onTickTask.cancel(); + Main.plugin.getServer().getScheduler().cancelTask(onTickTask); UUIDFetcher.cleanup(); + Board.cleanup(); } public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index b82e3b5..8605764 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -24,6 +24,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; 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.command.CommandSender; import org.bukkit.entity.Player; @@ -64,7 +65,12 @@ public class Start implements ICommand { } else { seekerName = args[0]; } - Player seeker = Board.getPlayer(seekerName); + Player temp = Bukkit.getPlayer(seekerName); + if(temp == null) { + sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); + return; + } + Player seeker = Board.getPlayer(temp.getUniqueId()); if(seeker == null) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index fd75040..e91e3da 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -34,32 +34,28 @@ 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<>(); + 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(String name){ - return playerList.containsKey(name); + return playerList.containsKey(player.getUniqueId()); } public static boolean isPlayer(CommandSender sender) { - return playerList.containsKey(sender.getName()); + return playerList.containsKey(Bukkit.getPlayer(sender.getName()).getUniqueId()); } public static boolean isHider(Player player) { - return Hider.contains(player.getName()); + return Hider.contains(player.getUniqueId()); } public static boolean isSeeker(Player player) { - return Seeker.contains(player.getName()); + return Seeker.contains(player.getUniqueId()); } public static boolean isSpectator(Player player) { - return Spectator.contains(player.getName()); + return Spectator.contains(player.getUniqueId()); } public static int sizeHider() { @@ -74,6 +70,13 @@ public class Board { return playerList.values().size(); } + public static void check(){ + for(UUID uuid : playerList.keySet()){ + if(Bukkit.getPlayer(uuid) == null) + playerList.remove(uuid); + } + } + public static List getHiders(){ return Hider.stream().map(playerList::get).collect(Collectors.toList()); } @@ -94,42 +97,42 @@ public class Board { return new ArrayList<>(playerList.values()); } - public static Player getPlayer(String name) { - return playerList.get(name); + public static Player getPlayer(UUID uuid) { + return playerList.get(uuid); } public static void addHider(Player player) { - Hider.add(player.getName()); - Seeker.remove(player.getName()); - Spectator.remove(player.getName()); - playerList.put(player.getName(), player); + Hider.add(player.getUniqueId()); + Seeker.remove(player.getUniqueId()); + Spectator.remove(player.getUniqueId()); + playerList.put(player.getUniqueId(), player); } public static void addSeeker(Player player) { - Hider.remove(player.getName()); - Seeker.add(player.getName()); - Spectator.remove(player.getName()); - playerList.put(player.getName(), player); + Hider.remove(player.getUniqueId()); + Seeker.add(player.getUniqueId()); + Spectator.remove(player.getUniqueId()); + playerList.put(player.getUniqueId(), player); } public static void addSpectator(Player player) { - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - Spectator.add(player.getName()); - playerList.put(player.getName(), player); + Hider.remove(player.getUniqueId()); + Seeker.remove(player.getUniqueId()); + Spectator.add(player.getUniqueId()); + playerList.put(player.getUniqueId(), player); } public static void remove(Player player) { - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - Spectator.remove(player.getName()); - playerList.remove(player.getName()); + Hider.remove(player.getUniqueId()); + Seeker.remove(player.getUniqueId()); + Spectator.remove(player.getUniqueId()); + playerList.remove(player.getUniqueId()); } 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()); + if(Hider.contains(player1.getUniqueId()) && Hider.contains(player2.getUniqueId())) return true; + else if(Seeker.contains(player1.getUniqueId()) && Seeker.contains(player2.getUniqueId())) return true; + else return Spectator.contains(player1.getUniqueId()) && Spectator.contains(player2.getUniqueId()); } public static void reload() { @@ -143,7 +146,7 @@ public class Board { } private static void createLobbyBoard(Player player, boolean recreate) { - CustomBoard board = customBoards.get(player.getName()); + CustomBoard board = customBoards.get(player.getUniqueId()); if(recreate) { board = new CustomBoard(player, "&l&eHIDE AND SEEK"); board.updateTeams(); @@ -172,7 +175,7 @@ public class Board { i++; } board.display(); - customBoards.put(player.getName(), board); + customBoards.put(player.getUniqueId(), board); } public static void createGameBoard(Player player){ @@ -180,7 +183,7 @@ public class Board { } private static void createGameBoard(Player player, boolean recreate){ - CustomBoard board = customBoards.get(player.getName()); + CustomBoard board = customBoards.get(player.getUniqueId()); if(recreate) { board = new CustomBoard(player, GAME_TITLE); board.updateTeams(); @@ -235,14 +238,14 @@ public class Board { i++; } board.display(); - customBoards.put(player.getName(), board); + customBoards.put(player.getUniqueId(), board); } public static void removeBoard(Player player) { ScoreboardManager manager = Bukkit.getScoreboardManager(); assert manager != null; player.setScoreboard(manager.getMainScoreboard()); - customBoards.remove(player.getName()); + customBoards.remove(player.getUniqueId()); } public static void reloadLobbyBoards() { @@ -281,6 +284,14 @@ public class Board { else return ChatColor.WHITE + "UNKNOWN"; } + public static void cleanup(){ + playerList.clear(); + Hider.clear(); + Seeker.clear(); + Spectator.clear(); + customBoards.clear(); + } + } class CustomBoard { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index aab55d4..ffe452b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -40,7 +40,6 @@ import org.bukkit.event.entity.*; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.player.*; -import net.tylermurphy.hideAndSeek.util.Packet; import org.bukkit.potion.PotionEffect; import org.bukkit.projectiles.ProjectileSource; @@ -257,20 +256,6 @@ public class EventListener implements Listener { 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