Skip to content

Commit

Permalink
fix: spectator should not be able to teleport to players outside of t…
Browse files Browse the repository at this point in the history
…he arena
  • Loading branch information
Misat11 committed Jul 16, 2024
1 parent 69783ad commit 35fd7d4
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 35fd7d4

Please sign in to comment.