[SPIGOT-7646] Old PDC values of ItemMeta gets applied even if the last entry gets removed Created: 28/Apr/24  Updated: 25/Dec/24  Resolved: 28/Apr/24

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Marcel Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

Doesn't matter as it can be seen it in Source of CraftMetaItem.java - CraftBukkit - SpigotMC Stash


Version: 1.20.5
Guidelines Read: Yes

 Description   

See the following code within CraftMetaItem#applyToItem:

        if (!persistentDataContainer.isEmpty()) {
            NBTTagCompound bukkitCustomCompound = new NBTTagCompound();
            Map<String, NBTBase> rawPublicMap = persistentDataContainer.getRaw();

            for (Map.Entry<String, NBTBase> nbtBaseEntry : rawPublicMap.entrySet()) {
                bukkitCustomCompound.put(nbtBaseEntry.getKey(), nbtBaseEntry.getValue());
            }

            if (customTag == null) {
                customTag = new NBTTagCompound();
            }
            customTag.put(BUKKIT_CUSTOM_TAG.BUKKIT, bukkitCustomCompound);
        }

        if (customTag != null) {
            itemTag.put(CUSTOM_DATA, CustomData.of(customTag));
        }
    }

As you can see the customTag is only being updated in case there is any entry, meaning that it does not get updated if the last entry within the PDC gets removed. The proper solution would be to remove the

BUKKIT_CUSTOM_TAG.BUKKIT

in case the PDC is empty.


Generated at Sat Dec 13 13:43:01 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.