How to remove items with a custom name and lore from a player's inventory

Discussion in 'Plugin Development' started by RickRaider, May 28, 2013.

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

    RickRaider

    Hi.

    I would like to know how to remove an item, that has been renamed and has a lore, from a player's inventory. Just removing the Material type doesn't work, because the ItemMeta is different. Any suggestions?
     
  2. Offline

    Froshin

    Is it okay to remove everything with the same ID?


    Otherwise you've got to define the itemStacks custom Meta and apply it onto the defined itemstack and then remove it, or alternatively remove all the items with the same meta. Which essentially would be pretty much the same thing, lol.

    You could go by it's display name aswell... There are many options! Sorry if my answer isn't optimal, I'm very much a newbie. But the two options I listed should be pretty easily executed.
     
  3. Offline

    Minnymin3

    Code:java
    1.  
    2. for (ItemStack i : player.getInventory().getContents) {
    3. if (i.getType == Material.SOMETHING
    4. && i.hasItemMeta() && i.getItemMeta().hasDisplayName()
    5. && i.getItemMeta().getDisplayName().equalsIgnoreCase("This is the name") {
    6. ItemStack item = i;
    7. player.getInventory().remove(i);
    8. }
     
Thread Status:
Not open for further replies.

Share This Page