Create Enchantment Book

Discussion in 'Spigot Plugin Development' started by Nosxxx, May 21, 2015.

  1. I would like to create a Enchantment Book by my plugin.

    I tried the following ways:

    item = new ItemStack( Material.BOOK, amount );
    item.addUnsafeEnchantment( ench, level );

    item = new ItemStack( material, amount );
    ItemMeta meta = item.getItemMeta();
    meta.addEnchant( ench, level, false );
    item.setItemMeta( meta );

    It creates the book, but the player isn't able to enchant his sword with his anvil.

    May someone can help me ?
     
  2. Do this:

    Code (Text):

    item = new ItemStack( Material.BOOK, amount );
    item.addUnsafeEnchantment( ench, level );
     
    For whatever reason I've also had bad luck when attempting at add enchantments to the item's ItemMeta. Just use addUnsafeEnchantment() on the ItemStack.