Solved Difference between ItemStack.addEnchantment and ItemMeta.addEnchant

Discussion in 'Spigot Plugin Development' started by Sytm, Mar 25, 2020.

Thread Status:
Not open for further replies.
  1. So basically the title says it all. Whats the difference between those two methods, is there any situation where you would choose one over the another and why?

    The JavaDocs of these methods are not really useful in this situation

    ItemStack#addEnchantment
    ItemMeta#addEnchant

    And when I try to google a possible answer all I get is how to add an enchantment, but not the difference between those two
     
  2. SteelPhoenix

    Moderator

    ItemStack#addEnchantment(...) is just an easy-access method, but internally it just calls the ItemMeta#addEnchant(...) method.
    You should stick to the latter one though, as the first one might get removed in the future. Other easy-access methods that modify the meta have been removed in the past.
     
  3. Basically no difference, use whatever is more convenient.

    This is the almost the same as asking whether to use Bukkit static methods or to use Bukkit#getServer().
     
  4. Thank you all for the answer! Have been wondering what the difference is for quite a while.
    And thanks for this, so I am gonna use the ItemMeta variant.
     
Thread Status:
Not open for further replies.