mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-01-05 22:07:34 +01:00
Fixed disabled worlds and requirements not working for custom enchants
This commit is contained in:
parent
67788041bc
commit
3a2d9fc37b
@ -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);
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user