Add distance check to TeleportEvent

In addition to checking if a player is on a vehicle, the update now also checks if the distance between the player's current location and the teleport destination is more than 5 blocks. If that's the case, the teleportation is cancelled.
This commit is contained in:
Teriuihi 2024-06-28 23:23:50 +02:00
parent e35bc71f96
commit df875406e1

View File

@ -18,6 +18,8 @@ public class TeleportEvent implements Listener {
Player player = event.getPlayer();
if (player.getVehicle() == null)
return;
if (event.getTo().distance(event.getFrom()) < 5)
return;
event.setCancelled(true);
player.sendRichMessage("<red>Teleporting was cancelled. You can not be sitting, or mounted while teleporting.");
}