Get number of empty slots in players inventory?

Discussion in 'Plugin Development' started by ice374, Jul 23, 2013.

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

    ice374

    How would I get the number of empty item slots in a players inventory as an int?

    I figure that I would need to cycle through the slots and add the so I have this, but that's about it.


    Code:
                for (ItemStack stack : contents) {
                    if (stack == null) {
                        continue;
    //add to some counter here
                    }

    I rarely do this but... I need code :-/
     
  2. ice374
    Try this
    Code:JAVA
    1.  
    2. public int getEmptySlots(Inventory inventory) {
    3. int i = 0;
    4. for (ItemStack is : inventory.getContents()) {
    5. if (is == null)
    6. continue;
    7. i++;
    8. }
    9. return i;
    10. }
    11.  
     
Thread Status:
Not open for further replies.

Share This Page