Checking if players inventory is full?

Discussion in 'Plugin Development' started by kensclark15, Jan 11, 2012.

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

    kensclark15

    I found a bug in my FoundDiamond plugin. If a players inventory is full it will not give them anything. Is there a way that I can make it so if there inventory is full but they have 60 of one material and if they were rewarded 10, then 4 would go into that stack and the 6 others would drop at their feet?
     
  2. Offline

    mb01

  3. Offline

    LaLa

    firstEmpy() returns -1 if the inventory is full.
     
  4. Offline

    skore87

    Does this include stacks that aren't max stack quantity or just that all slots are filled with something?
     
  5. Offline

    kensclark15

    Actually I found something that works.
    Code:
    HashMap<Integer, ItemStack> leftOver = new HashMap<Integer, ItemStack>();
                        leftOver.putAll((playerP.getInventory().addItem(new ItemStack(item.getMaterial(), amount))));
                        if (!leftOver.isEmpty()) {
                            Location loc = playerP.getLocation();
                            playerP.getWorld().dropItem(loc, new ItemStack(Material.getMaterial(leftOver.get(0).getTypeId()), leftOver.get(0).getAmount()));
                        }
    addItem() will return the leftover items.

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

    LaLa

    Slots left, but what @kensclark15 posted is probably what you are more looking for.
     
Thread Status:
Not open for further replies.

Share This Page