From cd521d4c1914968a43c62c657e641ad790b256ae Mon Sep 17 00:00:00 2001 From: themode Date: Wed, 23 Sep 2020 22:14:43 +0200 Subject: [PATCH] Fix teleport in the PlayerMoveEvent --- .../minestom/server/listener/PlayerPositionListener.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minestom/server/listener/PlayerPositionListener.java b/src/main/java/net/minestom/server/listener/PlayerPositionListener.java index 2e4690234..3dbf14761 100644 --- a/src/main/java/net/minestom/server/listener/PlayerPositionListener.java +++ b/src/main/java/net/minestom/server/listener/PlayerPositionListener.java @@ -56,16 +56,21 @@ public class PlayerPositionListener { return; } + final Position currentPosition = player.getPosition().clone(); Position newPosition = new Position(x, y, z, yaw, pitch); final Position cachedPosition = newPosition.clone(); PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(player, newPosition); player.callEvent(PlayerMoveEvent.class, playerMoveEvent); - if (!playerMoveEvent.isCancelled()) { + + // True if the event call changed the player position (possibly a teleport) + final boolean positionChanged = !currentPosition.equals(player.getPosition()); + + if (!playerMoveEvent.isCancelled() && !positionChanged) { // Move the player newPosition = playerMoveEvent.getNewPosition(); if (!newPosition.equals(cachedPosition)) { - // Position changed, teleport the player + // New position from the event changed, teleport the player player.teleport(newPosition); } // Change the internal data