Remove item with display name/lore from inventory

Discussion in 'Plugin Development' started by Wbjpen, Sep 15, 2013.

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

    Wbjpen

    Does anyone have a code that would remove a item with a certain display name and lore from the player's inventory? I'd also like to be able to set the amount it takes. Thanks
     
  2. Offline

    Benatat12

    Code:java
    1. ItemStack is = new ItemStack(/*Material type*/);
    2. ItemMeta im = is.getItemMeta();
    3. im.setLore(/*what you want*/);
    4. im.setDisplayName(/*what you want*/);
    5. is.setItemMeta(im);
    6. is.setAmount(/*amount*/);
    7. for(Player p : this.getServer().getOnlinePlayers()){
    8. if(p.getInventory().contains(is)){
    9. p.getInventory().remove(is);
    10. }
    11. }

    Wbjpen
     
  3. Offline

    shmkane

    Benatat12 Hey, I'm having the same issue and this code isn't working. Is there an alternate solution by any chance?
     
  4. Offline

    drtshock

    Loop through all online players, then in that loop check their inventories as an ItemStack array, and check the item meta that way :)
     
    chaseoes likes this.
Thread Status:
Not open for further replies.

Share This Page