From 102c8bbc5414b157381bd0b1298144d6a3d97285 Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:09:27 +0100 Subject: [PATCH] Add config for updating equipment on player actions (#12275) --- .../ServerGamePacketListenerImpl.java.patch | 24 +++++++++---------- .../configuration/GlobalConfiguration.java | 2 ++ 2 files changed, 14 insertions(+), 12 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 213726106..c938c7bb9 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 @@ -577,7 +577,7 @@ this.player.connection.send(new ClientboundSetHeldSlotPacket(inventory.selected)); this.player.inventoryMenu.broadcastChanges(); -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } } @@ -1103,7 +1103,7 @@ + } + // CraftBukkit end this.player.stopUsingItem(); -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } return; @@ -1125,21 +1125,21 @@ + } + // CraftBukkit end this.player.drop(false); -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } return; case DROP_ALL_ITEMS: if (!this.player.isSpectator()) { this.player.drop(true); -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } return; case RELEASE_USE_ITEM: - this.player.releaseUsingItem(); + if (this.player.getUseItem() == this.player.getItemInHand(this.player.getUsedItemHand())) this.player.releaseUsingItem(); // Paper - validate use item before processing release -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. return; case START_DESTROY_BLOCK: case ABORT_DESTROY_BLOCK: @@ -1172,7 +1172,7 @@ + } + } + // Paper end - Send block entities after destroy prediction -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. return; default: throw new IllegalArgumentException("Invalid player action"); @@ -1247,7 +1247,7 @@ this.player.connection.send(new ClientboundBlockUpdatePacket(serverLevel, blockPos)); this.player.connection.send(new ClientboundBlockUpdatePacket(serverLevel, blockPos.relative(direction))); -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } else { LOGGER.warn( "Rejecting UseItemOnPacket from {}: Location {} too far away from hit block {}.", @@ -1397,7 +1397,7 @@ this.player.getInventory().selected = packet.getSlot(); this.player.resetLastActionTime(); -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } else { LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); + this.disconnect(Component.literal("Invalid hotbar selection (Hacking?)"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION); // CraftBukkit // Paper - kick event cause @@ -2004,7 +2004,7 @@ + }); + } + // Paper end - PlayerUseUnknownEntityEvent -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } } @@ -2410,7 +2410,7 @@ } else { this.player.containerMenu.broadcastChanges(); } -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } } } @@ -2487,7 +2487,7 @@ if (flag) { this.player.containerMenu.broadcastChanges(); } -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } } } @@ -2536,7 +2536,7 @@ this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemStack); this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemStack); this.player.inventoryMenu.broadcastChanges(); -+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes. } else if (flag && flag2) { if (this.dropSpamThrottler.isUnderThreshold()) { this.dropSpamThrottler.increment(); diff --git a/paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java index 42777adb0..a35391646 100644 --- a/paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java +++ b/paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java @@ -184,6 +184,8 @@ public class GlobalConfiguration extends ConfigurationPart { public boolean skipVanillaDamageTickWhenShieldBlocked = false; @Comment("This setting controls what compression format is used for region files.") public CompressionFormat compressionFormat = CompressionFormat.ZLIB; + @Comment("This setting controls if equipment should be updated when handling certain player actions.") + public boolean updateEquipmentOnPlayerActions = true; public enum CompressionFormat { GZIP,