Solved ItemMeta#getAttributeModifiers() throwing NullPointerException

Discussion in 'Plugin Development' started by X21_Eagle_X21, Jul 24, 2020.

  1. Offline


    I'm trying to add attribute modifiers to a leather helmet, but the following line throws a NullPointerException and I can't figure out why.

    helmetMeta.getAttributeModifiers(Attribute.GENERIC_ARMOR).add(new AttributeModifier("generic.armor", 2, Operation.ADD_NUMBER));
    java.lang.NullPointerException: null at org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMetaItem.getAttributeModifiers( ~[server.jar:git-Spigot-758abbe-2b00831]
    I got the code from here by the way:

    Edit: SOLVED. I updated my Spigot and while the code I wrote in this post still doesn't work, another way I was trying and that was throwing errors too does. The working code is the following.

    helmetMeta.addAttributeModifier(Attribute.GENERIC_ARMOR, new AttributeModifier("generic.armor", 2, Operation.ADD_NUMBER));
    Last edited: Jul 24, 2020

Share This Page