return false; } else if (!data.equals(other.data)) { return false;
/** * Remove all matching items from the inventory. * * @param type the item to remove, or null to remove everything * @param data the data value to match on, or null to match all data values * @return the number of items (not stacks) removed */ public int clear(Material type, MaterialData data) { if (type == Material.AIR) { return 0; } int numCleared = 0; for (int i = 0; i < getSize(); ++i) { ItemStack stack = getItem(i); if (stack != null && (type == null || stack.getType() == type) && (data == null || stack .getData().equals(data))) { setItem(i, InventoryUtil.createEmptyStack()); if (!InventoryUtil.isEmpty(stack)) { // never report AIR as removed - else will report all empty slots cleared numCleared += stack.getAmount(); // report # items, not # stacks removed } } } return numCleared; }
/** * Checks if the itemStacks are equal, ignoring their amount * * @param one first itemStack * @param two second itemStack * @return Are they equal? */ public static boolean equals(ItemStack one, ItemStack two) { if (one == null || two == null) { return one == two; } if (one.isSimilar(two)) { return true; } // Special check for books as their pages might change when serialising (See SPIGOT-3206) return one.getType() == two.getType() && one.getDurability() == two.getDurability() && one.getData().equals(two.getData()) && one.hasItemMeta() && two.hasItemMeta() && one.getItemMeta() instanceof BookMeta && two.getItemMeta() instanceof BookMeta && one.getItemMeta().serialize().equals(two.getItemMeta().serialize()); }