Check full inv

Discussion in 'Plugin Development' started by Hacksore, Aug 25, 2011.

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

    Hacksore

    Like the title says how would I check if a players inventory is full.

    EDIT:

    I think i got it by checking if inv.firstEmpty() < 0
     
  2. Offline

    CptSausage

    I would do something like this (Not checked if it works):

    Code:
    public boolean isPlayerInventoryFull(Player player) {
        ItemStack[] contents = player.getInventory().getContents();
            for (ItemStack itemStack : contents) {
                if (itemStack == null) {
                    return false;
                }
            }
            return true;
    }
     
  3. Offline

    Hacksore

    Code:java
    1.  
    2. public boolean isPlayerInventoryFull(PlayerInventory inv) {
    3. (inv.firstEmpty() < 0) ? return true : return false;
    4. }
    5.  


    I'm going to try that, also I seem to have another problem when I give the diamond to a player it is nommable(I can eat it :D). I thought maybe it was because I never sent ply.updateInventory() but it looks like that is depreciated.

    What I am trying to do is this
    Code:java
    1.  
    2. public void onSpoutCraftEnable(SpoutCraftEnableEvent event) {
    3. Player ply = event.getPlayer();
    4. ItemStack stack = new ItemStack(264);
    5. PlayerInventory inv = ply.getInventory();
    6.  
    7. if(hasSpout(ply.getName())){
    8. /* do nothing*/
    9. }
    10. else if(inv.firstEmpty() < 0){
    11. ply.sendMessage(ChatColor.RED + "Your inventory is full please make some space and rejoin!");
    12. }
    13. else{
    14. inv.addItem(stack);
    15. countPlayer(ply.getName());
    16. ply.sendMessage(ChatColor.AQUA + "Here is that Diamond!");
    17. }
    18. }
    19.  

    So how do I give the diamond properly?

    EDIT:
    Ahh I got it, args1 of the ItemStack needed to be quantity.
     
Thread Status:
Not open for further replies.

Share This Page