John Smith John Smith - 25 days ago 8
Java Question

Java HashMaps with bukkit

And how to add 2 enchantments at once in bukkit with

myItem.addEnchantments( Enchantment.KNOCKBACK, 1 /* TODO Here goes 2nd enchantment */ );


'addEnchantments' accepts 'addEnchantments(Map < Enchantment, int >)'

Answer

You rather use addEnchantment twice (or more):

myItem.addEnchantment(Enchantment.KNOCKBACK, 1);
myItem.addEnchantment(Enchantment.THRONS, 2);

If you insist on using addEnchantments you'll need to create a map, populate it and pass it:

Map<Enhancement, Integer> map = new HashMap<Enhancement, Integer>();
map.put(Enchantment.KNOCKBACK, 1);
map.put(Enchantment.THRONS, 2);

myItem.addEnchantments(map);

In your case, I would go with option 1

Comments