From 4497cf06333666e3f620b683230cbf061bf5c65b Mon Sep 17 00:00:00 2001 From: StillLutto Date: Sat, 8 Jun 2024 21:02:03 +0200 Subject: [PATCH] Add PlayerLandEvent --- patches/api/0484-Add-PlayerLandEvent.patch | 99 +++++++++++++++++++ patches/server/1053-Add-PlayerLandEvent.patch | 34 +++++++ 2 files changed, 133 insertions(+) create mode 100644 patches/api/0484-Add-PlayerLandEvent.patch create mode 100644 patches/server/1053-Add-PlayerLandEvent.patch diff --git a/patches/api/0484-Add-PlayerLandEvent.patch b/patches/api/0484-Add-PlayerLandEvent.patch new file mode 100644 index 0000000000..00c16a511a --- /dev/null +++ b/patches/api/0484-Add-PlayerLandEvent.patch @@ -0,0 +1,99 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: StillLutto +Date: Sat, 8 Jun 2024 19:44:50 +0200 +Subject: [PATCH] Add PlayerLandEvent + + +diff --git a/src/main/java/io/papermc/paper/event/player/PlayerLandEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerLandEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0a26286eb9d807ee202df60923166525a5f3af62 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/event/player/PlayerLandEvent.java +@@ -0,0 +1,87 @@ ++package io.papermc.paper.event.player; ++ ++import com.google.common.base.Preconditions; ++import org.bukkit.Location; ++import org.bukkit.block.Block; ++import org.bukkit.entity.Player; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.player.PlayerEvent; ++import org.bukkit.event.player.PlayerMoveEvent; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.NotNull; ++ ++/** ++ * Called when the server detects the player lands on the ground. ++ *

++ * Added to avoid the overhead and special case logic that many plugins use ++ * when checking for player landing via {@link PlayerMoveEvent}, this event is fired whenever ++ * the server detects that the player lands on the ground. ++ */ ++public class PlayerLandEvent extends PlayerEvent { ++ ++ private static final HandlerList HANDLER_LIST = new HandlerList(); ++ ++ @NotNull private final Location to; ++ @NotNull private Location from; ++ @NotNull private Block mainSupportingBlock; ++ ++ @ApiStatus.Internal ++ public PlayerLandEvent(@NotNull final Player player, @NotNull final Location from, @NotNull final Location to, final Block mainSupportingBlock) { ++ super(player); ++ this.from = from; ++ this.to = to; ++ this.mainSupportingBlock = mainSupportingBlock; ++ } ++ ++ /** ++ * Gets the location where the player lands from ++ * ++ * @return Location where the player lands from ++ */ ++ @NotNull ++ public Location getFrom() { ++ return this.from; ++ } ++ ++ /** ++ * Sets the location to mark as where the player lands from ++ * ++ * @param from New location to mark as the players previous location ++ */ ++ public void setFrom(@NotNull Location from) { ++ Preconditions.checkArgument(from != null, "Cannot use null from location!"); ++ Preconditions.checkArgument(from.getWorld() != null, "Cannot use from location with null world!"); ++ this.from = from; ++ } ++ ++ /** ++ * Gets the location where the player lands ++ * ++ * @return Location where the player lands ++ */ ++ @NotNull ++ public Location getTo() { ++ return this.to.clone(); ++ } ++ ++ /** ++ * Gets the location this player jumped to ++ * ++ * @return Location the player jumped to ++ */ ++ @NotNull ++ public Block getMainSupportingBlock() { ++ return this.mainSupportingBlock; ++ } ++ ++ @NotNull ++ @Override ++ public HandlerList getHandlers() { ++ return HANDLER_LIST; ++ } ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return HANDLER_LIST; ++ } ++} diff --git a/patches/server/1053-Add-PlayerLandEvent.patch b/patches/server/1053-Add-PlayerLandEvent.patch new file mode 100644 index 0000000000..0c0cb5ed60 --- /dev/null +++ b/patches/server/1053-Add-PlayerLandEvent.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: StillLutto +Date: Sat, 8 Jun 2024 19:44:50 +0200 +Subject: [PATCH] Add PlayerLandEvent + + +diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +index 4ae88bfcead40cd05f9514a48a922a37767cb3cf..8e6d05933857764ef582a31088f7a97eed8c4cc9 100644 +--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java ++++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +@@ -193,6 +193,7 @@ import net.minecraft.world.phys.Vec3; + import net.minecraft.world.phys.shapes.BooleanOp; + import net.minecraft.world.phys.shapes.Shapes; + import net.minecraft.world.phys.shapes.VoxelShape; ++import org.bukkit.craftbukkit.block.CraftBlock; + import org.slf4j.Logger; + + // CraftBukkit start +@@ -1591,6 +1592,15 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl + this.player.absMoveTo(d0, d1, d2, f, f1); + boolean flag4 = this.player.isAutoSpinAttack(); + ++ // Paper start - Add PlayerLandEvent ++ if (flag2 && !(this.player.getY() - d4 >= 0.0)) { ++ this.player.setOnGround(true); ++ final org.bukkit.block.Block mainSupportingBlock = CraftBlock.at(this.player.level(), this.player.mainSupportingBlockPos.get()); ++ io.papermc.paper.event.player.PlayerLandEvent event = new io.papermc.paper.event.player.PlayerLandEvent(player, from, to, mainSupportingBlock); ++ event.callEvent(); ++ } ++ // Paper end - Add PlayerLandEvent ++ + this.clientIsFloating = d11 >= -0.03125D && !flag2 && this.player.gameMode.getGameModeForPlayer() != GameType.SPECTATOR && !this.server.isFlightAllowed() && !this.player.getAbilities().mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !flag && !flag4 && this.noBlocksAround(this.player); + this.player.serverLevel().getChunkSource().move(this.player); + this.player.doCheckFallDamage(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5, packet.isOnGround());