forked from Upstream/mmocore
Transferred the categories formulaEvaluation from SkillSlot to RegisteredSkill.
This commit is contained in:
parent
0f4699fbea
commit
7f07f9e349
@ -1,26 +1,22 @@
|
||||
package net.Indyuce.mmocore.api.player.profess.skillbinding;
|
||||
|
||||
import bsh.EvalError;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicHook;
|
||||
import net.Indyuce.mmocore.skill.ClassSkill;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
import java.util.List;
|
||||
|
||||
public class SkillSlot {
|
||||
private final int slot, modelData;
|
||||
private final String expression;
|
||||
private final String formula;
|
||||
private final String name;
|
||||
private final List<String> lore;
|
||||
private Material item;
|
||||
|
||||
public SkillSlot(int slot, int modelData, String expression, String name, List<String> lore, Material item) {
|
||||
public SkillSlot(int slot, int modelData, String formula, String name, List<String> lore, Material item) {
|
||||
this.slot = slot;
|
||||
this.modelData = modelData;
|
||||
this.expression = expression;
|
||||
this.formula = formula;
|
||||
this.name = name;
|
||||
this.lore = lore;
|
||||
this.item = item;
|
||||
@ -28,7 +24,7 @@ public class SkillSlot {
|
||||
|
||||
public SkillSlot(ConfigurationSection section) {
|
||||
this.slot = Integer.parseInt(section.getName());
|
||||
this.expression = section.contains("expression") ? section.getString("expression") : "true";
|
||||
this.formula = section.contains("expression") ? section.getString("expression") : "true";
|
||||
this.name = section.getString("name");
|
||||
this.lore = section.getStringList("lore");
|
||||
if (section.contains("item"))
|
||||
@ -61,16 +57,6 @@ public class SkillSlot {
|
||||
}
|
||||
|
||||
public boolean canPlaceSkill(ClassSkill classSkill) {
|
||||
|
||||
String parsedExpression = expression;
|
||||
for (String category : classSkill.getSkill().getCategories())
|
||||
parsedExpression = parsedExpression.replace("<" + category + ">", "true");
|
||||
parsedExpression = parsedExpression.replaceAll("<.*>", "false");
|
||||
try {
|
||||
boolean res = (boolean) MythicLib.plugin.getInterpreter().eval(parsedExpression);
|
||||
return res;
|
||||
} catch (EvalError e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return classSkill.getSkill().matchesFormula(formula);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.Indyuce.mmocore.skill;
|
||||
|
||||
import bsh.EvalError;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.skill.handler.SkillHandler;
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||
@ -35,6 +37,7 @@ public class RegisteredSkill implements Unlockable {
|
||||
categories = config.getStringList("categories");
|
||||
// Trigger type
|
||||
triggerType = getHandler().isTriggerable() ? (config.contains("passive-type") ? TriggerType.valueOf(UtilityMethods.enumName(config.getString("passive-type"))) : TriggerType.CAST) : TriggerType.API;
|
||||
categories.add(getHandler().getId());
|
||||
if (triggerType.isPassive())
|
||||
categories.add("passive");
|
||||
else
|
||||
@ -132,6 +135,19 @@ public class RegisteredSkill implements Unlockable {
|
||||
return defaultModifiers.get(modifier).calculate(level);
|
||||
}
|
||||
|
||||
public boolean matchesFormula(String formula) {
|
||||
String parsedExpression = formula;
|
||||
for (String category : categories)
|
||||
parsedExpression = parsedExpression.replace("<" + category + ">", "true");
|
||||
parsedExpression = parsedExpression.replaceAll("<.*>", "false");
|
||||
try {
|
||||
boolean res = (boolean) MythicLib.plugin.getInterpreter().eval(parsedExpression);
|
||||
return res;
|
||||
} catch (EvalError e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
Loading…
Reference in New Issue
Block a user