How to delete items in inventory?

Discussion in 'Plugin Development' started by MrJenteZ, Feb 9, 2016.

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


    Hey there.

    I have a problem deleting items that are 'used' meaning with durability.

    My plugin give's kits to people and for example when they use the sword, and then 'leave' the arena, it doesn't remove because of the durability, because it removes without durability.

    Any solutions?

    her's the code where i give and remove the items:
    if(s.getLine(2).equalsIgnoreCase(ChatColor.AQUA.toString() + ChatColor.BOLD + "Warrior"))
                                    PlayerInventory inv = e.getPlayer().getInventory();
                                    inv.removeItem(new ItemStack(Material.DIAMOND_SWORD, 1));
                                    inv.removeItem(new ItemStack(Material.BOW, 1));
                                    inv.removeItem(new ItemStack(Material.ARROW, 10));
                                    inv.removeItem(new ItemStack(Material.ENDER_PEARL, 10));
                                    inv.removeItem(new ItemStack(Material.OBSIDIAN, 14));
                                    inv.removeItem(new ItemStack(Material.FIREBALL, 10));
                                    inv.removeItem(new ItemStack(Material.GOLDEN_APPLE, 5));
                                    inv.removeItem(new ItemStack(Material.FLINT_AND_STEEL, 1));
                                    inv.removeItem(new ItemStack(373, 1, (short) 16420));
                                    inv.addItem(new ItemStack(Material.DIAMOND_SWORD, 1));
  2. Offline



    maby i'm wrong but whats the problem with Inventory#clear();?
  3. Offline


    This plugin can be used in survival, so i don't want them to lose all their stuff.
  4. Offline


    Why not store their inventory before they enter the arena, clear it, give them the kit, then when they're done in the arena clear the kit and give them their inv back.

    And the reason it's not working is you're telling it to remove the item with durability exactly equal to 16420
    inv.removeItem(new ItemStack(373, 1, (short)16420));
  5. Offline


    That's a potion. Everything get's deleted except for the bow and sword and flint and steel.
  6. Offline


    Loop trough the inventory, and if an itemstack's type is bow, remove it
  7. Offline


    Wouldn't i do the same thing as here then?
  8. Offline


  9. Offline


    Wouldn't i do the same thing as here then?
    But that doesn't work. It doesn't remove the item when there's a durability on it.
  10. Offline


    Then we missunderstood each other. I meant, just use a foreach loop, and loop trough the items on the inventory, then check, if it is a bow/sword/etc, and if it is, remove it.
  11. Offline


    I don't get it. I'll explain it again.

    If players have the bow or sword or flint and steel, but they didn't use it, so there's no durability, it does get removed.
    but when they used it, the item receives durability and then it doesn't remove.
  12. Offline


  13. Offline


    Zombie_Striker likes this.
  14. Offline


  15. Offline


    If you don't understand the javadocs then you should learn how to before coming on this forums. It really bugs a lot of people that you are making the same post that someone else already has, and then ask for something that's just a quick google search away.
    Edit: Can't you simply give the item a max durability and then remove it?
    Last edited: Feb 10, 2016
Thread Status:
Not open for further replies.

Share This Page