mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-19 15:09:27 +00:00
87 lines
7.1 KiB
Diff
87 lines
7.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
|
Date: Wed, 8 Jan 2025 22:48:04 -0300
|
|
Subject: [PATCH] Add PlayerPreMoveEvent
|
|
|
|
|
|
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 4b8f847e6a7437152fe3409f9f6bc800ca0be93b..9b3dc8de35cf3ab55e9eb9dc5849d6205a52dde5 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -1429,7 +1429,7 @@ public class ServerGamePacketListenerImpl
|
|
d3 = d - this.lastGoodX; // Paper - diff on change, used for checking large move vectors above
|
|
d4 = d1 - this.lastGoodY; // Paper - diff on change, used for checking large move vectors above
|
|
d5 = d2 - this.lastGoodZ; // Paper - diff on change, used for checking large move vectors above
|
|
- boolean flag = d4 > 0.0;
|
|
+ boolean flag = d4 > 0.0; // SparklyPaper - diff on change, used to reset the fall distance, checks if d7 is > 0.0D (player is moving upwards)
|
|
if (this.player.onGround() && !packet.isOnGround() && flag) {
|
|
// Paper start - Add PlayerJumpEvent
|
|
org.bukkit.entity.Player player = this.getCraftPlayer();
|
|
@@ -1463,7 +1463,37 @@ public class ServerGamePacketListenerImpl
|
|
|
|
boolean flag1 = this.player.verticalCollisionBelow;
|
|
this.player.move(MoverType.PLAYER, new Vec3(d3, d4, d5));
|
|
- this.player.onGround = packet.isOnGround(); // CraftBukkit - SPIGOT-5810, SPIGOT-5835, SPIGOT-6828: reset by this.player.move
|
|
+ // SparklyPaper start - Add PlayerPreMoveEvent event
|
|
+ boolean isOnGround = packet.isOnGround();
|
|
+ boolean horizontalCollision = packet.horizontalCollision();
|
|
+ if (net.sparklypower.sparklypaper.event.player.PlayerPreMoveEvent.getHandlerList().getRegisteredListeners().length != 0) {
|
|
+ org.bukkit.entity.Player player = this.getCraftPlayer();
|
|
+ Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location.
|
|
+ Location to = player.getLocation().clone(); // Start off the To location as the Players current location.
|
|
+
|
|
+ // If the packet contains movement information then we update the To location with the correct XYZ.
|
|
+ if (packet.hasPos) {
|
|
+ to.setX(packet.x);
|
|
+ to.setY(packet.y);
|
|
+ to.setZ(packet.z);
|
|
+ }
|
|
+
|
|
+ // If the packet contains look information then we update the To location with the correct Yaw & Pitch.
|
|
+ if (packet.hasRot) {
|
|
+ to.setYaw(packet.yRot);
|
|
+ to.setPitch(packet.xRot);
|
|
+ }
|
|
+
|
|
+ net.sparklypower.sparklypaper.event.player.PlayerPreMoveEvent event = new net.sparklypower.sparklypaper.event.player.PlayerPreMoveEvent(player, from, to, packet.isOnGround(), packet.horizontalCollision(), flag);
|
|
+
|
|
+ if (event.callEvent()) {
|
|
+ isOnGround = event.isOnGround();
|
|
+ horizontalCollision = event.isHorizontalCollision();
|
|
+ flag = event.isResetFallDistance();
|
|
+ }
|
|
+ }
|
|
+ // SparklyPaper end
|
|
+ this.player.onGround = isOnGround; // CraftBukkit - SPIGOT-5810, SPIGOT-5835, SPIGOT-6828: reset by this.player.move // SparklyPaper - Add PlayerPreMoveEvent
|
|
boolean didCollide = toX != this.player.getX() || toY != this.player.getY() || toZ != this.player.getZ(); // Paper - needed here as the difference in Y can be reset - also note: this is only a guess at whether collisions took place, floating point errors can make this true when it shouldn't be...
|
|
// Paper start - prevent position desync
|
|
if (this.awaitingPositionFromClient != null) {
|
|
@@ -1597,15 +1627,15 @@ public class ServerGamePacketListenerImpl
|
|
&& this.noBlocksAround(this.player);
|
|
this.player.serverLevel().getChunkSource().move(this.player);
|
|
Vec3 vec3 = new Vec3(this.player.getX() - x, this.player.getY() - y, this.player.getZ() - z);
|
|
- this.player.setOnGroundWithMovement(packet.isOnGround(), packet.horizontalCollision(), vec3);
|
|
- this.player.doCheckFallDamage(vec3.x, vec3.y, vec3.z, packet.isOnGround());
|
|
+ this.player.setOnGroundWithMovement(isOnGround, horizontalCollision, vec3); // SparklyPaper - Add PlayerPreMoveEvent
|
|
+ this.player.doCheckFallDamage(vec3.x, vec3.y, vec3.z, isOnGround); // SparklyPaper - Add PlayerPreMoveEvent
|
|
if (!this.player.isSpectator() && this.player.isAffectedByBlocks()) this.player.recordMovementThroughBlocks(new Vec3(x, y, z), this.player.position()); // Paper - Do not record movement for vehicles/players unaffected by blocks
|
|
this.handlePlayerKnownMovement(vec3);
|
|
if (flag) {
|
|
this.player.resetFallDistance();
|
|
}
|
|
|
|
- if (packet.isOnGround()
|
|
+ if (isOnGround // SparklyPaper - Add PlayerPreMoveEvent
|
|
|| this.player.hasLandedInLiquid()
|
|
|| this.player.onClimbable()
|
|
|| this.player.isSpectator()
|
|
@@ -1620,7 +1650,7 @@ public class ServerGamePacketListenerImpl
|
|
this.lastGoodZ = this.player.getZ();
|
|
} else {
|
|
this.internalTeleport(x, y, z, f, f1); // 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() - x, this.player.getY() - y, this.player.getZ() - z, packet.isOnGround());
|
|
+ this.player.doCheckFallDamage(this.player.getX() - x, this.player.getY() - y, this.player.getZ() - z, isOnGround); // SparklyPaper - Add PlayerPreMoveEvent
|
|
}
|
|
}
|
|
}
|