diff --git a/src/main/java/net/minestom/server/listener/PlayerPositionListener.java b/src/main/java/net/minestom/server/listener/PlayerPositionListener.java index d9bcd945f..d248442f9 100644 --- a/src/main/java/net/minestom/server/listener/PlayerPositionListener.java +++ b/src/main/java/net/minestom/server/listener/PlayerPositionListener.java @@ -61,11 +61,6 @@ public class PlayerPositionListener { if (player.getLastSentTeleportId() != player.getLastReceivedTeleportId()) { return; } - // Try to move in an unloaded chunk, prevent it - if (!ChunkUtils.isLoaded(instance, x, z)) { - player.teleport(player.getPosition()); - return; - } final var currentPosition = player.getPosition(); final var newPosition = new Pos(x, y, z, yaw, pitch); @@ -74,6 +69,12 @@ public class PlayerPositionListener { return; } + // Try to move in an unloaded chunk, prevent it + if (!currentPosition.sameChunk(newPosition) && !ChunkUtils.isLoaded(instance, x, z)) { + player.teleport(player.getPosition()); + return; + } + PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(player, newPosition); EventDispatcher.call(playerMoveEvent); diff --git a/src/main/java/net/minestom/server/utils/chunk/ChunkUtils.java b/src/main/java/net/minestom/server/utils/chunk/ChunkUtils.java index 983f63518..13489dd57 100644 --- a/src/main/java/net/minestom/server/utils/chunk/ChunkUtils.java +++ b/src/main/java/net/minestom/server/utils/chunk/ChunkUtils.java @@ -77,10 +77,7 @@ public final class ChunkUtils { * @return true if the chunk is loaded, false otherwise */ public static boolean isLoaded(@NotNull Instance instance, double x, double z) { - final int chunkX = getChunkCoordinate(x); - final int chunkZ = getChunkCoordinate(z); - - final Chunk chunk = instance.getChunk(chunkX, chunkZ); + final Chunk chunk = instance.getChunk(getChunkCoordinate(x), getChunkCoordinate(z)); return isLoaded(chunk); }