Force update attributes

See https://github.com/PaperMC/Paper/pull/12241/
This commit is contained in:
0x22
2025-03-07 17:57:18 -08:00
committed by Spottedleaf
parent e5d988df85
commit 743346a5da
3 changed files with 61 additions and 15 deletions

View File

@@ -547,7 +547,7 @@
addBlockDataToItem(blockState, serverLevel, blockPos, cloneItemStack);
}
@@ -685,14 +_,24 @@
@@ -685,18 +_,29 @@
if (stack.isItemEnabled(this.player.level().enabledFeatures())) {
Inventory inventory = this.player.getInventory();
int i = inventory.findSlotMatchingItem(stack);
@@ -576,6 +576,11 @@
}
this.player.connection.send(new ClientboundSetHeldSlotPacket(inventory.selected));
this.player.inventoryMenu.broadcastChanges();
+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes.
}
}
@@ -814,6 +_,13 @@
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
int item = packet.getItem();
@@ -1072,7 +1077,7 @@
if (this.player.hasClientLoaded()) {
BlockPos pos = packet.getPos();
this.player.resetLastActionTime();
@@ -1101,14 +_,46 @@
@@ -1101,32 +_,95 @@
case SWAP_ITEM_WITH_OFFHAND:
if (!this.player.isSpectator()) {
ItemStack itemInHand = this.player.getItemInHand(InteractionHand.OFF_HAND);
@@ -1098,6 +1103,7 @@
+ }
+ // CraftBukkit end
this.player.stopUsingItem();
+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes.
}
return;
@@ -1119,14 +1125,21 @@
+ }
+ // CraftBukkit end
this.player.drop(false);
+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes.
}
@@ -1120,13 +_,39 @@
return;
case DROP_ALL_ITEMS:
if (!this.player.isSpectator()) {
this.player.drop(true);
+ 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.
return;
case START_DESTROY_BLOCK:
case ABORT_DESTROY_BLOCK:
@@ -1159,6 +1172,7 @@
+ }
+ }
+ // Paper end - Send block entities after destroy prediction
+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes.
return;
default:
throw new IllegalArgumentException("Invalid player action");
@@ -1229,6 +1243,14 @@
} else {
Component component1 = Component.translatable("build.tooHigh", maxY).withStyle(ChatFormatting.RED);
this.player.sendSystemMessage(component1, true);
@@ -1187,6 +_,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.
} else {
LOGGER.warn(
"Rejecting UseItemOnPacket from {}: Location {} too far away from hit block {}.",
@@ -1203,6 +_,8 @@
@Override
public void handleUseItem(ServerboundUseItemPacket packet) {
@@ -1354,7 +1376,7 @@
throw new IllegalArgumentException("Expected packet sequence nr >= 0");
} else {
this.ackBlockChangesUpTo = Math.max(sequence, this.ackBlockChangesUpTo);
@@ -1275,7 +_,17 @@
@@ -1275,20 +_,38 @@
@Override
public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -1372,8 +1394,10 @@
if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) {
this.player.stopUsingItem();
}
@@ -1284,11 +_,18 @@
this.player.getInventory().selected = packet.getSlot();
this.player.resetLastActionTime();
+ 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
@@ -1956,7 +1980,7 @@
ServerGamePacketListenerImpl.LOGGER
.warn("Player {} tried to attack an invalid entity", ServerGamePacketListenerImpl.this.player.getName().getString());
}
@@ -1656,6 +_,26 @@
@@ -1656,6 +_,27 @@
);
}
}
@@ -1980,6 +2004,7 @@
+ });
+ }
+ // Paper end - PlayerUseUnknownEntityEvent
+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes.
}
}
@@ -2381,6 +2406,14 @@
for (Entry<ItemStack> entry : Int2ObjectMaps.fastIterable(packet.getChangedSlots())) {
this.player.containerMenu.setRemoteSlotNoCopy(entry.getIntKey(), entry.getValue());
@@ -1726,6 +_,7 @@
} else {
this.player.containerMenu.broadcastChanges();
}
+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes.
}
}
}
@@ -1733,6 +_,14 @@
@Override
@@ -2450,7 +2483,15 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1792,6 +_,43 @@
@@ -1776,6 +_,7 @@
if (flag) {
this.player.containerMenu.broadcastChanges();
}
+ this.player.detectEquipmentUpdatesPublic(); // Paper - Force update attributes.
}
}
}
@@ -1792,10 +_,48 @@
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
boolean flag2 = itemStack.isEmpty() || itemStack.getCount() <= itemStack.getMaxStackSize();
@@ -2494,6 +2535,11 @@
if (flag1 && flag2) {
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.
} else if (flag && flag2) {
if (this.dropSpamThrottler.isUnderThreshold()) {
this.dropSpamThrottler.increment();
@@ -1809,11 +_,24 @@
@Override