Skip to content

ItemMeta#addAttributeModifier wrongly throws IllegalArgumentException #9993

@hyper1423

Description

@hyper1423

Expected behavior

It should be allowed to add AttributeModifiers with same UUID into ItemMeta as long as they have different Attribute types, which is the vanilla behavior.

Observed/Actual behavior

ItemMeta#addAttributeModifier wrongly throws an IllegalArgumentException on adding such an AttributeModifier.

Steps/models to reproduce

ItemStack item = <...>;
item.editMeta((meta) -> {
    AttributeModifier modifier = new AttributeModifier(UUID.randomUUID(), "Example", 69420.0, AttributeModifier.Operation.ADD_NUMBER);
    meta.addAttributeModifier(Attribute.GENERIC_ARMOR, modifier);
    meta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, modifier); // Throws IllegalArgumentException
});

Plugin and Datapack List

The only plugin I have is the one I am developing, but it does not seem to be the issue.
I have no datapacks on my server.

Paper version

This server is running Paper version git-Paper-310 (MC: 1.20.2) (Implementing API version 1.20.2-R0.1-SNAPSHOT) (Git: 9993eb9)
You are running the latest version
Previous version: git-Paper-309 (MC: 1.20.2)

(There was a paper update literally while writing this report... I thought my gradle plugin broke lol)

Other

Line 1177-1179 of org.bukkit.craftbukkit.v1_20_R2.inventory.CraftMetaItem:

for (Map.Entry<Attribute, AttributeModifier> entry : this.attributeModifiers.entries()) {
    Preconditions.checkArgument(!entry.getValue().getUniqueId().equals(modifier.getUniqueId()), "Cannot register AttributeModifier. Modifier is already applied! %s", modifier);
}

The issue could be resolved by fixing line 1178 to take Attribute into consideration:

for (Map.Entry<Attribute, AttributeModifier> entry : this.attributeModifiers.entries()) {
    Preconditions.checkArgument(!(entry.getValue().getUniqueId().equals(modifier.getUniqueId()) && entry.getKey() == attribute), "Cannot register AttributeModifier. Modifier is already applied! %s", modifier);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueSimple bug fix or feature which would be a good first PR for someone new to the projectstatus: acceptedDisputed bug is accepted as valid or Feature accepted as desired to be added.type: bugSomething doesn't work as it was intended to.

    Type

    No fields configured for Bug.

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions