2023-08-08 04:51:09 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Moulberry <james.jenour@protonmail.com>
Date: Wed, 26 Jul 2023 20:13:31 +0800
Subject: [PATCH] Implement PlayerFailMoveEvent
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-06-14 14:11:52 +02:00
index 730c7d28e3a3494feec6a94492b2b1b00412d94e..97c0fe8b90776ba8335bf322e8a74872468aae58 100644
2023-08-08 04:51:09 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-06-14 10:17:11 +02:00
@@ -1261,8 +1261,8 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-08-08 04:51:09 +02:00
double d0 = ServerGamePacketListenerImpl.clampHorizontal(packet.getX(this.player.getX())); final double toX = d0; // Paper - OBFHELPER
2024-01-26 19:41:41 +01:00
double d1 = ServerGamePacketListenerImpl.clampVertical(packet.getY(this.player.getY())); final double toY = d1; // Paper - OBFHELPER
2023-08-08 04:51:09 +02:00
double d2 = ServerGamePacketListenerImpl.clampHorizontal(packet.getZ(this.player.getZ())); final double toZ = d2; // Paper - OBFHELPER
- float f = Mth.wrapDegrees(packet.getYRot(this.player.getYRot()));
- float f1 = Mth.wrapDegrees(packet.getXRot(this.player.getXRot()));
+ float f = Mth.wrapDegrees(packet.getYRot(this.player.getYRot())); final float toYaw = f; // Paper - OBFHELPER
+ float f1 = Mth.wrapDegrees(packet.getXRot(this.player.getXRot())); final float toPitch = f1; // Paper - OBFHELPER
if (this.player.isPassenger()) {
this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1);
2024-06-14 10:17:11 +02:00
@@ -1329,8 +1329,14 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-12-06 17:34:54 +01:00
}
2023-12-06 18:47:45 +01:00
// Paper start - Prevent moving into unloaded chunks
if (this.player.level().paperConfig().chunks.preventMovingIntoUnloadedChunks && (this.player.getX() != toX || this.player.getZ() != toZ) && !worldserver.areChunksLoadedForMove(this.player.getBoundingBox().expandTowards(new Vec3(toX, toY, toZ).subtract(this.player.position())))) {
- this.internalTeleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot(), Collections.emptySet());
- return;
+ // Paper start - Add fail move event
+ io.papermc.paper.event.player.PlayerFailMoveEvent event = fireFailMove(io.papermc.paper.event.player.PlayerFailMoveEvent.FailReason.MOVED_INTO_UNLOADED_CHUNK,
+ toX, toY, toZ, toYaw, toPitch, false);
+ if (!event.isAllowed()) {
+ this.internalTeleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot(), Collections.emptySet());
+ return;
+ }
2024-01-14 16:31:39 +01:00
+ // Paper end - Add fail move event
2023-12-06 18:47:45 +01:00
}
2024-01-21 13:56:22 +01:00
// Paper end - Prevent moving into unloaded chunks
2023-08-08 04:51:09 +02:00
2024-06-14 10:17:11 +02:00
@@ -1339,9 +1345,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-08-08 04:51:09 +02:00
2023-12-06 17:34:54 +01:00
if (d10 - d9 > Math.max(f2, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && !this.isSingleplayerOwner()) {
// CraftBukkit end
2023-12-06 18:47:45 +01:00
- ServerGamePacketListenerImpl.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8});
- this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
- return;
2023-12-06 17:34:54 +01:00
+ // Paper start - Add fail move event
+ io.papermc.paper.event.player.PlayerFailMoveEvent event = fireFailMove(io.papermc.paper.event.player.PlayerFailMoveEvent.FailReason.MOVED_TOO_QUICKLY,
+ toX, toY, toZ, toYaw, toPitch, true);
+ if (!event.isAllowed()) {
+ if (event.getLogWarning())
2023-12-06 18:47:45 +01:00
+ ServerGamePacketListenerImpl.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8});
+ this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
+ return;
2023-12-06 17:34:54 +01:00
+ }
2024-01-14 16:31:39 +01:00
+ // Paper end - Add fail move event
2023-12-06 17:34:54 +01:00
}
}
}
2024-06-14 10:17:11 +02:00
@@ -1403,14 +1416,31 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2024-01-22 21:04:08 +01:00
d8 = d2 - this.player.getZ();
d10 = d6 * d6 + d7 * d7 + d8 * d8;
2024-04-25 00:36:49 +02:00
- boolean flag3 = false;
2024-01-22 21:04:08 +01:00
+ boolean movedWrongly = false; // Paper - Add fail move event; rename
2023-08-08 04:51:09 +02:00
if (!this.player.isChangingDimension() && d10 > org.spigotmc.SpigotConfig.movedWronglyThreshold && !this.player.isSleeping() && !this.player.gameMode.isCreative() && this.player.gameMode.getGameModeForPlayer() != GameType.SPECTATOR) { // Spigot
2024-04-25 00:36:49 +02:00
- flag3 = true;
2023-08-08 04:51:09 +02:00
+ // Paper start - Add fail move event
+ io.papermc.paper.event.player.PlayerFailMoveEvent event = fireFailMove(io.papermc.paper.event.player.PlayerFailMoveEvent.FailReason.MOVED_WRONGLY,
+ toX, toY, toZ, toYaw, toPitch, true);
+ if (!event.isAllowed()) {
2024-01-22 21:04:08 +01:00
+ movedWrongly = true;
2023-08-08 04:51:09 +02:00
+ if (event.getLogWarning())
2024-04-25 00:36:49 +02:00
+ // Paper end
2023-08-08 04:51:09 +02:00
ServerGamePacketListenerImpl.LOGGER.warn("{} moved wrongly!", this.player.getName().getString());
2024-04-25 00:36:49 +02:00
+ } // Paper
2023-08-08 04:51:09 +02:00
}
2024-04-25 00:36:49 +02:00
- if (!this.player.noPhysics && !this.player.isSleeping() && (flag3 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb, d0, d1, d2))) {
+ // Paper start - Add fail move event
2024-01-22 21:04:08 +01:00
+ boolean teleportBack = !this.player.noPhysics && !this.player.isSleeping() && (movedWrongly && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb, d0, d1, d2));
+ if (teleportBack) {
+ io.papermc.paper.event.player.PlayerFailMoveEvent event = fireFailMove(io.papermc.paper.event.player.PlayerFailMoveEvent.FailReason.CLIPPED_INTO_BLOCK,
+ toX, toY, toZ, toYaw, toPitch, false);
+ if (event.isAllowed()) {
+ teleportBack = false;
+ }
+ }
+ if (teleportBack) {
2024-04-25 00:36:49 +02:00
+ // Paper end - Add fail move event
2024-01-22 21:04:08 +01:00
this.internalTeleport(d3, d4, d5, f, f1, Collections.emptySet()); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet.
this.player.doCheckFallDamage(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5, packet.isOnGround());
} else {
2024-06-14 10:17:11 +02:00
@@ -3467,4 +3497,17 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-08-08 04:51:09 +02:00
2024-01-22 21:04:08 +01:00
InteractionResult run(ServerPlayer player, Entity entity, InteractionHand hand);
}
+
2023-08-08 04:51:09 +02:00
+ // Paper start - Add fail move event
+ private io.papermc.paper.event.player.PlayerFailMoveEvent fireFailMove(io.papermc.paper.event.player.PlayerFailMoveEvent.FailReason failReason,
2024-01-22 21:04:08 +01:00
+ double toX, double toY, double toZ, float toYaw, float toPitch, boolean logWarning) {
2023-08-08 04:51:09 +02:00
+ Player player = this.getCraftPlayer();
+ Location from = new Location(player.getWorld(), this.lastPosX, this.lastPosY, this.lastPosZ, this.lastYaw, this.lastPitch);
+ Location to = new Location(player.getWorld(), toX, toY, toZ, toYaw, toPitch);
+ io.papermc.paper.event.player.PlayerFailMoveEvent event = new io.papermc.paper.event.player.PlayerFailMoveEvent(player, failReason,
+ false, logWarning, from, to);
+ event.callEvent();
+ return event;
+ }
2024-01-14 16:31:39 +01:00
+ // Paper end - Add fail move event
2024-01-22 21:04:08 +01:00
}