mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-25 18:47:40 +01:00
Clone the teleport position to prevent object sharing
This commit is contained in:
parent
36933fe4b3
commit
bf692d8043
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user