diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java b/plugin/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java index 0e1c712b1..6aad41d07 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java @@ -1256,6 +1256,31 @@ public void onItemMerge(ItemMergeEvent event) { } } + @EventHandler + public void onSpectatorTeleported(PlayerTeleportEvent event) { + if (event.isCancelled()) { + return; + } + + if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) { + return; + } + + Player player = event.getPlayer(); + + if (!Main.isPlayerInGame(player)) { + return; + } + + GamePlayer gPlayer = Main.getPlayerGameProfile(player); + + Game game = gPlayer.getGame(); + + if (!GameCreator.isInArea(event.getTo(), game.getPos1(), game.getPos2())) { + event.setCancelled(true); + } + } + /* This event was replaced on 1.12 with newer (event handling is devided between Player112Listener and PlayerBefore112Listener) */ public static void onItemPickup(Player player, Item item, Cancellable cancel) { if (cancel.isCancelled()) {