How to check if a player's inventory is empty. [Help]

Discussion in 'Plugin Development' started by coldguy101, May 17, 2012.

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

    coldguy101

    How would I check if a player's inventory is empty?
     
  2. I think you should try something like this:
    Code:
    if(player.getInventory().getSize() <= 0)
    {
        // do what you want...
    }
     
  3. Nope, that gives the maximum size of the inventory.

    Code:
    for(ItemStack item : player.getInventory().getContents())
    {
        if(item != null)
          return false;
    }
    return true;
    That checks if the inventory is empty, but ignores armor slots. In order to do that you just need to do the same thing but instead of getContents() use getArmorContents().
     
    Father Of Time likes this.
  4. Offline

    coldguy101

    @kimpelblase2
    Thanks!
     
  5. You misspelled me :D
    However, good luck with your project ;)
     
  6. Hmm yeah your right, thanks for correcting me:)
    greetz blackwolf12333
     
  7. Offline

    coldguy101

    Just wondering, what does the : do in the loop?
     
  8. Offline

    keelar

    It's called an "Enhanced For Loop". A quick google search will explain how it works.
     
  9. Offline

    coldguy101

    Thank you :D
     
  10. dont forgot to check the crafting slots
     
Thread Status:
Not open for further replies.

Share This Page