Removes disableMaterialLimitation
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

Removes the disableMaterialLimitation option
Replaces EnchantmentTarget.BREAKABLE.includes(item) with getMaxDurability(item) > 0 as it seems more generic
This commit is contained in:
2023-01-16 19:45:41 +01:00
parent e5cb3b4a30
commit 347b69b2a8
9 changed files with 26 additions and 64 deletions

View File

@ -1,7 +1,6 @@
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;
@ -20,13 +19,11 @@ public final class ItemHelper {
/**
* Gets whether the given item is repairable
*
* @param item <p>The item to check</p>
* @param disableMaterialLimitation <p>Whether to disable the EnchantmentTarget.BREAKABLE limitation</p>
* @param item <p>The item to check</p>
* @return <p>True if the item is repairable</p>
*/
public static boolean isRepairable(ItemStack item, boolean disableMaterialLimitation) {
return item.getItemMeta() instanceof Damageable && (disableMaterialLimitation ||
EnchantmentTarget.BREAKABLE.includes(item));
public static boolean isRepairable(ItemStack item) {
return item.getItemMeta() instanceof Damageable && getMaxDurability(item) > 0;
}
/**
@ -79,7 +76,7 @@ public final class ItemHelper {
List<Material> reforgeAbleMaterials = new ArrayList<>();
for (Material material : Material.values()) {
ItemStack item = new ItemStack(material);
if (item.getItemMeta() instanceof Damageable && EnchantmentTarget.BREAKABLE.includes(item)) {
if (isRepairable(item)) {
reforgeAbleMaterials.add(material);
}
}

View File

@ -23,16 +23,14 @@ public final class SalvageHelper {
*
* <p>Note: Only items craft-able in a crafting table are salvageable. Netherite gear is therefore not salvageable.</p>
*
* @param server <p>The server to get recipes from</p>
* @param salvagedItem <p>The item stack to salvage</p>
* @param ignoredSalvage <p>Any material which should not be returned as part of the salvage.</p>
* @param limitationDisabled <p>Whether the repairable item limitation is disabled</p>
* @param server <p>The server to get recipes from</p>
* @param salvagedItem <p>The item stack to salvage</p>
* @param ignoredSalvage <p>Any material which should not be returned as part of the salvage.</p>
* @return <p>The items to return to the user, or null if not salvageable</p>
*/
public static List<ItemStack> getSalvage(Server server, ItemStack salvagedItem, List<Material> ignoredSalvage,
boolean limitationDisabled) {
public static List<ItemStack> getSalvage(Server server, ItemStack salvagedItem, List<Material> ignoredSalvage) {
if (salvagedItem == null || salvagedItem.getAmount() < 1 ||
!ItemHelper.isRepairable(salvagedItem, limitationDisabled)) {
!ItemHelper.isRepairable(salvagedItem)) {
return null;
}