Adds a new check for items with full durability (#4)
This commit is contained in:
43
src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java
Normal file
43
src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java
Normal file
@ -0,0 +1,43 @@
|
||||
package net.knarcraft.blacksmith.util;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
|
||||
public final class ItemHelper {
|
||||
|
||||
private ItemHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current durability of the given item
|
||||
*
|
||||
* @param itemStack <p>The item to get the durability of</p>
|
||||
* @return <p>The durability of the item</p>
|
||||
*/
|
||||
public static short getDurability(ItemStack itemStack) {
|
||||
Damageable damageable = (Damageable) itemStack.getItemMeta();
|
||||
int maxDurability = itemStack.getType().getMaxDurability();
|
||||
if (damageable != null) {
|
||||
return (short) (maxDurability - damageable.getDamage());
|
||||
} else {
|
||||
return (short) maxDurability;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the damage done to the given item
|
||||
*
|
||||
* @param itemStack <p>The damage done to the item</p>
|
||||
* @return <p>The damage done to the item</p>
|
||||
*/
|
||||
public static short getDamage(ItemStack itemStack) {
|
||||
Damageable damageable = (Damageable) itemStack.getItemMeta();
|
||||
if (damageable != null) {
|
||||
return (short) damageable.getDamage();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user