From 29aebdc2a19bdcd37c2c5701d226c145557c8fe6 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Fri, 28 Oct 2022 21:56:02 +0200 Subject: [PATCH] Fixed bug of stats adding up when quitting and joining back --- .../mmocore/api/player/PlayerData.java | 27 +++++++++++++++---- .../mmocore/experience/PlayerProfessions.java | 9 ++++--- 2 files changed, 27 insertions(+), 9 deletions(-) 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 02d32258..529f4a86 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 @@ -2,6 +2,8 @@ package net.Indyuce.mmocore.api.player; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.player.MMOPlayerData; +import io.lumine.mythic.lib.api.stat.StatInstance; +import io.lumine.mythic.lib.api.stat.modifier.StatModifier; import io.lumine.mythic.lib.player.cooldown.CooldownMap; import io.lumine.mythic.lib.player.skill.PassiveSkill; import net.Indyuce.mmocore.party.provided.MMOCorePartyModule; @@ -33,6 +35,7 @@ import net.Indyuce.mmocore.guild.provided.Guild; import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect; import net.Indyuce.mmocore.party.AbstractParty; import net.Indyuce.mmocore.player.Unlockable; +import net.Indyuce.mmocore.player.stats.StatInfo; import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.skill.cast.SkillCastingHandler; @@ -117,6 +120,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc // NON-FINAL player data stuff made public to facilitate field change public boolean noCooldown; + private boolean statLoaded; public CombatRunnable combat; /** @@ -132,6 +136,13 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc questData = new PlayerQuests(this); playerStats = new PlayerStats(this); + //Used to see if the triggers need to be applied + boolean statLoaded = false; + for (StatInstance instance : mmoData.getStatMap().getInstances()) + for (StatModifier modifier : instance.getModifiers()) + if (modifier.getKey().startsWith("trigger")) + statLoaded = true; + this.statLoaded = statLoaded; } @@ -168,12 +179,14 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll()) skillTree.setupNodeState(this); - //Stat triggers setup - for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll()) { - for (SkillTreeNode node : skillTree.getNodes()) { - node.getExperienceTable().claimStatTriggers(this, node); + + if (!statLoaded) + //Stat triggers setup + for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll()) { + for (SkillTreeNode node : skillTree.getNodes()) { + node.getExperienceTable().claimStatTriggers(this, node); + } } - } } @@ -227,6 +240,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return nodeLevelsString.entrySet(); } + public boolean isStatLoaded() { + return statLoaded; + } + public Map getNodeLevels() { return new HashMap<>(nodeLevels); } 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 9061864f..4b16578b 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,10 +100,11 @@ public class PlayerProfessions { 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().claimStatTriggers(playerData, profession); - } + if (!playerData.isStatLoaded()) + for (Profession profession : MMOCore.plugin.professionManager.getAll()) { + if (profession.hasExperienceTable()) + profession.getExperienceTable().claimStatTriggers(playerData, profession); + } }