aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0876-Add-PlayerPickItemEvent.patch
diff options
context:
space:
mode:
authorNassim Jahnke <[email protected]>2024-06-16 12:56:00 +0200
committerNassim Jahnke <[email protected]>2024-06-16 12:56:00 +0200
commitdc684c60d16f66ea84467ec8e253f2a36a17a7c8 (patch)
treee516f1bd4bfbdb37a5aeee42384aade111eca3e1 /patches/server/0876-Add-PlayerPickItemEvent.patch
parent752f957e12e4ceb8b7d2043a4a7dbce786b7b98f (diff)
downloadPaper-dc684c60d16f66ea84467ec8e253f2a36a17a7c8.tar.gz
Paper-dc684c60d16f66ea84467ec8e253f2a36a17a7c8.zip
Remove bad server.scheduleOnMain disconnect calls from old patches
The new behavior of disconnect to block the current thread until the disconnect succeeded is better than throwing it off to happen at some point
Diffstat (limited to 'patches/server/0876-Add-PlayerPickItemEvent.patch')
-rw-r--r--patches/server/0876-Add-PlayerPickItemEvent.patch48
1 files changed, 48 insertions, 0 deletions
diff --git a/patches/server/0876-Add-PlayerPickItemEvent.patch b/patches/server/0876-Add-PlayerPickItemEvent.patch
new file mode 100644
index 0000000000..e97cdf35c3
--- /dev/null
+++ b/patches/server/0876-Add-PlayerPickItemEvent.patch
@@ -0,0 +1,48 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: RodneyMKay <[email protected]>
+Date: Wed, 8 Sep 2021 21:34:01 +0200
+Subject: [PATCH] Add PlayerPickItemEvent
+
+
+diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+index 48c1327d7226fdbb34ef0cc9e6516aaf94e6781c..5694afb14889187a4cfc342ccf497dd6ca867f0e 100644
+--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
++++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+@@ -935,8 +935,17 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
+ this.disconnect(Component.literal("Invalid hotbar selection (Hacking?)"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION); // Paper - kick event cause
+ return;
+ }
+- this.player.getInventory().pickSlot(packet.getSlot()); // Paper - Diff above if changed
+ // Paper end - validate pick item position
++ // Paper start - Add PlayerPickItemEvent
++ Player bukkitPlayer = this.player.getBukkitEntity();
++ int targetSlot = this.player.getInventory().getSuitableHotbarSlot();
++ int sourceSlot = packet.getSlot();
++
++ io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot);
++ if (!event.callEvent()) return;
++
++ this.player.getInventory().pickSlot(event.getSourceSlot(), event.getTargetSlot());
++ // Paper end - Add PlayerPickItemEvent
+ this.player.connection.send(new ClientboundContainerSetSlotPacket(-2, 0, this.player.getInventory().selected, this.player.getInventory().getItem(this.player.getInventory().selected)));
+ this.player.connection.send(new ClientboundContainerSetSlotPacket(-2, 0, packet.getSlot(), this.player.getInventory().getItem(packet.getSlot())));
+ this.player.connection.send(new ClientboundSetCarriedItemPacket(this.player.getInventory().selected));
+diff --git a/src/main/java/net/minecraft/world/entity/player/Inventory.java b/src/main/java/net/minecraft/world/entity/player/Inventory.java
+index 688ed0c32b05b0135b94ec05738cdc6ff8dcb677..a62e7354bf67a66bdf9cd7c8f5d2e8f6bcacc74f 100644
+--- a/src/main/java/net/minecraft/world/entity/player/Inventory.java
++++ b/src/main/java/net/minecraft/world/entity/player/Inventory.java
+@@ -171,7 +171,13 @@ public class Inventory implements Container, Nameable {
+ }
+
+ public void pickSlot(int slot) {
+- this.selected = this.getSuitableHotbarSlot();
++ // Paper start - Add PlayerPickItemEvent
++ pickSlot(slot, this.getSuitableHotbarSlot());
++ }
++
++ public void pickSlot(int slot, int targetSlot) {
++ this.selected = targetSlot;
++ // Paper end - Add PlayerPickItemEvent
+ ItemStack itemstack = (ItemStack) this.items.get(this.selected);
+
+ this.items.set(this.selected, (ItemStack) this.items.get(slot));