Delete items from intentory or getItemInHand.

Discussion in 'Plugin Development' started by Hourglass, Jan 30, 2011.

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

    Hourglass

    How could I do this?

    If I set player.getInventory().getItemInHand().setAmount(0); nothing happens.
    Other "solutions" don't work, too.

    Is it even possible to "delete" the item?
     
  2. Offline

    void420

    Have you tried .....setTypeId(0); or setType(Material.AIR); ?
     
  3. Offline

    Mixcoatl

    This is entirely possible. You need to use one of the clear or remove methods of the Inventory class if you want to actually destroy the item stack. I'm not certain what happens when you set the amount of an item stack to zero: I would expect Bukkit to throw an exception, but who knows?
     
  4. Offline

    Raphfrk

    Speaking of which, how do you remove the item in an armour slot?
     
  5. Offline

    Mixcoatl

    I haven't tried it, myself. Maybe something like this would work:
    Code:
    final PlayerInventory i = player.getInventory();
    // This should work... I think?
    i.removeItem(i.getBoots(), i.getChestplate(), i.getHelmet(), i.getLeggings());
    // This might also work.
    i.removeITem(i.getArmorContents());
     
  6. Offline

    Diogyn

    Hi
    I got this problem too, and none of these solution are working.
    Is there an other solution ?
    I thought to reduce the armor level as if the player got damage...

    Code:
    p.damage(5);
            p.setHealth(20);
            p.damage(5);
            p.setHealth(20);
            p.damage(5);
            p.setHealth(20);
            p.damage(5);
            p.setHealth(20);
    It's hugly and... it doesn't work.
     
Thread Status:
Not open for further replies.

Share This Page