Use teleportAsync for handling cancelled move events

Some plugins are bad and update the `from` position to something
completely garbage. To avoid a crash from this cross-region
teleportation, the teleportAsync function is now used.

The reason the teleport isn't simply ignored is since there may
be legitimate reasons to update the `from` position to something
off-region. This also handles the case where the plugin _uses_
an asynchronous teleport while cancelling the event.

This mirrors the behavior for changing the target destination
but not cancelling the event.

Fixes https://github.com/PaperMC/Folia/issues/115
This commit is contained in:
Spottedleaf 2023-07-01 12:04:24 -07:00
parent 801cff1570
commit d1c9e63470
2 changed files with 20 additions and 2 deletions

View File

@ -16430,7 +16430,7 @@ index 44d99e89226adb6234b9405f25ac9dab9bd84297..072634e26d32ca0b3438a5d3a03be367
Collections.shuffle( this.connections ); Collections.shuffle( this.connections );
} }
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index d9c2d06ae24dcf80a497e75f4c7f63d401b77f9b..e7760d8a1013a0106effbdb7f9991e44b95359c4 100644 index d9c2d06ae24dcf80a497e75f4c7f63d401b77f9b..f405b376c313ef297b47191e25c43ad90813f673 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -325,10 +325,10 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic @@ -325,10 +325,10 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
@ -16580,6 +16580,15 @@ index d9c2d06ae24dcf80a497e75f4c7f63d401b77f9b..e7760d8a1013a0106effbdb7f9991e44
++this.receivedMovePacketCount; ++this.receivedMovePacketCount;
int i = this.receivedMovePacketCount - this.knownMovePacketCount; int i = this.receivedMovePacketCount - this.knownMovePacketCount;
@@ -759,7 +773,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
// If the event is cancelled we move the player back to their old location.
if (event.isCancelled()) {
- this.teleport(from);
+ this.player.getBukkitEntity().teleportAsync(from, PlayerTeleportEvent.TeleportCause.PLUGIN); // Folia - region threading
return;
}
@@ -767,7 +781,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic @@ -767,7 +781,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
// there to avoid any 'Moved wrongly' or 'Moved too quickly' errors. // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors.
// We only do this if the Event was not cancelled. // We only do this if the Event was not cancelled.
@ -16688,6 +16697,15 @@ index d9c2d06ae24dcf80a497e75f4c7f63d401b77f9b..e7760d8a1013a0106effbdb7f9991e44
if (i > Math.max(this.allowedPlayerTicks, 5)) { if (i > Math.max(this.allowedPlayerTicks, 5)) {
ServerGamePacketListenerImpl.LOGGER.debug("{} is sending move packets too frequently ({} packets since last tick)", this.player.getName().getString(), i); ServerGamePacketListenerImpl.LOGGER.debug("{} is sending move packets too frequently ({} packets since last tick)", this.player.getName().getString(), i);
@@ -1608,7 +1635,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
// If the event is cancelled we move the player back to their old location.
if (event.isCancelled()) {
- this.teleport(from);
+ this.player.getBukkitEntity().teleportAsync(from, PlayerTeleportEvent.TeleportCause.PLUGIN); // Folia - region threading
return;
}
@@ -1616,7 +1643,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic @@ -1616,7 +1643,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
// there to avoid any 'Moved wrongly' or 'Moved too quickly' errors. // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors.
// We only do this if the Event was not cancelled. // We only do this if the Event was not cancelled.

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Work around https://github.com/PaperMC/paperweight/issues/194
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index e7760d8a1013a0106effbdb7f9991e44b95359c4..82ffef34b596a98faa245ba401e67add9d9ac7d0 100644 index f405b376c313ef297b47191e25c43ad90813f673..ace5e9900eb4e08ace4fb24ffa66c6d6d03ab82a 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -504,7 +504,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic @@ -504,7 +504,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic