Check if inventory is full?

Discussion in 'Plugin Development' started by Mike724, Aug 30, 2011.

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

    Mike724

    I'm making a plugin and need a way to check if the player has enough space in their inventory for an item, how can I do this?

    Say the player has a full inventory and only 2 dirt, and I want to check if they have space for 20 more dirt, then it should return true because it can fit.

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  2. Offline

    The_Tree_Maker

    First, you'll need to have a Player to Check.
    Second, you'll need to get the Players Inventory and get a ItemStack Array.
    Third, you'll need to check each item for dirt. If the item is dirt, check how much dirt there is. If there is room for 20 more. Return true. Else skip to the next item in the ItemStack Array and say False.

    Also, don't forget to look what is in the players hand.

    I am currently on a PC I don't develop with so I can't give you some sample code. Hopefully Pseudo code will help.
     
  3. Offline

    Mike724

    Thank you, I'll try to figure it out now.
     
Thread Status:
Not open for further replies.

Share This Page