How do I remove enchanted items from inventory?

Discussion in 'Plugin Development' started by Colby l, Feb 9, 2014.

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

    Colby l

    I'm trying to remove an enchanted item from the inventory of a player, without him/her having to have the item held in their hand.

    I need to check if the player has the enchanted version of the item, if not, remove the non-enchanted item. If they have the enchanted item, then remove it from their inventory.

    Thanks for the help, and comment if you need any more details.
     
  2. Colby l
    Couldn't you just use Inventory#remove(), because you're going to remove the ItemStack from the inventory, enchanted or not?
     
  3. Offline

    Colby l

    I've tried that, and the item won't remove from the inventory.

    Code:java
    1. // Config variables
    2. int itemChargeAmount = config.getItemChargeAmount(tier);
    3. String itemChargeEnum = config.getItemChargeEnum(tier);
    4.  
    5. PlayerInventory inventory = p.getInventory();
    6. // removes item(s)
    7. //makes the itemName usable in the Messages constructor
    8. String itemName = Material.getMaterial(itemChargeEnum).name();
    9. //test
    10.  
    11. //Removes item from inventory
    12. inventory.removeItem(new ItemStack(Material.getMaterial(itemChargeEnum), itemChargeAmount));
    13. //Sends player message about what, and how much, of the item was removed
    14. p.sendMessage(ChatColor.GREEN + Messages.itemRemovedMessage(p, itemName, itemChargeAmount) /*"I'll take that " + Material.getMaterial(itemChargeEnum).name() + ", " + p.getName() + (".")*/);
    15. }
     
Thread Status:
Not open for further replies.

Share This Page