Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I check if a player has a clear inventory? I'm making a PvP arena plugin but I need it so when someone types /pvp join, it checks if they have a clear inventory. If they do have a clear inventory, it lets them join, if they don't, it asks them to.

I tried this but it's not reliable as there are more slots:

if(p.getInventory().getArmorContents() == null
    && p.getInventory().getItemInHand() == null
    && p.getInventory().getItemInHand() == null) {

Then I tried this but it did not work:

if (p.getInventory().getContents().length == 0) {
share|improve this question

You could try to accomplish it by looping through player's inventor and checking if Nth slot in his inventory is empty, if it isn't -- the function returns false.

    private boolean hasItems(ItemStack item) {
        for (int i=0; i<=thePlayer.inventory.getSizeInventory()-5; i++) {
             if (thePlayer.inventory.mainInventory[i].itemId != NULL) {
                 return false;
        return true;

You subtract 1 from the getSizeInventory() because it returns length and the arrays in Java are zero-based, and 4 because crafting slots count as well (I guess).

share|improve this answer
Arnas is correct. Check through the player inventory and return false immediately if an item is found. IIRC, there is a function mentioned in the MCP reversed code that does just that. I think it is in one of the inventory classes. – Jason Coombes Feb 11 '13 at 11:55
Why do you take in an itemstack? Where did you get thePlayer from – Bálint Jul 8 at 9:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.