Get count of certain item in inventory and taking

Discussion in 'Spigot Plugin Development' started by Bars, May 13, 2015.

  1. Don't work.
    type = material
    am = amount
    me = meta-data
    Code (Java):
                if (!p.getInventory().contains(new ItemStack(type, am, me))) {
                    // If player has no fuel
                    p.sendMessage(msg("not-enough-fuel"));
                    e.setCancelled(true);
                    p.setFlying(false);
                    return;
                } else
                    p.getInventory().removeItem(new ItemStack(type, am, me));
    I also tried this, but it not work too:
    Code (Java):
    if (!p.getInventory().containsAtLeast(new ItemStack(type, am, me), am))
     
  2. That is because you are checking if the inventory contains the exact itemstack. You need to use .isSimilar instead of .contains.

    Explanation: isSimilar checks if it is that ItemStack, disregarding the quantity.