Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to check if inventory is full

Comments in 'Plugin Development' started by RekkuzaRage, Dec 7, 2015.

  1. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    251
    Minecraft User:
    RekkuzaRage
    Is there is good methods of checking if a inventory is full? Thanks.
  2. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Let $player as the player object.
    PHP:
    public function isInventoryFull($player){
        for(
    $i 0$i $player->getInventory()->getSize(); $i++){
            if(
    $player->getInventory()->getItem($i)->getId() === 0){
                return 
    true;
            }
        }
        return 
    false;
    }
    Last edited: Dec 7, 2015
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Or simply
    PHP:
    $inventory->firstEmpty() === -1

Share This Page

Advertisement