mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Update
This commit is contained in:
parent
0a1345622e
commit
27bbca1502
@ -17,6 +17,9 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
|||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a super class of the {@link AutoEnchanter} and {@link AutoDisenchanter} which is
|
* This is a super class of the {@link AutoEnchanter} and {@link AutoDisenchanter} which is
|
||||||
* used to streamline some methods and combine common attributes to reduce redundancy.
|
* used to streamline some methods and combine common attributes to reduce redundancy.
|
||||||
@ -31,6 +34,8 @@ abstract class AbstractEnchantmentMachine extends AContainer {
|
|||||||
|
|
||||||
private final ItemSetting<Boolean> useLevelLimit = new ItemSetting<>(this, "use-enchant-level-limit", false);
|
private final ItemSetting<Boolean> 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 IntRangeSetting levelLimit = new IntRangeSetting(this, "enchant-level-limit", 0, 10, Short.MAX_VALUE);
|
||||||
|
private final ItemSetting<List<String>> ignoredEnchantLores = new ItemSetting<>(this, "ignored-enchant-lores", Arrays.asList("&7- &cCan't be Auto-Enchanted"));
|
||||||
|
private final ItemSetting<List<String>> ignoredDisenchantLores = new ItemSetting<>(this, "ignored-disenchant-lores", Arrays.asList("&7- &cCan't be Auto-Disenchanted"));
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
protected AbstractEnchantmentMachine(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
protected AbstractEnchantmentMachine(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
@ -38,6 +43,8 @@ abstract class AbstractEnchantmentMachine extends AContainer {
|
|||||||
|
|
||||||
addItemSetting(useLevelLimit);
|
addItemSetting(useLevelLimit);
|
||||||
addItemSetting(levelLimit);
|
addItemSetting(levelLimit);
|
||||||
|
addItemSetting(ignoredEnchantLores);
|
||||||
|
addItemSetting(ignoredDisenchantLores);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isEnchantmentLevelAllowed(int enchantmentLevel) {
|
protected boolean isEnchantmentLevelAllowed(int enchantmentLevel) {
|
||||||
@ -55,4 +62,23 @@ abstract class AbstractEnchantmentMachine extends AContainer {
|
|||||||
menu.replaceExistingItem(22, progressBar);
|
menu.replaceExistingItem(22, progressBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean hasIgnoredLore(ItemStack itemStack, AbstractEnchantmentMachine enchantmentMachine) {
|
||||||
|
List<String> ignoredLores = null;
|
||||||
|
if (enchantmentMachine instanceof AutoEnchanter) {
|
||||||
|
ignoredLores = ignoredEnchantLores.getValue();
|
||||||
|
} else if (enchantmentMachine instanceof AutoDisenchanter) {
|
||||||
|
ignoredLores = ignoredDisenchantLores.getValue();
|
||||||
|
}
|
||||||
|
if (itemStack.hasItemMeta()) {
|
||||||
|
List<String> lores = itemStack.getItemMeta().getLore();
|
||||||
|
if (lores != null && ignoredLores != null) {
|
||||||
|
for (String lore : ignoredLores) {
|
||||||
|
if (lores.contains(ChatColors.color(lore))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +142,8 @@ public class AutoDisenchanter extends AbstractEnchantmentMachine {
|
|||||||
private boolean isDisenchantable(@Nullable ItemStack item) {
|
private boolean isDisenchantable(@Nullable ItemStack item) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return false;
|
return false;
|
||||||
|
} else if (hasIgnoredLore(item, this)) {
|
||||||
|
return false;
|
||||||
} else if (item.getType() != Material.BOOK) {
|
} else if (item.getType() != Material.BOOK) {
|
||||||
// ^ This stops endless checks of getByItem for books
|
// ^ This stops endless checks of getByItem for books
|
||||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||||
|
@ -120,8 +120,12 @@ public class AutoEnchanter extends AbstractEnchantmentMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEnchantable(@Nullable ItemStack item) {
|
private boolean isEnchantable(@Nullable ItemStack item) {
|
||||||
// stops endless checks of getByItem for enchanted book stacks.
|
if (item == null) {
|
||||||
if (item != null && item.getType() != Material.ENCHANTED_BOOK) {
|
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);
|
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||||
return sfItem == null || sfItem.isEnchantable();
|
return sfItem == null || sfItem.isEnchantable();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user