Clearing inventory of (Material, Amount)

Discussion in 'Plugin Development' started by Ape101, Mar 8, 2014.

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

    Ape101

    How can i clear a players inventory of a certain material and a certain amount?
    im creating a shop and a player uses the sign gui to enter an amount of an item to sell, so how would i then clear their inventory of that amount of that material?
     
  2. Offline

    Shayana

    Iterate through the inventory content, when you find an ItemStack with the requested material, set its amount as the old amount minus what you want to remove ?
     
  3. Offline

    Ape101

    Sounds like it would work. But i've never used an iterator before. Mind showing an example?
     
  4. Offline

    Shayana

    The iterator is not very used for this purpose... I mean you can use a for loop for every ItemStack in the inventory.
    Would look like this :

    Code:java
    1. for(ItemStack is : inventory.getContent()) {
    2. //do stuff
    3. }
     
  5. Offline

    Ape101

    Is there even a method to remove items in that though?
    i think i could use that for loop, i just dont know how to remove the items
     
  6. Offline

    Shayana

    According to Javadocs, you can remove an ItemStack from the Inventory depending on its material, or matching an ItemStack you've specified.
    Using the for loop I gave you, these methods are useless. You would rather need to set the amount of the itemstack you are looking at, even 0 if you need to remove 64+ items of its material.
    Feel free to post the code you used when you tried, I can help you with that !
     
Thread Status:
Not open for further replies.

Share This Page