Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@
Packet<ClientGamePacketListener> packet = null;
boolean pos = positionChanged || this.tickCount % 60 == 0;
boolean sentPosition = false;
@@ -218,6 +_,25 @@
@@ -218,7 +_,22 @@

this.tickCount++;
if (this.entity.hurtMarked) {
+ // CraftBukkit start - Create PlayerVelocity event
+ boolean cancelled = false;
+
+ if (this.entity instanceof ServerPlayer) {
+ org.bukkit.entity.Player player = (org.bukkit.entity.Player) this.entity.getBukkitEntity();
+ if (this.entity.getBukkitEntity() instanceof org.bukkit.entity.Player player) {
+ org.bukkit.util.Vector velocity = player.getVelocity();
+
+ org.bukkit.event.player.PlayerVelocityEvent event = new org.bukkit.event.player.PlayerVelocityEvent(player, velocity.clone());
Expand All @@ -79,14 +78,12 @@
+ player.setVelocity(event.getVelocity());
+ }
+ }
+
+ if (cancelled) {
+ return;
+ }
+ // CraftBukkit end
this.entity.hurtMarked = false;
+ if (cancelled) return; // Paper - if PlayerVelocity was cancel then we skip the sendToTrackingPlayersAndSelf
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not early return here just in case more stuff gets added later.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just remove this change?

this.synchronizer.sendToTrackingPlayersAndSelf(new ClientboundSetEntityMotionPacket(this.entity));
}
}
@@ -269,7 +_,10 @@
public void sendPairingData(final ServerPlayer player, final Consumer<Packet<ClientGamePacketListener>> broadcast) {
this.entity.updateDataBeforeSync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,17 @@
if (destroyedBlock) {
BlockPos randomPos = new BlockPos(
x0 + this.random.nextInt(x1 - x0 + 1), y0 + this.random.nextInt(y1 - y0 + 1), z0 + this.random.nextInt(z1 - z0 + 1)
@@ -501,7 +_,15 @@
@@ -493,15 +_,23 @@
}

@Override
- public void knockback(final double power, final double xd, final double zd) {
+ public void knockback(final double power, final double xd, final double zd, final @Nullable Entity attacker, final io.papermc.paper.event.entity.EntityKnockbackEvent.Cause eventCause) { // Paper - knockback events
if (!this.phaseManager.getCurrentPhase().isSitting()) {
- super.knockback(power, xd, zd);
+ super.knockback(power, xd, zd, attacker, eventCause); // Paper - knockback events
}
}

@Override
public void kill(final ServerLevel level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
return true;
} else {
return false;
@@ -1109,19 +_,40 @@
@@ -1109,18 +_,35 @@
public void causeExtraKnockback(final Entity entity, final float knockbackAmount, final Vec3 oldMovement) {
if (knockbackAmount > 0.0F) {
if (entity instanceof LivingEntity livingTarget) {
Expand All @@ -311,29 +311,25 @@
}

if (entity instanceof ServerPlayer && entity.hurtMarked) {
+ // CraftBukkit start - Add Velocity Event
+ boolean cancelled = false;
- ((ServerPlayer)entity).connection.send(new ClientboundSetEntityMotionPacket(entity));
+ // Paper start - Add Velocity Event
+ org.bukkit.entity.Player player = (org.bukkit.entity.Player) entity.getBukkitEntity();
+ org.bukkit.util.Vector velocity = org.bukkit.craftbukkit.util.CraftVector.toBukkit(oldMovement);
+
+ org.bukkit.event.player.PlayerVelocityEvent event = new org.bukkit.event.player.PlayerVelocityEvent(player, velocity.clone());
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
entity.hurtMarked = false;
+ if (!event.callEvent()) {
+ return;
Comment thread
Doc94 marked this conversation as resolved.
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+
+ if (!cancelled) {
((ServerPlayer)entity).connection.send(new ClientboundSetEntityMotionPacket(entity));
entity.hurtMarked = false;
+ // Paper end
+ ((ServerPlayer)entity).connection.send(new ClientboundSetEntityMotionPacket(entity));
+ // entity.hurtMarked = false; // Paper - move before PlayerVelocityEvent call
entity.setDeltaMovement(oldMovement);
+ }
+ // CraftBukkit end
}
}

@@ -1142,8 +_,11 @@
&& !(nearby instanceof ArmorStand armorStand && armorStand.isMarker())
&& this.distanceToSqr(nearby) < 9.0) {
Expand Down
Loading