diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AbstractEnchantmentMachine.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AbstractEnchantmentMachine.java index 36ef40179..87f1d3785 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AbstractEnchantmentMachine.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AbstractEnchantmentMachine.java @@ -34,8 +34,7 @@ abstract class AbstractEnchantmentMachine extends AContainer { private final ItemSetting useLevelLimit = new ItemSetting<>(this, "use-enchant-level-limit", false); private final IntRangeSetting levelLimit = new IntRangeSetting(this, "enchant-level-limit", 0, 10, Short.MAX_VALUE); - private final ItemSetting> ignoredEnchantLores = new ItemSetting<>(this, "ignored-enchant-lores", Arrays.asList("&7- &cCan't be Auto-Enchanted")); - private final ItemSetting> ignoredDisenchantLores = new ItemSetting<>(this, "ignored-disenchant-lores", Arrays.asList("&7- &cCan't be Auto-Disenchanted")); + private final ItemSetting> ignoredLores = new ItemSetting<>(this, "ignored-lores", Arrays.asList("&7- &cCan't be used in " + getMachineIdentifier())); @ParametersAreNonnullByDefault protected AbstractEnchantmentMachine(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { @@ -43,8 +42,7 @@ abstract class AbstractEnchantmentMachine extends AContainer { addItemSetting(useLevelLimit); addItemSetting(levelLimit); - addItemSetting(ignoredEnchantLores); - addItemSetting(ignoredDisenchantLores); + addItemSetting(ignoredLores); } protected boolean isEnchantmentLevelAllowed(int enchantmentLevel) { @@ -62,20 +60,13 @@ abstract class AbstractEnchantmentMachine extends AContainer { menu.replaceExistingItem(22, progressBar); } - protected boolean hasIgnoredLore(ItemStack itemStack, AbstractEnchantmentMachine enchantmentMachine) { - List ignoredLores = null; - if (enchantmentMachine instanceof AutoEnchanter) { - ignoredLores = ignoredEnchantLores.getValue(); - } else if (enchantmentMachine instanceof AutoDisenchanter) { - ignoredLores = ignoredDisenchantLores.getValue(); - } + protected boolean hasIgnoredLore(@Nonnull ItemStack itemStack) { + List ignoredLore = ignoredLores.getValue(); if (itemStack.hasItemMeta()) { - List lores = itemStack.getItemMeta().getLore(); - if (lores != null && ignoredLores != null) { - for (String lore : ignoredLores) { - if (lores.contains(ChatColors.color(lore))) { - return true; - } + List itemLore = itemStack.getItemMeta().getLore(); + for (String lore : ignoredLore) { + if (itemLore.contains(ChatColors.color(lore))) { + return true; } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java index dd4b447b5..09a5ddb39 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java @@ -142,14 +142,12 @@ public class AutoDisenchanter extends AbstractEnchantmentMachine { private boolean isDisenchantable(@Nullable ItemStack item) { if (item == null) { return false; - } else if (hasIgnoredLore(item, this)) { - return false; } else if (item.getType() != Material.BOOK) { // ^ This stops endless checks of getByItem for books SlimefunItem sfItem = SlimefunItem.getByItem(item); return sfItem == null || sfItem.isDisenchantable(); } else { - return true; + return !hasIgnoredLore(item); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java index 0034335e2..69e39a235 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java @@ -35,7 +35,6 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; * */ public class AutoEnchanter extends AbstractEnchantmentMachine { - @ParametersAreNonnullByDefault public AutoEnchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); @@ -122,14 +121,12 @@ public class AutoEnchanter extends AbstractEnchantmentMachine { private boolean isEnchantable(@Nullable ItemStack item) { if (item == null) { return false; - } else if (hasIgnoredLore(item, this)) { - return false; } else if (item.getType() != Material.ENCHANTED_BOOK) { // stops endless checks of getByItem for enchanted book stacks. SlimefunItem sfItem = SlimefunItem.getByItem(item); return sfItem == null || sfItem.isEnchantable(); } else { - return false; + return !hasIgnoredLore(item); } }