From a3c944c37bbe4b54525dc23a42c44274945f16fe Mon Sep 17 00:00:00 2001 From: chickeneer Date: Thu, 22 Apr 2021 19:02:07 -0700 Subject: [PATCH] fix PlayerItemHeldEvent firing twice --- .../ServerGamePacketListenerImpl.java.patch | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 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 ae1650b8d3..1eb7688d7d 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 @@ -1172,12 +1172,13 @@ this.player.getTextFilter().leave(); } -@@ -1367,7 +2012,16 @@ +@@ -1367,7 +2012,17 @@ @Override public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); + if (this.player.isImmobile()) return; // CraftBukkit if (packet.getSlot() >= 0 && packet.getSlot() < Inventory.getSelectionSize()) { ++ if (packet.getSlot() == this.player.getInventory().selected) { return; } // Paper - don't fire itemheldevent when there wasn't a slot change + PlayerItemHeldEvent event = new PlayerItemHeldEvent(this.getCraftPlayer(), this.player.getInventory().selected, packet.getSlot()); + this.cserver.getPluginManager().callEvent(event); + if (event.isCancelled()) { @@ -1189,7 +1190,7 @@ if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) { this.player.stopUsingItem(); } -@@ -1376,11 +2030,18 @@ +@@ -1376,11 +2031,18 @@ this.player.resetLastActionTime(); } else { ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); @@ -1208,7 +1209,7 @@ Optional optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages()); if (!optional.isEmpty()) { -@@ -1394,27 +2055,44 @@ +@@ -1394,27 +2056,44 @@ return; } @@ -1260,7 +1261,7 @@ ParseResults parseresults = this.parseCommand(command); if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) { -@@ -1431,19 +2109,37 @@ +@@ -1431,19 +2110,37 @@ if (!optional.isEmpty()) { this.tryHandleChat(packet.command(), () -> { @@ -1302,7 +1303,7 @@ } catch (SignedMessageChain.DecodeException signedmessagechain_a) { this.handleMessageDecodeFailure(signedmessagechain_a); return; -@@ -1451,10 +2147,10 @@ +@@ -1451,10 +2148,10 @@ CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map); @@ -1315,7 +1316,7 @@ } private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) { -@@ -1530,14 +2226,20 @@ +@@ -1530,14 +2227,20 @@ return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack()); } @@ -1340,7 +1341,7 @@ } } -@@ -1566,6 +2268,127 @@ +@@ -1566,6 +2269,127 @@ return false; } @@ -1468,7 +1469,7 @@ private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException { SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages); -@@ -1573,13 +2396,42 @@ +@@ -1573,13 +2397,42 @@ } private void broadcastChatMessage(PlayerChatMessage message) { @@ -1516,7 +1517,7 @@ this.disconnect((Component) Component.translatable("disconnect.spam")); } -@@ -1601,7 +2453,40 @@ +@@ -1601,7 +2454,40 @@ @Override public void handleAnimate(ServerboundSwingPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1557,7 +1558,7 @@ this.player.swing(packet.getHand()); } -@@ -1609,6 +2494,29 @@ +@@ -1609,6 +2495,29 @@ public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (this.player.hasClientLoaded()) { @@ -1587,7 +1588,7 @@ this.player.resetLastActionTime(); Entity entity; PlayerRideableJumping ijumpable; -@@ -1616,6 +2524,11 @@ +@@ -1616,6 +2525,11 @@ switch (packet.getAction()) { case PRESS_SHIFT_KEY: this.player.setShiftKeyDown(true); @@ -1599,7 +1600,7 @@ break; case RELEASE_SHIFT_KEY: this.player.setShiftKeyDown(false); -@@ -1691,6 +2604,12 @@ +@@ -1691,6 +2605,12 @@ } public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound params) { @@ -1612,7 +1613,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 +2622,13 @@ +@@ -1703,6 +2623,13 @@ return this.connection.getRemoteAddress(); } @@ -1626,7 +1627,7 @@ public void switchToConfig() { this.waitingForSwitchToConfig = true; this.removePlayerFromWorld(); -@@ -1718,9 +2644,17 @@ +@@ -1718,9 +2645,17 @@ @Override public void handleInteract(ServerboundInteractPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1644,7 +1645,7 @@ this.player.resetLastActionTime(); this.player.setShiftKeyDown(packet.isUsingSecondaryAction()); -@@ -1733,20 +2667,58 @@ +@@ -1733,20 +2668,58 @@ if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { packet.dispatch(new ServerboundInteractPacket.Handler() { @@ -1707,7 +1708,7 @@ } } -@@ -1755,19 +2727,20 @@ +@@ -1755,19 +2728,20 @@ @Override public void onInteraction(InteractionHand hand) { @@ -1731,7 +1732,7 @@ label23: { if (entity instanceof AbstractArrow) { -@@ -1785,6 +2758,11 @@ +@@ -1785,6 +2759,11 @@ } ServerGamePacketListenerImpl.this.player.attack(entity); @@ -1743,7 +1744,7 @@ return; } } -@@ -1795,7 +2773,26 @@ +@@ -1795,7 +2774,26 @@ }); } } @@ -1770,7 +1771,7 @@ } } -@@ -1809,7 +2806,7 @@ +@@ -1809,7 +2807,7 @@ case PERFORM_RESPAWN: if (this.player.wonGame) { this.player.wonGame = false; @@ -1779,7 +1780,7 @@ this.resetPosition(); CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD); } else { -@@ -1817,11 +2814,11 @@ +@@ -1817,11 +2815,11 @@ return; } @@ -1793,7 +1794,7 @@ } } break; -@@ -1833,16 +2830,27 @@ +@@ -1833,16 +2831,27 @@ @Override public void handleContainerClose(ServerboundContainerClosePacket packet) { @@ -1823,7 +1824,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 +2863,284 @@ +@@ -1855,7 +2864,284 @@ boolean flag = packet.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -2109,7 +2110,7 @@ ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator(); while (objectiterator.hasNext()) { -@@ -1879,6 +3164,14 @@ +@@ -1879,6 +3165,14 @@ @Override public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) { @@ -2124,7 +2125,7 @@ PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); this.player.resetLastActionTime(); if (!this.player.isSpectator() && this.player.containerMenu.containerId == packet.containerId()) { -@@ -1900,9 +3193,43 @@ +@@ -1900,9 +3194,43 @@ ServerGamePacketListenerImpl.LOGGER.debug("Player {} tried to place impossible recipe {}", this.player, recipeholder.id().location()); return; } @@ -2169,7 +2170,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 +3244,7 @@ +@@ -1917,6 +3245,7 @@ @Override public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -2177,7 +2178,7 @@ this.player.resetLastActionTime(); if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) { if (!this.player.containerMenu.stillValid(this.player)) { -@@ -1945,6 +3273,43 @@ +@@ -1945,6 +3274,43 @@ boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize(); @@ -2221,7 +2222,7 @@ if (flag1 && flag2) { this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack); -@@ -1964,7 +3329,19 @@ +@@ -1964,7 +3330,19 @@ @Override public void handleSignUpdate(ServerboundSignUpdatePacket packet) { @@ -2242,7 +2243,7 @@ this.filterTextPacket(list).thenAcceptAsync((list1) -> { this.updateSignText(packet, list1); -@@ -1972,6 +3349,7 @@ +@@ -1972,6 +3350,7 @@ } private void updateSignText(ServerboundSignUpdatePacket packet, List signText) { @@ -2250,7 +2251,7 @@ this.player.resetLastActionTime(); ServerLevel worldserver = this.player.serverLevel(); BlockPos blockposition = packet.getPos(); -@@ -1993,15 +3371,33 @@ +@@ -1993,15 +3372,33 @@ @Override public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -2285,7 +2286,7 @@ if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) { this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player)); } -@@ -2012,7 +3408,7 @@ +@@ -2012,7 +3409,7 @@ public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) { @@ -2294,7 +2295,7 @@ } } -@@ -2058,7 +3454,7 @@ +@@ -2058,7 +3455,7 @@ if (!this.waitingForSwitchToConfig) { throw new IllegalStateException("Client acknowledged config, but none was requested"); } else { @@ -2303,7 +2304,7 @@ } } -@@ -2083,8 +3479,10 @@ +@@ -2083,8 +3480,10 @@ }); }