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;
|
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 net.Indyuce.mmocore.skill.ClassSkill;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import javax.script.ScriptException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SkillSlot {
|
public class SkillSlot {
|
||||||
private final int slot, modelData;
|
private final int slot, modelData;
|
||||||
private final String expression;
|
private final String formula;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final List<String> lore;
|
private final List<String> lore;
|
||||||
private Material item;
|
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.slot = slot;
|
||||||
this.modelData = modelData;
|
this.modelData = modelData;
|
||||||
this.expression = expression;
|
this.formula = formula;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.lore = lore;
|
this.lore = lore;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
@ -28,7 +24,7 @@ public class SkillSlot {
|
|||||||
|
|
||||||
public SkillSlot(ConfigurationSection section) {
|
public SkillSlot(ConfigurationSection section) {
|
||||||
this.slot = Integer.parseInt(section.getName());
|
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.name = section.getString("name");
|
||||||
this.lore = section.getStringList("lore");
|
this.lore = section.getStringList("lore");
|
||||||
if (section.contains("item"))
|
if (section.contains("item"))
|
||||||
@ -61,16 +57,6 @@ public class SkillSlot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canPlaceSkill(ClassSkill classSkill) {
|
public boolean canPlaceSkill(ClassSkill classSkill) {
|
||||||
|
return classSkill.getSkill().matchesFormula(formula);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.Indyuce.mmocore.skill;
|
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.UtilityMethods;
|
||||||
import io.lumine.mythic.lib.skill.handler.SkillHandler;
|
import io.lumine.mythic.lib.skill.handler.SkillHandler;
|
||||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||||
@ -35,6 +37,7 @@ public class RegisteredSkill implements Unlockable {
|
|||||||
categories = config.getStringList("categories");
|
categories = config.getStringList("categories");
|
||||||
// Trigger type
|
// Trigger type
|
||||||
triggerType = getHandler().isTriggerable() ? (config.contains("passive-type") ? TriggerType.valueOf(UtilityMethods.enumName(config.getString("passive-type"))) : TriggerType.CAST) : TriggerType.API;
|
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())
|
if (triggerType.isPassive())
|
||||||
categories.add("passive");
|
categories.add("passive");
|
||||||
else
|
else
|
||||||
@ -132,6 +135,19 @@ public class RegisteredSkill implements Unlockable {
|
|||||||
return defaultModifiers.get(modifier).calculate(level);
|
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
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user