From 9b0d705d63ef0255e8a89ecb244e6be870d49f79 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 --- .../ServerGamePacketListenerImpl.java.patch | 166 ++++++++++-------- .../world/entity/player/Inventory.java.patch | 30 +++- 2 files changed, 125 insertions(+), 71 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch index 19c3254507..f2b5c76e79 100644 --- a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch @@ -48,7 +48,7 @@ import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; -@@ -192,12 +196,73 @@ +@@ -192,11 +196,72 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; @@ -59,7 +59,7 @@ import net.minecraft.world.phys.shapes.VoxelShape; +import org.bukkit.NamespacedKey; import org.slf4j.Logger; - ++ +// CraftBukkit start +import io.papermc.paper.adventure.ChatProcessor; // Paper +import io.papermc.paper.adventure.PaperAdventure; // Paper @@ -118,10 +118,9 @@ +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.SmithingInventory; +// CraftBukkit end -+ + public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListener, ServerPlayerConnection, TickablePacketListener { - static final Logger LOGGER = LogUtils.getLogger(); @@ -212,7 +277,9 @@ private int tickCount; private int ackBlockChangesUpTo = -1; @@ -563,7 +562,37 @@ ServerGamePacketListenerImpl.addBlockDataToItem(iblockdata, worldserver, blockposition, itemstack); } -@@ -866,6 +1148,13 @@ +@@ -712,15 +994,25 @@ + if (stack.isItemEnabled(this.player.level().enabledFeatures())) { + Inventory playerinventory = this.player.getInventory(); + 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; ++ } ++ i = event.getSourceSlot(); + + if (i != -1) { +- if (Inventory.isHotbarSlot(i)) { +- playerinventory.selected = i; ++ if (Inventory.isHotbarSlot(i) && Inventory.isHotbarSlot(event.getTargetSlot())) { ++ playerinventory.selected = event.getTargetSlot(); + } else { +- playerinventory.pickSlot(i); ++ playerinventory.pickSlot(i, event.getTargetSlot()); + } + } else if (this.player.hasInfiniteMaterials()) { +- playerinventory.addAndPickItem(stack); ++ playerinventory.addAndPickItem(stack, event.getTargetSlot()); ++ // Paper end - Add PlayerPickItemEvent + } + + this.player.connection.send(new ClientboundSetHeldSlotPacket(playerinventory.selected)); +@@ -866,6 +1158,13 @@ AbstractContainerMenu container = this.player.containerMenu; if (container instanceof MerchantMenu containermerchant) { @@ -577,7 +606,7 @@ if (!containermerchant.stillValid(this.player)) { ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant); return; -@@ -879,6 +1168,51 @@ +@@ -879,6 +1178,51 @@ @Override public void handleEditBook(ServerboundEditBookPacket packet) { @@ -629,7 +658,7 @@ int i = packet.slot(); if (Inventory.isHotbarSlot(i) || i == 40) { -@@ -899,12 +1233,16 @@ +@@ -899,12 +1243,16 @@ } private void updateBookContents(List pages, int slotId) { @@ -647,7 +676,7 @@ } } -@@ -915,12 +1253,13 @@ +@@ -915,12 +1263,13 @@ ItemStack itemstack1 = itemstack.transmuteCopy(Items.WRITTEN_BOOK); itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT); @@ -663,7 +692,7 @@ } } -@@ -978,26 +1317,34 @@ +@@ -978,26 +1327,34 @@ public void handleMovePlayer(ServerboundMovePlayerPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (ServerGamePacketListenerImpl.containsInvalidValues(packet.getX(0.0D), packet.getY(0.0D), packet.getZ(0.0D), packet.getYRot(0.0F), packet.getXRot(0.0F))) { @@ -705,7 +734,7 @@ double d3 = this.player.getX(); double d4 = this.player.getY(); double d5 = this.player.getZ(); -@@ -1005,7 +1352,16 @@ +@@ -1005,7 +1362,16 @@ double d7 = d1 - this.firstGoodY; double d8 = d2 - this.firstGoodZ; double d9 = this.player.getDeltaMovement().lengthSqr(); @@ -723,7 +752,7 @@ if (this.player.isSleeping()) { if (d10 > 1.0D) { -@@ -1019,36 +1375,106 @@ +@@ -1019,36 +1385,106 @@ ++this.receivedMovePacketCount; int i = this.receivedMovePacketCount - this.knownMovePacketCount; @@ -736,13 +765,13 @@ + if (i > Math.max(this.allowedPlayerTicks, 5)) { ServerGamePacketListenerImpl.LOGGER.debug("{} is sending move packets too frequently ({} packets since last tick)", this.player.getName().getString(), i); i = 1; -+ } -+ + } + + if (packet.hasRot || d10 > 0) { + this.allowedPlayerTicks -= 1; + } else { + this.allowedPlayerTicks = 20; - } ++ } + double speed; + if (this.player.getAbilities().flying) { + speed = this.player.getAbilities().flyingSpeed * 20f; @@ -761,7 +790,7 @@ + // Paper end - Add fail move event + } + // Paper end - Prevent moving into unloaded chunks - ++ if (this.shouldCheckPlayerMovement(flag)) { float f2 = flag ? 300.0F : 100.0F; @@ -839,7 +868,7 @@ double d11 = d7; d6 = d0 - this.player.getX(); -@@ -1059,17 +1485,100 @@ +@@ -1059,17 +1495,100 @@ d8 = d2 - this.player.getZ(); d10 = d6 * d6 + d7 * d7 + d8 * d8; @@ -945,7 +974,7 @@ this.player.absMoveTo(d0, d1, d2, f, f1); boolean flag4 = this.player.isAutoSpinAttack(); -@@ -1119,6 +1628,7 @@ +@@ -1119,6 +1638,7 @@ this.awaitingTeleportTime = this.tickCount; this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot()); } @@ -953,7 +982,7 @@ return true; } else { -@@ -1147,23 +1657,98 @@ +@@ -1147,23 +1667,98 @@ } public void teleport(double x, double y, double z, float yaw, float pitch) { @@ -1055,7 +1084,7 @@ if (this.player.hasClientLoaded()) { BlockPos blockposition = packet.getPos(); -@@ -1175,14 +1760,46 @@ +@@ -1175,14 +1770,46 @@ if (!this.player.isSpectator()) { ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND); @@ -1104,7 +1133,7 @@ this.player.drop(false); } -@@ -1199,8 +1816,34 @@ +@@ -1199,8 +1826,34 @@ case START_DESTROY_BLOCK: case ABORT_DESTROY_BLOCK: case STOP_DESTROY_BLOCK: @@ -1139,7 +1168,7 @@ return; default: throw new IllegalArgumentException("Invalid player action"); -@@ -1218,9 +1861,31 @@ +@@ -1218,9 +1871,31 @@ } } @@ -1171,7 +1200,7 @@ if (this.player.hasClientLoaded()) { this.player.connection.ackBlockChangesUpTo(packet.getSequence()); ServerLevel worldserver = this.player.serverLevel(); -@@ -1230,6 +1895,11 @@ +@@ -1230,6 +1905,11 @@ if (itemstack.isItemEnabled(worldserver.enabledFeatures())) { BlockHitResult movingobjectpositionblock = packet.getHitResult(); Vec3 vec3d = movingobjectpositionblock.getLocation(); @@ -1183,7 +1212,7 @@ BlockPos blockposition = movingobjectpositionblock.getBlockPos(); if (this.player.canInteractWithBlock(blockposition, 1.0D)) { -@@ -1243,7 +1913,8 @@ +@@ -1243,7 +1923,8 @@ int i = this.player.level().getMaxY(); if (blockposition.getY() <= i) { @@ -1193,7 +1222,7 @@ InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); if (enuminteractionresult.consumesAction()) { -@@ -1257,11 +1928,11 @@ +@@ -1257,11 +1938,11 @@ } else if (enuminteractionresult instanceof InteractionResult.Success) { InteractionResult.Success enuminteractionresult_d = (InteractionResult.Success) enuminteractionresult; @@ -1207,7 +1236,7 @@ } else { MutableComponent ichatmutablecomponent1 = Component.translatable("build.tooHigh", i).withStyle(ChatFormatting.RED); -@@ -1281,6 +1952,8 @@ +@@ -1281,6 +1962,8 @@ @Override public void handleUseItem(ServerboundUseItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1216,7 +1245,7 @@ if (this.player.hasClientLoaded()) { this.ackBlockChangesUpTo(packet.getSequence()); ServerLevel worldserver = this.player.serverLevel(); -@@ -1296,6 +1969,47 @@ +@@ -1296,6 +1979,47 @@ this.player.absRotateTo(f, f1); } @@ -1264,7 +1293,7 @@ InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); if (enuminteractionresult instanceof InteractionResult.Success) { -@@ -1321,7 +2035,7 @@ +@@ -1321,7 +2045,7 @@ Entity entity = packet.getEntity(worldserver); if (entity != null) { @@ -1273,7 +1302,7 @@ return; } } -@@ -1342,22 +2056,52 @@ +@@ -1342,22 +2066,52 @@ @Override public void onDisconnect(DisconnectionDetails info) { @@ -1330,7 +1359,7 @@ throw new IllegalArgumentException("Expected packet sequence nr >= 0"); } else { this.ackBlockChangesUpTo = Math.max(sequence, this.ackBlockChangesUpTo); -@@ -1367,7 +2111,17 @@ +@@ -1367,7 +2121,17 @@ @Override public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1348,7 +1377,7 @@ if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) { this.player.stopUsingItem(); } -@@ -1376,11 +2130,18 @@ +@@ -1376,11 +2140,18 @@ this.player.resetLastActionTime(); } else { ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); @@ -1367,7 +1396,7 @@ Optional optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages()); if (!optional.isEmpty()) { -@@ -1394,27 +2155,46 @@ +@@ -1394,27 +2165,46 @@ return; } @@ -1421,7 +1450,7 @@ ParseResults parseresults = this.parseCommand(command); if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) { -@@ -1431,19 +2211,39 @@ +@@ -1431,19 +2221,39 @@ if (!optional.isEmpty()) { this.tryHandleChat(packet.command(), () -> { @@ -1465,7 +1494,7 @@ } catch (SignedMessageChain.DecodeException signedmessagechain_a) { this.handleMessageDecodeFailure(signedmessagechain_a); return; -@@ -1451,10 +2251,10 @@ +@@ -1451,10 +2261,10 @@ CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map); @@ -1478,7 +1507,7 @@ } private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) { -@@ -1530,14 +2330,20 @@ +@@ -1530,14 +2340,20 @@ return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack()); } @@ -1504,7 +1533,7 @@ } } -@@ -1549,7 +2355,7 @@ +@@ -1549,7 +2365,7 @@ if (optional.isEmpty()) { ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString()); @@ -1513,7 +1542,7 @@ } return optional; -@@ -1564,8 +2370,129 @@ +@@ -1564,7 +2380,128 @@ } return false; @@ -1611,8 +1640,8 @@ + this.server.console.sendMessage(s); + } + } - } - ++ } ++ + private void handleCommand(String s) { + org.spigotmc.AsyncCatcher.catchOp("Command Dispatched Async: " + s); // Paper - Add async catcher + if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot @@ -1637,13 +1666,12 @@ + return; + } finally { + } -+ } + } + // CraftBukkit end -+ + private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException { SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages); - -@@ -1573,15 +2500,44 @@ +@@ -1573,15 +2510,44 @@ } private void broadcastChatMessage(PlayerChatMessage message) { @@ -1694,7 +1722,7 @@ } -@@ -1592,7 +2548,7 @@ +@@ -1592,7 +2558,7 @@ synchronized (this.lastSeenMessages) { if (!this.lastSeenMessages.applyOffset(packet.offset())) { ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString()); @@ -1703,7 +1731,7 @@ } } -@@ -1601,7 +2557,40 @@ +@@ -1601,7 +2567,40 @@ @Override public void handleAnimate(ServerboundSwingPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1744,7 +1772,7 @@ this.player.swing(packet.getHand()); } -@@ -1609,6 +2598,29 @@ +@@ -1609,6 +2608,29 @@ public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (this.player.hasClientLoaded()) { @@ -1774,7 +1802,7 @@ this.player.resetLastActionTime(); Entity entity; PlayerRideableJumping ijumpable; -@@ -1616,6 +2628,11 @@ +@@ -1616,6 +2638,11 @@ switch (packet.getAction()) { case PRESS_SHIFT_KEY: this.player.setShiftKeyDown(true); @@ -1786,7 +1814,7 @@ break; case RELEASE_SHIFT_KEY: this.player.setShiftKeyDown(false); -@@ -1684,13 +2701,19 @@ +@@ -1684,13 +2711,19 @@ } if (i > 4096) { @@ -1807,7 +1835,7 @@ this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params)); this.addPendingMessage(message); } -@@ -1703,6 +2726,18 @@ +@@ -1703,6 +2736,18 @@ return this.connection.getRemoteAddress(); } @@ -1826,7 +1854,7 @@ public void switchToConfig() { this.waitingForSwitchToConfig = true; this.removePlayerFromWorld(); -@@ -1718,9 +2753,17 @@ +@@ -1718,9 +2763,17 @@ @Override public void handleInteract(ServerboundInteractPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1844,7 +1872,7 @@ this.player.resetLastActionTime(); this.player.setShiftKeyDown(packet.isUsingSecondaryAction()); -@@ -1733,20 +2776,58 @@ +@@ -1733,20 +2786,58 @@ if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { packet.dispatch(new ServerboundInteractPacket.Handler() { @@ -1907,7 +1935,7 @@ } } -@@ -1755,19 +2836,20 @@ +@@ -1755,19 +2846,20 @@ @Override public void onInteraction(InteractionHand hand) { @@ -1931,7 +1959,7 @@ label23: { if (entity instanceof AbstractArrow) { -@@ -1785,17 +2867,41 @@ +@@ -1785,17 +2877,41 @@ } ServerGamePacketListenerImpl.this.player.attack(entity); @@ -1974,7 +2002,7 @@ } } -@@ -1809,7 +2915,7 @@ +@@ -1809,7 +2925,7 @@ case PERFORM_RESPAWN: if (this.player.wonGame) { this.player.wonGame = false; @@ -1983,7 +2011,7 @@ this.resetPosition(); CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD); } else { -@@ -1817,11 +2923,11 @@ +@@ -1817,11 +2933,11 @@ return; } @@ -1998,7 +2026,7 @@ } } break; -@@ -1833,16 +2939,27 @@ +@@ -1833,16 +2949,27 @@ @Override public void handleContainerClose(ServerboundContainerClosePacket packet) { @@ -2028,7 +2056,7 @@ this.player.containerMenu.sendAllDataToRemote(); } else if (!this.player.containerMenu.stillValid(this.player)) { ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); -@@ -1855,7 +2972,284 @@ +@@ -1855,7 +2982,284 @@ boolean flag = packet.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -2314,7 +2342,7 @@ ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator(); while (objectiterator.hasNext()) { -@@ -1879,6 +3273,14 @@ +@@ -1879,6 +3283,14 @@ @Override public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) { @@ -2329,7 +2357,7 @@ PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); this.player.resetLastActionTime(); if (!this.player.isSpectator() && this.player.containerMenu.containerId == packet.containerId()) { -@@ -1900,9 +3302,43 @@ +@@ -1900,9 +3312,43 @@ ServerGamePacketListenerImpl.LOGGER.debug("Player {} tried to place impossible recipe {}", this.player, recipeholder.id().location()); return; } @@ -2374,7 +2402,7 @@ if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) { this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display())); } -@@ -1917,6 +3353,7 @@ +@@ -1917,6 +3363,7 @@ @Override public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -2382,7 +2410,7 @@ this.player.resetLastActionTime(); if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) { if (!this.player.containerMenu.stillValid(this.player)) { -@@ -1945,7 +3382,44 @@ +@@ -1945,7 +3392,44 @@ boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize(); @@ -2427,7 +2455,7 @@ if (flag1 && flag2) { this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack); this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack); -@@ -1964,7 +3438,19 @@ +@@ -1964,7 +3448,19 @@ @Override public void handleSignUpdate(ServerboundSignUpdatePacket packet) { @@ -2448,7 +2476,7 @@ this.filterTextPacket(list).thenAcceptAsync((list1) -> { this.updateSignText(packet, list1); -@@ -1972,6 +3458,7 @@ +@@ -1972,6 +3468,7 @@ } private void updateSignText(ServerboundSignUpdatePacket packet, List signText) { @@ -2456,7 +2484,7 @@ this.player.resetLastActionTime(); ServerLevel worldserver = this.player.serverLevel(); BlockPos blockposition = packet.getPos(); -@@ -1993,15 +3480,33 @@ +@@ -1993,15 +3490,33 @@ @Override public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -2491,7 +2519,7 @@ if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) { this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player)); } -@@ -2012,7 +3517,7 @@ +@@ -2012,7 +3527,7 @@ public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) { @@ -2500,7 +2528,7 @@ } } -@@ -2033,7 +3538,7 @@ +@@ -2033,7 +3548,7 @@ if (!Objects.equals(profilepublickey_a, profilepublickey_a1)) { if (profilepublickey_a != null && profilepublickey_a1.expiresAt().isBefore(profilepublickey_a.expiresAt())) { @@ -2509,7 +2537,7 @@ } else { try { SignatureValidator signaturevalidator = this.server.getProfileKeySignatureValidator(); -@@ -2045,8 +3550,8 @@ +@@ -2045,8 +3560,8 @@ this.resetPlayerChatState(remotechatsession_a.validate(this.player.getGameProfile(), signaturevalidator)); } catch (ProfilePublicKey.ValidationException profilepublickey_b) { @@ -2520,7 +2548,7 @@ } } -@@ -2058,7 +3563,7 @@ +@@ -2058,7 +3573,7 @@ if (!this.waitingForSwitchToConfig) { throw new IllegalStateException("Client acknowledged config, but none was requested"); } else { @@ -2529,7 +2557,7 @@ } } -@@ -2076,15 +3581,18 @@ +@@ -2076,15 +3591,18 @@ private void resetPlayerChatState(RemoteChatSession session) { this.chatSession = session; @@ -2551,7 +2579,7 @@ @Override public void handleClientTickEnd(ServerboundClientTickEndPacket packet) { -@@ -2115,4 +3623,17 @@ +@@ -2115,4 +3633,17 @@ InteractionResult run(ServerPlayer player, Entity entity, InteractionHand hand); } diff --git a/paper-server/patches/sources/net/minecraft/world/entity/player/Inventory.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/player/Inventory.java.patch index 1ab445eb99..e3c7a74106 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/player/Inventory.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/player/Inventory.java.patch @@ -50,7 +50,7 @@ + public org.bukkit.inventory.InventoryHolder getOwner() { + return this.player.getBukkitEntity(); + } - ++ + @Override + public int getMaxStackSize() { + return this.maxStack; @@ -59,7 +59,7 @@ + public void setMaxStackSize(int size) { + this.maxStack = size; + } -+ + + @Override + public Location getLocation() { + return this.player.getBukkitEntity().getLocation(); @@ -98,3 +98,29 @@ public int getFreeSlot() { for (int i = 0; i < this.items.size(); ++i) { if (((ItemStack) this.items.get(i)).isEmpty()) { +@@ -69,8 +145,10 @@ + return -1; + } + +- public void addAndPickItem(ItemStack stack) { +- this.selected = this.getSuitableHotbarSlot(); ++ // Paper start - Add PlayerPickItemEvent ++ public void addAndPickItem(ItemStack stack, final int targetSlot) { ++ this.selected = targetSlot; ++ // Paper end - Add PlayerPickItemEvent + if (!((ItemStack) this.items.get(this.selected)).isEmpty()) { + int i = this.getFreeSlot(); + +@@ -82,8 +160,10 @@ + this.items.set(this.selected, stack); + } + +- public void pickSlot(int slot) { +- this.selected = this.getSuitableHotbarSlot(); ++ // Paper start - Add PlayerPickItemEvent ++ public void pickSlot(int slot, final 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));