int i = playerinventory.findSlotMatchingItem(stack);
+ // Paper start - Add PlayerPickItemEvent
+ final int sourceSlot = i;
+ final int targetSlot = Inventory.isHotbarSlot(sourceSlot) ? sourceSlot : playerinventory.getSuitableHotbarSlot();
+ final Player bukkitPlayer = this.player.getBukkitEntity();
+ final io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot);
+ if (!event.callEvent()) {
+ return;
+ }
+ // Paper end - Add PlayerPickItemEvent
if (i != -1) {
if (Inventory.isHotbarSlot(i)) {
- playerinventory.selected = i;
+ playerinventory.selected = event.getTargetSlot(); // Paper - Add target slot
} else {
- playerinventory.pickSlot(i);
+ playerinventory.pickSlot(i, event.getTargetSlot()); // Paper - Add target slot
}
} else if (this.player.hasInfiniteMaterials()) {
- playerinventory.addAndPickItem(stack);
+ playerinventory.addAndPickItem(stack, event.getTargetSlot()); // Paper - Add target slot