package net.knarcraft.blacksmith.util; import org.bukkit.Material; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; import java.util.ArrayList; import java.util.List; /** * A helper class for getting information about items */ public final class ItemHelper { private ItemHelper() { } /** * Gets the max durability of an item * * @param itemStack
The item to get the durability of
* @returnThe max durability of the item
*/ public static short getMaxDurability(ItemStack itemStack) { return itemStack.getType().getMaxDurability(); } /** * Gets the current durability of the given item * * @param itemStackThe item to get the durability of
* @returnThe durability of the item
*/ public static short getDurability(ItemStack itemStack) { Damageable damageable = (Damageable) itemStack.getItemMeta(); int maxDurability = getMaxDurability(itemStack); if (damageable != null) { return (short) (maxDurability - damageable.getDamage()); } else { return (short) maxDurability; } } /** * Gets the damage done to the given item * * @param itemStackThe damage done to the item
* @returnThe damage done to the item
*/ public static short getDamage(ItemStack itemStack) { Damageable damageable = (Damageable) itemStack.getItemMeta(); if (damageable != null) { return (short) damageable.getDamage(); } else { return 0; } } /** * Gets a complete list of all reforge-able materials * * @returnA complete list of reforge-able materials
*/ public static ListThe material to check
* @param requireDamagedWhether only a damaged anvil should count
* @returnTrue if the given material is an anvil
*/ public static boolean isAnvil(Material material, boolean requireDamaged) { boolean isDamagedAnvil = material == Material.CHIPPED_ANVIL || material == Material.DAMAGED_ANVIL; boolean isAnvil = isDamagedAnvil || material == Material.ANVIL; return (requireDamaged && isDamagedAnvil) || (!requireDamaged && isAnvil); } }