Fixed disabled worlds and requirements not working for custom enchants

This commit is contained in:
Auxilor 2022-04-22 09:10:24 +01:00
parent 67788041bc
commit 3a2d9fc37b
4 changed files with 88 additions and 5 deletions

View File

@ -0,0 +1,25 @@
package com.willfp.ecoenchants.enchantments.custom;
import com.willfp.eco.core.config.interfaces.Config;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.libreforge.conditions.Condition;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ConditionHasEcoEnchantRequirements extends Condition {
/**
* Create new condition.
*/
public ConditionHasEcoEnchantRequirements() {
super("has_ecoenchant_requirements");
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Config config) {
EcoEnchant ecoEnchant = EcoEnchants.getByKey(NamespacedKey.minecraft(config.getString("enchant")));
return ecoEnchant.areRequirementsMet(player);
}
}

View File

@ -0,0 +1,26 @@
package com.willfp.ecoenchants.enchantments.custom;
import com.willfp.eco.core.config.interfaces.Config;
import com.willfp.eco.util.ListUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.libreforge.conditions.Condition;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ConditionInEcoEnchantWorld extends Condition {
/**
* Create new condition.
*/
public ConditionInEcoEnchantWorld() {
super("in_ecoenchant_world");
}
@Override
public boolean isConditionMet(@NotNull final Player player,
@NotNull final Config config) {
EcoEnchant ecoEnchant = EcoEnchants.getByKey(NamespacedKey.minecraft(config.getString("enchant")));
return !ListUtils.containsIgnoreCase(ecoEnchant.getDisabledWorldNames(), player.getWorld().getName());
}
}

View File

@ -32,7 +32,7 @@ public class CustomEcoEnchant extends EcoEnchant {
int i = 1;
for (Config levelConfig : config.getSubsections("levels")) {
levels.put(i, new CustomEcoEnchantLevel(this, levelConfig));
levels.put(i, new CustomEcoEnchantLevel(this, levelConfig, i));
i++;
}
}
@ -91,4 +91,9 @@ public class CustomEcoEnchant extends EcoEnchant {
public boolean isEnabled() {
return true;
}
static {
new ConditionInEcoEnchantWorld();
new ConditionHasEcoEnchantRequirements();
}
}

View File

@ -1,6 +1,8 @@
package com.willfp.ecoenchants.enchantments.custom;
import com.willfp.eco.core.config.BuildableConfig;
import com.willfp.eco.core.config.interfaces.Config;
import com.willfp.eco.core.placeholder.StaticPlaceholder;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.libreforge.Holder;
import com.willfp.libreforge.conditions.Conditions;
@ -36,15 +38,25 @@ public class CustomEcoEnchantLevel implements Holder {
@Getter
private final String valuePlaceholder;
/**
* The level.
*/
private final int level;
/**
* Create custom EcoEnchant level.
*
* @param parent The parent.
* @param config The config.
* @param level The level.
*/
public CustomEcoEnchantLevel(@NotNull final EcoEnchant parent,
@NotNull final Config config) {
@NotNull final Config config,
final int level) {
this.parent = parent;
this.level = level;
config.injectPlaceholders(new StaticPlaceholder("level", () -> String.valueOf(level)));
for (Config cfg : config.getSubsections("effects")) {
effects.add(Effects.compile(cfg, "Custom EcoEnchant ID " + parent.getKey().getKey()));
@ -54,6 +66,20 @@ public class CustomEcoEnchantLevel implements Holder {
conditions.add(Conditions.compile(cfg, "Custom EcoEnchant ID " + parent.getKey().getKey()));
}
conditions.add(Conditions.compile(
new BuildableConfig()
.add("args.enchant", parent.getKey().toString())
.add("id", "in_ecoenchant_world"),
"EcoEnchants Internals (world) - If you see this message, report it as a bug!"
));
conditions.add(Conditions.compile(
new BuildableConfig()
.add("args.enchant", parent.getKey().toString())
.add("id", "has_ecoenchant_requirements"),
"EcoEnchants Internals (requirements) - If you see this message, report it as a bug!"
));
this.valuePlaceholder = config.getString("value-placeholder");
}
@ -71,8 +97,9 @@ public class CustomEcoEnchantLevel implements Holder {
@Override
public String toString() {
return "CustomEcoEnchantLevel{" +
"parent=" + parent +
'}';
return "CustomEcoEnchantLevel{"
+ "parent=" + parent
+ ",level=" + level
+ '}';
}
}