Skip to content

fix: keep item meta on chest items (1.26.2) - #543

Merged
tastybento merged 1 commit into
developfrom
fix/chest-item-meta
Jul 25, 2026
Merged

fix: keep item meta on chest items (1.26.2)#543
tastybento merged 1 commit into
developfrom
fix/chest-item-meta

Conversation

@tastybento

Copy link
Copy Markdown
Member

Problem

Players report chest loot arriving inert — the reported case was Plains enchanted books with no enchantments on them.

Since 1.26.0, chest files are read with plain SnakeYAML rather than YamlConfiguration, so that an item unknown to the server version can be skipped individually instead of taking down the whole file. Nothing is deserialized on the way in, though, so an item's meta: section reaches chestItem() as a plain Map — and ItemStack.deserialize only applies meta that is already an ItemMeta:

406: containsKey "meta"
430: instanceof org/bukkit/inventory/meta/ItemMeta   <-- false for a Map
442: setItemMeta                                     <-- branch never taken

The meta is dropped silently. This affects every meta-carrying chest item in every phase — potions, tipped arrows, custom-named items, banners, heads, written books — not just the books.

Not a phase-file problem: the legacy enchantment names in the YAML (PROTECTION_FALL, DAMAGE_ALL, …) are still remapped by CraftBukkit via FieldRename.ENCHANTMENT_DATA, which is built .forAllVersions(). No phase file changes needed.

Fix

chestItem() now walks the raw map depth first and deserializes any map carrying a == type key through ConfigurationSerialization before the item is built, so meta is a real ItemMeta by the time Bukkit sees it. The per-item material check and the "skip unknown item, keep the phase" behaviour from 1.26.0 are unchanged.

Fails soft: a part that cannot be deserialized is left as a map and logged, so a bad meta section costs its meta rather than the whole item.

Verification

Real Paper 26.2 server, shipped phase files, a probe plugin reading the loaded Plains chests:

1.26.0:  PROBE RESULT: 0/3 Plains enchanted books carry enchantments
1.26.2:  PROBE: book has ...minecraft:feather_falling=1
         PROBE: book has ...minecraft:fire_protection=1
         PROBE: book has ...minecraft:protection=1
         PROBE RESULT: 3/3 Plains enchanted books carry enchantments

No Skipping item or Could not read lines in the boot log, so every serialized object across all phases deserialized cleanly.

New unit test testLoadPhasesChestItemKeepsMeta loads a chest file in the shipped shape and asserts the meta section reaches the meta deserializer intact; before the fix it was never called at all. Full suite: 553 tests, 0 failures.

Version bumped to 1.26.2.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SAQ3YQkcfRoCZEwa6SPJcp

Chest files have been read with plain SnakeYAML since 1.26.0 so that an
item unknown to the server version can be skipped individually instead of
taking down the whole file. That left every nested value as a plain map,
including an item's meta section, and ItemStack.deserialize silently
ignores meta that is not already an ItemMeta. Enchanted books, potions,
custom names and anything else meta-carrying arrived stripped: players in
Plains were getting enchanted books with nothing stored on them.

Chest item maps are now walked depth first and any map carrying a "=="
type key is deserialized through ConfigurationSerialization before the
item is built, so meta is a real ItemMeta by the time Bukkit sees it. A
part that cannot be deserialized is left as a map and logged, so a bad
meta section costs its meta rather than the whole item.

Verified on a real Paper 26.2 server against the shipped phase files:
1.26.0 gave 0/3 Plains enchanted books with enchantments, this gives 3/3.
The legacy enchantment names in the phase YAML (PROTECTION_FALL and
friends) are still remapped by CraftBukkit, so no phase file changes are
needed.

Bumps version to 1.26.2.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SAQ3YQkcfRoCZEwa6SPJcp
@sonarqubecloud

Copy link
Copy Markdown

@tastybento
tastybento merged commit a4df2e3 into develop Jul 25, 2026
3 checks passed
@tastybento
tastybento deleted the fix/chest-item-meta branch July 25, 2026 19:17
@tastybento tastybento mentioned this pull request Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant