Removes disableMaterialLimitation
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
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:
@ -49,15 +49,7 @@ public enum GlobalSetting {
|
||||
* The cost for repairing a damaged anvil
|
||||
*/
|
||||
ANVIL_DAMAGED_COST("global.damagedAnvilReforgingCost", SettingValueType.POSITIVE_DOUBLE, 20.0,
|
||||
"damagedAnvilReforgingCost"),
|
||||
|
||||
/**
|
||||
* Whether to disable the normal limitation for which items are reforgeAble
|
||||
*
|
||||
* <p>If true, all items instanceof Damageable can be reforged</p>
|
||||
*/
|
||||
DISABLE_MATERIAL_LIMITATION("global.disableMaterialLimitation", SettingValueType.BOOLEAN, false,
|
||||
"disableMaterialLimitation");
|
||||
"damagedAnvilReforgingCost");
|
||||
|
||||
private final String path;
|
||||
private final String parent;
|
||||
|
@ -295,15 +295,6 @@ public class GlobalSettings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to disable the "EnchantmentTarget.BREAKABLE" limitation
|
||||
*
|
||||
* @return <p>True if the material limitation is disabled</p>
|
||||
*/
|
||||
public boolean disableMaterialLimitation() {
|
||||
return asBoolean(GlobalSetting.DISABLE_MATERIAL_LIMITATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given value as a boolean
|
||||
*
|
||||
|
@ -460,8 +460,7 @@ public class NPCSettings {
|
||||
}
|
||||
|
||||
Material material = InputParsingHelper.matchMaterial(item);
|
||||
boolean limitationDisabled = BlacksmithPlugin.getInstance().getSettings().disableMaterialLimitation();
|
||||
if (material != null && ItemHelper.isRepairable(new ItemStack(material, 1), limitationDisabled)) {
|
||||
if (material != null && ItemHelper.isRepairable(new ItemStack(material, 1))) {
|
||||
if (!blacklist) {
|
||||
reforgeAbleItems.add(material);
|
||||
} else {
|
||||
|
@ -179,8 +179,7 @@ public class BlacksmithTrait extends Trait {
|
||||
List<Material> reforgeAbleItems = config.getReforgeAbleItems();
|
||||
|
||||
boolean notHoldingAnvil = !this.config.getRepairAnvils() || !ItemHelper.isAnvil(hand.getType(), false);
|
||||
boolean limitationDisabled = BlacksmithPlugin.getInstance().getSettings().disableMaterialLimitation();
|
||||
boolean notHoldingRepairable = !ItemHelper.isRepairable(hand, limitationDisabled) ||
|
||||
boolean notHoldingRepairable = !ItemHelper.isRepairable(hand) ||
|
||||
(!reforgeAbleItems.isEmpty() && !reforgeAbleItems.contains(hand.getType()));
|
||||
|
||||
if (notHoldingAnvil && notHoldingRepairable) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user