Clone the teleport position to prevent object sharing

This commit is contained in:
themode 2021-01-23 08:42:49 +01:00
parent 36933fe4b3
commit bf692d8043

View File

@ -244,9 +244,11 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
public void teleport(@NotNull Position position, @Nullable long[] chunks, @Nullable Runnable callback) { public void teleport(@NotNull Position position, @Nullable long[] chunks, @Nullable Runnable callback) {
Check.stateCondition(instance == null, "You need to use Entity#setInstance before teleporting an entity!"); Check.stateCondition(instance == null, "You need to use Entity#setInstance before teleporting an entity!");
final Position teleportPosition = position.clone(); // Prevent synchronization issue
final ChunkCallback endCallback = (chunk) -> { final ChunkCallback endCallback = (chunk) -> {
refreshPosition(position.getX(), position.getY(), position.getZ()); refreshPosition(teleportPosition);
refreshView(position.getYaw(), position.getPitch()); refreshView(teleportPosition.getYaw(), teleportPosition.getPitch());
sendSynchronization(); sendSynchronization();
@ -254,7 +256,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
}; };
if (chunks == null || chunks.length == 0) { if (chunks == null || chunks.length == 0) {
instance.loadOptionalChunk(position, endCallback); instance.loadOptionalChunk(teleportPosition, endCallback);
} else { } else {
ChunkUtils.optionalLoadAll(instance, chunks, null, endCallback); ChunkUtils.optionalLoadAll(instance, chunks, null, endCallback);
} }