Adds a helper class for calculating random item salvage #18
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
This commit is contained in:
@ -8,12 +8,25 @@ 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 <p>The item to get the durability of</p>
|
||||
* @return <p>The max durability of the item</p>
|
||||
*/
|
||||
public static short getMaxDurability(ItemStack itemStack) {
|
||||
return itemStack.getType().getMaxDurability();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current durability of the given item
|
||||
*
|
||||
@ -22,7 +35,7 @@ public final class ItemHelper {
|
||||
*/
|
||||
public static short getDurability(ItemStack itemStack) {
|
||||
Damageable damageable = (Damageable) itemStack.getItemMeta();
|
||||
int maxDurability = itemStack.getType().getMaxDurability();
|
||||
int maxDurability = getMaxDurability(itemStack);
|
||||
if (damageable != null) {
|
||||
return (short) (maxDurability - damageable.getDamage());
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user