Added flags

This commit is contained in:
Auxilor 2021-06-12 10:47:55 +01:00
parent ca8169d46b
commit c00834fd62
2 changed files with 30 additions and 6 deletions

View File

@ -142,6 +142,11 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
@Getter
private boolean enabled;
/**
* Custom option flags for the enchantment.
*/
private final List<String> flags = new ArrayList<>();
/**
* Create a new EcoEnchant.
*
@ -215,6 +220,8 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
targets.addAll(config.getTargets());
targets.forEach(enchantmentTarget -> targetMaterials.addAll(enchantmentTarget.getMaterials()));
enabled = config.getBool("enabled");
flags.clear();
flags.addAll(config.getStrings(EcoEnchants.GENERAL_LOCATION + "flags"));
EnchantmentUtils.registerPlaceholders(this);
postUpdate();
@ -253,12 +260,13 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
}
/**
* Get enchantment cast to {@link Enchantment}.
* If enchantment has specified flag.
*
* @return The enchantment.
* @param flag The flag.
* @return If the enchantment has the flag.
*/
public Enchantment getEnchantment() {
return this;
public boolean hasFlag(@NotNull final String flag) {
return this.flags.contains(flag);
}
/**

View File

@ -144,7 +144,15 @@ public class AnvilMerge {
if (PLUGIN.getConfigYml().getBool("anvil.hard-cap.enabled")) {
if (!player.hasPermission("ecoenchants.anvil.bypasshardcap")) {
if (outEnchants.size() >= PLUGIN.getConfigYml().getInt("anvil.hard-cap.cap")) {
if (outEnchants.keySet()
.stream()
.filter(enchant -> {
if (enchant instanceof EcoEnchant) {
return !((EcoEnchant) enchant).hasFlag("hard-cap-ignore");
}
return true;
}).count() >= PLUGIN.getConfigYml().getInt("anvil.hard-cap.cap")) {
return;
}
}
@ -182,7 +190,15 @@ public class AnvilMerge {
if (PLUGIN.getConfigYml().getBool("anvil.hard-cap.enabled")) {
if (!player.hasPermission("ecoenchants.anvil.bypasshardcap")) {
if (outEnchants.size() >= PLUGIN.getConfigYml().getInt("anvil.hard-cap.cap")) {
if (outEnchants.keySet()
.stream()
.filter(enchant -> {
if (enchant instanceof EcoEnchant) {
return !((EcoEnchant) enchant).hasFlag("hard-cap-ignore");
}
return true;
}).count() >= PLUGIN.getConfigYml().getInt("anvil.hard-cap.cap")) {
doesConflict.set(true);
}
}