From 487ce5e3f56c5bff5d0538e4cd8d23ddfb73cc02 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 10 May 2022 13:24:19 -0400 Subject: [PATCH] fix seeker death and other things --- .../hideAndSeek/game/EventListener.java | 13 +++++++++++++ .../net/tylermurphy/hideAndSeek/game/Game.java | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 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 7d83217..f8f754f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -116,6 +116,7 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onMove(PlayerMoveEvent event){ + if(!Board.isPlayer(event.getPlayer())) return; if(!event.getPlayer().getWorld().getName().equals(Game.getGameWorld())) return; if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return; if(event.getTo() == null || event.getTo().getWorld() == null) return; @@ -188,6 +189,15 @@ public class EventListener implements Listener { } else if(!pvpEnabled && !allowNaturalCauses){ event.setCancelled(true); return; + // Spectators cannot take damage + } else if(Board.isSpectator(player)){ + event.setCancelled(true); + if(Version.atLeast("1.18") && player.getLocation().getY() < -64){ + player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + } else if(player.getLocation().getY() < 0){ + player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + } + return; } // Handle death event event.setCancelled(true); @@ -216,6 +226,9 @@ public class EventListener implements Listener { // Add leaderboard stats Board.addDeath(player.getUniqueId()); if(attacker != null){ Board.addKill(attacker.getUniqueId()); } + Game.resetPlayer(player); + Board.reloadBoardTeams(); + } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index fb91a2f..76ad068 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -186,6 +186,11 @@ public class Game { } worldBorder.resetWorldborder(getGameWorld()); for(Player player : Board.getPlayers()) { + for(Player player2 : Board.getPlayers()){ + player.showPlayer(player2); + } + player.setFlying(false); + player.setAllowFlight(false); if(Version.atLeast("1.9")){ for(Player temp : Board.getPlayers()) { Packet.setGlow(player, temp, false); @@ -299,7 +304,12 @@ public class Game { } else { Board.addSpectator(player); player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); - player.setGameMode(GameMode.SPECTATOR); + player.setGameMode(GameMode.ADVENTURE); + for(Player player2 : Board.getPlayers()){ + player2.hidePlayer(player); + } + player.setFlying(true); + player.setAllowFlight(true); Board.createGameBoard(player); player.teleport(new Location(Bukkit.getWorld(getGameWorld()), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString()); @@ -315,6 +325,12 @@ public class Game { } public static void leave(Player player){ + player.setFlying(false); + player.setAllowFlight(false); + for(Player player2 : Board.getPlayers()){ + player2.showPlayer(player); + player.showPlayer(player2); + } if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); else Game.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); Board.removeBoard(player);