Solved Enchanting a item in hand

Discussion in 'Plugin Development' started by 99storm2, Jun 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    99storm2

    I am making a plugin that will enchant the item in hand kinda like /enchant. Im stuck on enchanting the item though. I know when adding the item to a players inventory you do like itemmeta.addEnchantment(Enchantment.KNOCKBACK, 3);
    but how would you add it to a item in the players inventory already?
     
  2. Offline

    rfsantos1996

    player.getItemOnHand() and update it's meta with the enchantment added
     
    99storm2 likes this.
  3. Offline

    _feedDz

    mkae the item a variable like
    ItemStack item = player.getItemInHand();
    then do
    item.addEnchant(Enchantment.KNOCKBACK,3);

    then do player.getInventory().add(item);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
    99storm2 likes this.
  4. Offline

    99storm2

    rfsantos1996
    Thanks

    Code i used incase anyone needs help with this in the future:
    Code:java
    1. ItemMeta im = player.getItemInHand().getItemMeta();
    2. im.addEnchant(Enchantment.DAMAGE_ALL, enchlev, true);
    3. player.getItemInHand().setItemMeta(im);
    4.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
Thread Status:
Not open for further replies.

Share This Page