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 e75449dc..695b16d0 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 @@ -25,10 +25,7 @@ import net.Indyuce.mmocore.api.quest.PlayerQuests; import net.Indyuce.mmocore.api.quest.trigger.StatTrigger; import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.api.util.MMOCoreUtils; -import net.Indyuce.mmocore.experience.EXPSource; -import net.Indyuce.mmocore.experience.ExperienceObject; -import net.Indyuce.mmocore.experience.ExperienceTableClaimer; -import net.Indyuce.mmocore.experience.PlayerProfessions; +import net.Indyuce.mmocore.experience.*; import net.Indyuce.mmocore.experience.droptable.ExperienceItem; import net.Indyuce.mmocore.experience.droptable.ExperienceTable; import net.Indyuce.mmocore.guild.provided.Guild; @@ -153,9 +150,6 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD } catch (NullPointerException exception) { MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data."); } - //We remove all the stats and buffs associated to triggers. - getMMOPlayerData().getStatMap().getInstances().forEach(statInstance -> statInstance.removeIf(key -> key.startsWith(Trigger.TRIGGER_PREFIX))); - getMMOPlayerData().getSkillModifierMap().getInstances().forEach(skillModifierInstance -> skillModifierInstance.removeIf(key -> key.startsWith(Trigger.TRIGGER_PREFIX))); final Iterator> ite = new HashMap(boundSkills).entrySet().iterator(); while (ite.hasNext()) try { @@ -177,6 +171,23 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD if (!nodeLevels.containsKey(node)) nodeLevels.put(node, 0); setupSkillTree(); + setupRemovableTrigger(); + } + + public void setupRemovableTrigger() { + //We remove all the stats and buffs associated to triggers. + getMMOPlayerData().getStatMap().getInstances().forEach(statInstance -> statInstance.removeIf(key -> key.startsWith(Trigger.TRIGGER_PREFIX))); + getMMOPlayerData().getSkillModifierMap().getInstances().forEach(skillModifierInstance -> skillModifierInstance.removeIf(key -> key.startsWith(Trigger.TRIGGER_PREFIX))); + + if (profess.hasExperienceTable()) + profess.getExperienceTable().claimRemovableTrigger(this, profess); + for (Profession profession : MMOCore.plugin.professionManager.getAll()) + if (profession.hasExperienceTable()) + profession.getExperienceTable().claimRemovableTrigger(this, profession); + // Stat triggers setup + for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll()) + for (SkillTreeNode node : skillTree.getNodes()) + node.getExperienceTable().claimRemovableTrigger(this, node); } public void setupSkillTree() { @@ -184,11 +195,6 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD // 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().claimRemovableTrigger(this, node); } public int getPointSpent(SkillTree skillTree) { @@ -351,7 +357,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD /** * @return If the item is unlocked by the player - * This is used for skills that can be locked & unlocked. + * This is used for skills that can be locked & unlocked. */ public boolean hasUnlocked(Unlockable unlockable) { return unlockable.isUnlockedByDefault() || unlockedItems.contains(unlockable.getUnlockNamespacedKey()); @@ -1221,7 +1227,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD * checks if they could potentially upgrade to one of these * * @return If the player can change its current class to - * a subclass + * a subclass */ @Deprecated public boolean canChooseSubclass() { 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 115a91cb..a9ce304b 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 @@ -300,7 +300,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { @Override public String getKey() { - return "class." + getId(); + return "class_" + getId(); } @NotNull diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index 4d973de9..ef4436b8 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -107,7 +107,7 @@ public class SavedClassInformation implements ClassDataContainer { for (Entry entry : json.getAsJsonObject("bound-skills").entrySet()) boundSkills.put(Integer.parseInt(entry.getKey()), entry.getValue().getAsString()); if (json.has("unlocked-items")) - for ( JsonElement unlockedItem : json.get("unlocked-items").getAsJsonArray()) + for (JsonElement unlockedItem : json.get("unlocked-items").getAsJsonArray()) unlockedItems.add(unlockedItem.getAsString()); } @@ -342,11 +342,6 @@ public class SavedClassInformation implements ClassDataContainer { // Add the values to the times claimed table and claims the corresponding stat triggers. nodeTimesClaimed.forEach((str, val) -> player.setClaims(str, val)); - // We claim back the stats triggers for all the skill tree nodes of the new class. - for (SkillTree skillTree : profess.getSkillTrees()) - for (SkillTreeNode node : skillTree.getNodes()) - node.getExperienceTable().claimRemovableTrigger(player, node); - profess.getExperienceTable().claimRemovableTrigger(player, profess); // Unload current class information player.unloadClassInfo(profess); @@ -356,7 +351,7 @@ public class SavedClassInformation implements ClassDataContainer { player.setMana(mana); player.setStellium(stellium); player.setStamina(stamina); - + player.setupRemovableTrigger(); // Updates level on exp bar player.refreshVanillaExp(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StatTrigger.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StatTrigger.java index d99d0289..e95c0668 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StatTrigger.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StatTrigger.java @@ -33,8 +33,10 @@ public class StatTrigger extends Trigger implements Removable { StatModifier prevModifier = player.getMMOPlayerData().getStatMap().getInstance(stat).getModifier(modifierKey); if (prevModifier == null) statModifier.register(player.getMMOPlayerData()); - else + else { + prevModifier.unregister(player.getMMOPlayerData()); prevModifier.add(amount).register(player.getMMOPlayerData()); + } } @Override diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java index d442c0c4..b6e04f0f 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java @@ -100,14 +100,6 @@ public class PlayerProfessions { if (obj.has("timesClaimed")) for (Entry entry : obj.getAsJsonObject("timesClaimed").entrySet()) playerData.getItemClaims().put("profession." + entry.getKey(), entry.getValue().getAsInt()); - - for (Profession profession : MMOCore.plugin.professionManager.getAll()) { - if (profession.hasExperienceTable()) - profession.getExperienceTable().claimRemovableTrigger(playerData, profession); - } - if (playerData.getProfess().hasExperienceTable()) - playerData.getProfess().getExperienceTable().claimRemovableTrigger(playerData, playerData.getProfess()); - } public PlayerData getPlayerData() { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/Profession.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/Profession.java index 4a152548..a5d8dbc7 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/Profession.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/Profession.java @@ -93,7 +93,7 @@ public class Profession extends PostLoadObject implements ExperienceObject { @Override public String getKey() { - return "profession." + getId(); + return "profession_" + getId(); } @Override diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/MMOCoreDataSynchronizer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/MMOCoreDataSynchronizer.java index 30736a42..2ce01a59 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/MMOCoreDataSynchronizer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/sql/MMOCoreDataSynchronizer.java @@ -122,6 +122,7 @@ public class MMOCoreDataSynchronizer extends SQLDataSynchronizer { getData().setMana(result.getDouble("mana")); getData().setStamina(result.getDouble("stamina")); getData().setStellium(result.getDouble("stellium")); + getData().setupRemovableTrigger(); if (getData().isOnline() && !getData().getPlayer().isDead()) { /* diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataHandler.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataHandler.java index 8cd0d6cd..9542a275 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataHandler.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataHandler.java @@ -133,7 +133,7 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler