Removing a certain number of items from a players inventory - how?

Discussion in 'Plugin Development' started by barrysmith, Oct 14, 2013.

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

    barrysmith

    I can't seem to find any simple, bog-standard way of removing n number of item x from a players inventory. I want to remove 38 emeralds from a players inventory assuming he / she has them already.

    Is there just a single method to achieve this? The bukkit documentation seemed very vague on this subject :(

    Thanks
     
  2. Offline

    SuperOmegaCow

    barrysmith get how many emeralds they have at the moment and subtract that by 38 then give them what ever is left.
     
  3. Offline

    The_Doctor_123

    SuperOmegaCow
    One problem, the items may end up in different slots, making it look bad.

    Now, Bukkit doesn't provide what you want to do(which they really should..), but you could write up a method to do what you want to happen. I can't right now because I'm busy.
     
  4. Offline

    sgavster

    ~untested

    Code:java
    1. ItemStack e = new ItemStack(Material.EMERALD);
    2. if(e.getAmount() >= 38)
    3. {
    4. if(p.getInventory().contains(e))
    5. {
    6. p.getInventory().removeItem(new ItemStack(Material.EMERALD, 38));
    7. }
    8. }
     
  5. Offline

    barrysmith

  6. Offline

    sgavster

    barrysmith No problem!~
    By the way, to tag people just press the 'tahg' button on our posts or write name, you don't need to self-link it :D
     
Thread Status:
Not open for further replies.

Share This Page