1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Merge pull request #3749 from J3fftw1/feature/maxEnchants

added a way to set max enchants to go on an item
This commit is contained in:
Sefiraat 2023-06-09 22:41:38 +01:00 committed by GitHub
commit 39886fc007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -28,6 +29,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
* *
* @author TheBusyBiscuit * @author TheBusyBiscuit
* @author Rothes * @author Rothes
* @author J3fftw1
* *
* @see AutoEnchanter * @see AutoEnchanter
* @see AutoDisenchanter * @see AutoDisenchanter
@ -37,6 +39,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<Integer> maxEnchants = new IntRangeSetting(this, "max-enchants", 0, 10, Short.MAX_VALUE);
private final ItemSetting<Boolean> useMaxEnchants= new ItemSetting<>(this, "use-max-encahnts", false);
private final ItemSetting<Boolean> useIgnoredLores = new ItemSetting<>(this, "use-ignored-lores", false); private final ItemSetting<Boolean> useIgnoredLores = new ItemSetting<>(this, "use-ignored-lores", false);
private final ItemSetting<List<String>> ignoredLores = new ItemSetting<>(this, "ignored-lores", Collections.singletonList("&7- &cCan't be used in " + this.getItemName())); private final ItemSetting<List<String>> ignoredLores = new ItemSetting<>(this, "ignored-lores", Collections.singletonList("&7- &cCan't be used in " + this.getItemName()));
@ -48,6 +52,8 @@ abstract class AbstractEnchantmentMachine extends AContainer {
addItemSetting(levelLimit); addItemSetting(levelLimit);
addItemSetting(useIgnoredLores); addItemSetting(useIgnoredLores);
addItemSetting(ignoredLores); addItemSetting(ignoredLores);
addItemSetting(maxEnchants);
addItemSetting(useMaxEnchants);
} }
protected boolean isEnchantmentLevelAllowed(int enchantmentLevel) { protected boolean isEnchantmentLevelAllowed(int enchantmentLevel) {
@ -84,4 +90,8 @@ abstract class AbstractEnchantmentMachine extends AContainer {
return false; return false;
} }
protected boolean isEnchantmentAmountAllowed(@Nonnull ItemStack item ) {
return !useMaxEnchants.getValue() || item.getEnchantments().size() >= maxEnchants.getValue();
}
} }

View File

@ -94,6 +94,10 @@ public class AutoDisenchanter extends AbstractEnchantmentMachine {
} }
} }
if (isEnchantmentAmountAllowed(item)) {
return null;
}
// Check if we found any valid enchantments // Check if we found any valid enchantments
if (!enchantments.isEmpty()) { if (!enchantments.isEmpty()) {
ItemStack disenchantedItem = item.clone(); ItemStack disenchantedItem = item.clone();

View File

@ -116,6 +116,14 @@ public class AutoEnchanter extends AbstractEnchantmentMachine {
enchantments.entrySet().removeIf(e -> target.getEnchantmentLevel(e.getKey()) >= e.getValue()); enchantments.entrySet().removeIf(e -> target.getEnchantmentLevel(e.getKey()) >= e.getValue());
} }
/*
* When maxEnchants is set to -1 it will be ignored. When it's set to 0 it will not allow any enchants to go
* on an item. When maxEnchants is set to any other value it will allow that many enchants to go on the item.
*/
if (isEnchantmentAmountAllowed(target)) {
return null;
}
// Check if we found any valid enchantments // Check if we found any valid enchantments
if (!enchantments.isEmpty()) { if (!enchantments.isEmpty()) {
ItemStack enchantedItem = target.clone(); ItemStack enchantedItem = target.clone();