1.14.4 i need help, i had a trouble when i check inventory full

Discussion in 'Spigot Plugin Development' started by JunoMC, Feb 17, 2020.

  1. this is my code:

    Code (Java):
    public boolean isInventoryFull(@NotNull Player player, ItemStack itemStack, int amount) {
            for (ItemStack itemStacks : player.getOpenInventory().getBottomInventory()) {
                if (itemStacks == null) {
                    return false;
                } else if (itemStacks.isSimilar(itemStack)) {
                    int currentSize = itemStacks.getMaxStackSize() - itemStacks.getAmount();
                    if (amount <= currentSize) {
                        return false;
                    }
                }
            }
            return true;
        }
    but i dont know why it always return false!
     
  2. Add some debug, ie System.out.println(1); and System.out.println("Checking item: " + itemStacks); in different areas, it'll do wonders.
     
  3. SteelPhoenix

    Moderator

    Just use Inventory#firstEmpty() == -1
     
  4. if u check slot null, you can use that method! but i must check slot have item and enough size for same items!
     
  5. thanks for your advice!
     
  6. SteelPhoenix

    Moderator

    What for? Adding items to the inventory? You can also use Inventory#addItems(ItemStack[]) and it will return a map with all items that did not fit
     
    • Agree Agree x 1
  7. so if amount of item over slot null? then rest of that item will disappear?
     
  8. drives_a_ford

    Moderator

    What?
    Just read the javadocs of Inventory#addItem:
     
    • Agree Agree x 1
  9. Also doesnt the inventory have the .getItem method? Just make a loop checking if its null
    Code (Text):
    for(....){
    if(p.getInventory().getItem(i)==null){
    return false....
    }
    }
    basically check every slot if its null