Adds a helper class for calculating random item salvage #18
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

This commit is contained in:
2023-01-13 20:34:34 +01:00
parent 89cebb85c3
commit 8e5d4c7a61
2 changed files with 181 additions and 1 deletions

View File

@ -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 {