2023-08-22 07:22:05 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: RodneyMKay <36546810+RodneyMKay@users.noreply.github.com>
|
|
|
|
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
|
2024-06-14 10:17:11 +02:00
|
|
|
index 9206806204862e7b50f5c520660a07bdd7604480..122244a37872a21fe0df5f6ab8f4cad941b59479 100644
|
2023-08-22 07:22:05 +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
|
|
|
@@ -935,8 +935,17 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
2023-08-22 07:22:05 +02:00
|
|
|
this.disconnect("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
|
2024-01-21 12:11:43 +01:00
|
|
|
// Paper end - validate pick item position
|
2024-01-14 16:31:39 +01:00
|
|
|
+ // Paper start - Add PlayerPickItemEvent
|
2023-08-22 07:22:05 +02:00
|
|
|
+ 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());
|
2024-01-14 16:31:39 +01:00
|
|
|
+ // Paper end - Add PlayerPickItemEvent
|
2023-08-22 07:22:05 +02:00
|
|
|
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())));
|
2024-01-14 16:31:39 +01:00
|
|
|
this.player.connection.send(new ClientboundSetCarriedItemPacket(this.player.getInventory().selected));
|
2023-08-22 07:22:05 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Inventory.java b/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
2024-06-14 10:17:11 +02:00
|
|
|
index 688ed0c32b05b0135b94ec05738cdc6ff8dcb677..a62e7354bf67a66bdf9cd7c8f5d2e8f6bcacc74f 100644
|
2023-08-22 07:22:05 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
2024-04-25 00:36:49 +02:00
|
|
|
@@ -171,7 +171,13 @@ public class Inventory implements Container, Nameable {
|
2023-08-22 07:22:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2024-01-14 16:31:39 +01:00
|
|
|
+ // Paper end - Add PlayerPickItemEvent
|
2023-08-22 07:22:05 +02:00
|
|
|
ItemStack itemstack = (ItemStack) this.items.get(this.selected);
|
|
|
|
|
|
|
|
this.items.set(this.selected, (ItemStack) this.items.get(slot));
|