diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 282dce35..2ff55bf5 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -183,16 +183,15 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public void setupSkillTree() { + // Node states setup for (SkillTree skillTree : getProfess().getSkillTrees()) skillTree.setupNodeStates(this); // Stat triggers setup - for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll()) for (SkillTreeNode node : skillTree.getNodes()) node.getExperienceTable().claimStatTriggers(this, node); - } public int getPointSpent(SkillTree skillTree) { @@ -1165,7 +1164,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return mmoData.getCooldownMap(); } - public void setClass(PlayerClass profess) { + public void setClass(@Nullable PlayerClass profess) { this.profess = profess; // Clear old skills @@ -1177,11 +1176,12 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc if (isOnline()) getStats().updateStats(); - // Loads the classUnlockedSkills - profess.getSkills() - .stream() - .filter(ClassSkill::isUnlockedByDefault) - .forEach(skill ->unlock(skill.getSkill())); + if (profess != null) + // Loads the classUnlockedSkills + profess.getSkills() + .stream() + .filter(ClassSkill::isUnlockedByDefault) + .forEach(skill -> unlock(skill.getSkill())); } public boolean hasSkillBound(int slot) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java index 0fb0070b..5632bde9 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java @@ -104,11 +104,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { | SecurityException exception) { throw new IllegalArgumentException("Could not apply playerhead texture: " + exception.getMessage()); } - Validate.isTrue(config.isConfigurationSection("skill-slots"), "You must define the skills-slots for class " + id); - for (String key : config.getConfigurationSection("skill-slots").getKeys(false)) { - SkillSlot skillSlot = new SkillSlot(config.getConfigurationSection("skill-slots." + key)); - skillSlots.put(skillSlot.getSlot(), skillSlot); - } + for (String string : config.getStringList("display.lore")) description.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string)); for (String string : config.getStringList("display.attribute-lore")) @@ -119,10 +115,13 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { displayOrder = config.getInt("display.order"); actionBarFormat = config.contains("action-bar", true) ? config.getString("action-bar") : null; + // Exp curve expCurve = config.contains("exp-curve") ? MMOCore.plugin.experience.getCurveOrThrow( config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-")) : ExpCurve.DEFAULT; + + // Main exp table ExperienceTable expTable = null; if (config.contains("exp-table")) try { @@ -131,6 +130,8 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp table from class '" + id + "': " + exception.getMessage()); } this.expTable = expTable; + + // Skill trees if (config.contains("skill-trees")) for (String str : config.getStringList("skill-trees")) try { @@ -139,6 +140,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { MMOCore.log(Level.WARNING, "Could not find skill tree with ID: " + str); } + // Class-specific scripts if (config.contains("scripts")) for (String key : config.getConfigurationSection("scripts").getKeys(false)) try { @@ -161,6 +163,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { } this.comboMap = comboMap; + // Triggers (DEPRECATED) if (config.contains("triggers")) for (String key : config.getConfigurationSection("triggers").getKeys(false)) try { @@ -170,6 +173,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { MMOCore.log(Level.WARNING, "Could not load trigger '" + key + "' from class '" + id + "':" + exception.getMessage()); } + // Class STATS, not attributes (historic reasons) if (config.contains("attributes")) for (String key : config.getConfigurationSection("attributes").getKeys(false)) try { @@ -180,16 +184,30 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { + id + "': " + exception.getMessage()); } + // Skill slots + if (config.contains("skill-slots")) + for (String key : config.getConfigurationSection("skill-slots").getKeys(false)) + try { + SkillSlot skillSlot = new SkillSlot(config.getConfigurationSection("skill-slots." + key)); + skillSlots.put(skillSlot.getSlot(), skillSlot); + } catch (RuntimeException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill slot '" + key + "' from class '" + + id + "': " + exception.getMessage()); + } + + // Class skills for (RegisteredSkill registered : MMOCore.plugin.skillManager.getAll()) { - String key = registered.getHandler().getId(); + final String key = registered.getHandler().getId(); if (config.contains("skills." + key)) skills.put(key, new ClassSkill(registered, config.getConfigurationSection("skills." + key))); else skills.put(key, new ClassSkill(registered, 1, 1,false)); } + // Casting particle castParticle = config.contains("cast-particle") ? new CastingParticle(config.getConfigurationSection("cast-particle")) : null; + // Other class options if (config.contains("options")) for (String key : config.getConfigurationSection("options").getKeys(false)) try { @@ -200,6 +218,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { "Could not load option '" + key + "' from class '" + key + "': " + exception.getMessage()); } + // Experience sources if (config.contains("main-exp-sources")) { for (String key : config.getStringList("main-exp-sources")) try { @@ -346,8 +365,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { @Override public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) { - hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null - : hologramLocation; + hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null : hologramLocation; playerData.giveExperience(experience, source, hologramLocation, true); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java index 852ead65..3483ae41 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java @@ -4,6 +4,7 @@ import net.Indyuce.mmocore.skill.ClassSkill; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; +import javax.annotation.Nullable; import java.util.List; public class SkillSlot { @@ -11,7 +12,7 @@ public class SkillSlot { private final String formula; private final String name; private final List lore; - private Material item; + private final Material item; public SkillSlot(int slot, int modelData, String formula, String name, List lore, Material item) { this.slot = slot; @@ -27,8 +28,7 @@ public class SkillSlot { this.formula = section.contains("expression") ? section.getString("expression") : "true"; this.name = section.getString("name"); this.lore = section.getStringList("lore"); - if (section.contains("item")) - this.item = Material.valueOf(section.getString("item")); + this.item = section.contains("item") ? Material.valueOf(section.getString("item")) : null; this.modelData = section.getInt("model-data", 0); } @@ -44,6 +44,7 @@ public class SkillSlot { return lore; } + @Nullable public Material getItem() { return item; } @@ -56,7 +57,7 @@ public class SkillSlot { return modelData; } - public boolean canPlaceSkill(ClassSkill classSkill) { + public boolean acceptsSkill(ClassSkill classSkill) { return classSkill.getSkill().matchesFormula(formula); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java index 7aa355fc..ade2afe9 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java @@ -18,18 +18,19 @@ import java.util.function.BiFunction; public class SkillCommandTreeNode extends CommandTreeNode { public SkillCommandTreeNode(CommandTreeNode parent) { super(parent, "skill"); + addChild(new LockSkillCommandTreeNode(this, "lock", true)); addChild(new LockSkillCommandTreeNode(this, "unlock", false)); - addChild(new ActionCommandTreeNode(this, "give", (old, amount) -> old + amount)); - addChild(new ActionCommandTreeNode(this, "set", (old, amount) -> amount)); + addChild(new LevelCommandTreeNode(this, "give", (old, amount) -> old + amount)); + addChild(new LevelCommandTreeNode(this, "set", (old, amount) -> amount)); } - - public class ActionCommandTreeNode extends CommandTreeNode { + public class LevelCommandTreeNode extends CommandTreeNode { private final BiFunction change; - public ActionCommandTreeNode(CommandTreeNode parent, String type, BiFunction change) { + public LevelCommandTreeNode(CommandTreeNode parent, String type, BiFunction change) { super(parent, type); + this.change = change; addParameter(Parameter.PLAYER); addParameter(new Parameter("", diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index 0c53849c..09df079d 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -17,7 +17,6 @@ import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.api.SoundEvent; import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; @@ -421,7 +420,7 @@ public class SkillList extends EditableInventory { return; } - if(!skillSlot.canPlaceSkill(selected)){ + if(!skillSlot.acceptsSkill(selected)){ MMOCore.plugin.configManager.getSimpleMessage("not-compatible-skill").send(player); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); return; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/StatManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/StatManager.java index 1b6f2855..041634d0 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/StatManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/StatManager.java @@ -51,6 +51,7 @@ public class StatManager implements MMOCoreManager { * - in stats.yml which defines default stat formulas * * @return A list of stats that must be taken into account in MMOCore + * in the player stat calculation. */ public Set getRegistered() { return usedStats; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java index 7f001828..46e9823f 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java @@ -72,12 +72,10 @@ public class RegisteredSkill implements Unlockable { @Override public void whenLocked(PlayerData playerData) { - playerData.mapBoundSkills() - .forEach((slot, skill) -> - { - if (skill.equals(getUnlockNamespacedKey().split(":")[1])) - playerData.unbindSkill(slot); - }); + playerData.mapBoundSkills().forEach((slot, skill) -> { + if (skill.equals(getUnlockNamespacedKey().split(":")[1])) + playerData.unbindSkill(slot); + }); } @Override @@ -143,8 +141,7 @@ public class RegisteredSkill implements Unlockable { parsedExpression = parsedExpression.replace("<" + category + ">", "true"); parsedExpression = parsedExpression.replaceAll("<.*>", "false"); try { - boolean res = (boolean) MythicLib.plugin.getInterpreter().eval(parsedExpression); - return res; + return (boolean) MythicLib.plugin.getInterpreter().eval(parsedExpression); } catch (EvalError error) { throw new RuntimeException(error); }