Fixed issue #922 related to stats related to class/profession being lost when reloading/quitting.

This commit is contained in:
Ka0rX 2023-09-06 21:48:58 +01:00
parent 09ea9ab3a9
commit 2f91a58a26
8 changed files with 29 additions and 33 deletions

View File

@ -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.StatTrigger;
import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.experience.*;
import net.Indyuce.mmocore.experience.ExperienceObject;
import net.Indyuce.mmocore.experience.ExperienceTableClaimer;
import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.experience.droptable.ExperienceItem; import net.Indyuce.mmocore.experience.droptable.ExperienceItem;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable; import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.guild.provided.Guild; import net.Indyuce.mmocore.guild.provided.Guild;
@ -153,9 +150,6 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
} catch (NullPointerException exception) { } catch (NullPointerException exception) {
MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data."); 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<Map.Entry<Integer, BoundSkillInfo>> ite = new HashMap(boundSkills).entrySet().iterator(); final Iterator<Map.Entry<Integer, BoundSkillInfo>> ite = new HashMap(boundSkills).entrySet().iterator();
while (ite.hasNext()) while (ite.hasNext())
try { try {
@ -177,6 +171,23 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
if (!nodeLevels.containsKey(node)) nodeLevels.put(node, 0); if (!nodeLevels.containsKey(node)) nodeLevels.put(node, 0);
setupSkillTree(); 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() { public void setupSkillTree() {
@ -184,11 +195,6 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
// Node states setup // Node states setup
for (SkillTree skillTree : getProfess().getSkillTrees()) for (SkillTree skillTree : getProfess().getSkillTrees())
skillTree.setupNodeStates(this); 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) { 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 * @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) { public boolean hasUnlocked(Unlockable unlockable) {
return unlockable.isUnlockedByDefault() || unlockedItems.contains(unlockable.getUnlockNamespacedKey()); 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 * checks if they could potentially upgrade to one of these
* *
* @return If the player can change its current class to * @return If the player can change its current class to
* a subclass * a subclass
*/ */
@Deprecated @Deprecated
public boolean canChooseSubclass() { public boolean canChooseSubclass() {

View File

@ -300,7 +300,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
@Override @Override
public String getKey() { public String getKey() {
return "class." + getId(); return "class_" + getId();
} }
@NotNull @NotNull

View File

@ -107,7 +107,7 @@ public class SavedClassInformation implements ClassDataContainer {
for (Entry<String, JsonElement> entry : json.getAsJsonObject("bound-skills").entrySet()) for (Entry<String, JsonElement> entry : json.getAsJsonObject("bound-skills").entrySet())
boundSkills.put(Integer.parseInt(entry.getKey()), entry.getValue().getAsString()); boundSkills.put(Integer.parseInt(entry.getKey()), entry.getValue().getAsString());
if (json.has("unlocked-items")) 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()); 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. // Add the values to the times claimed table and claims the corresponding stat triggers.
nodeTimesClaimed.forEach((str, val) -> player.setClaims(str, val)); 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 // Unload current class information
player.unloadClassInfo(profess); player.unloadClassInfo(profess);
@ -356,7 +351,7 @@ public class SavedClassInformation implements ClassDataContainer {
player.setMana(mana); player.setMana(mana);
player.setStellium(stellium); player.setStellium(stellium);
player.setStamina(stamina); player.setStamina(stamina);
player.setupRemovableTrigger();
// Updates level on exp bar // Updates level on exp bar
player.refreshVanillaExp(); player.refreshVanillaExp();
} }

View File

@ -33,8 +33,10 @@ public class StatTrigger extends Trigger implements Removable {
StatModifier prevModifier = player.getMMOPlayerData().getStatMap().getInstance(stat).getModifier(modifierKey); StatModifier prevModifier = player.getMMOPlayerData().getStatMap().getInstance(stat).getModifier(modifierKey);
if (prevModifier == null) if (prevModifier == null)
statModifier.register(player.getMMOPlayerData()); statModifier.register(player.getMMOPlayerData());
else else {
prevModifier.unregister(player.getMMOPlayerData());
prevModifier.add(amount).register(player.getMMOPlayerData()); prevModifier.add(amount).register(player.getMMOPlayerData());
}
} }
@Override @Override

View File

@ -100,14 +100,6 @@ public class PlayerProfessions {
if (obj.has("timesClaimed")) if (obj.has("timesClaimed"))
for (Entry<String, JsonElement> entry : obj.getAsJsonObject("timesClaimed").entrySet()) for (Entry<String, JsonElement> entry : obj.getAsJsonObject("timesClaimed").entrySet())
playerData.getItemClaims().put("profession." + entry.getKey(), entry.getValue().getAsInt()); 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() { public PlayerData getPlayerData() {

View File

@ -93,7 +93,7 @@ public class Profession extends PostLoadObject implements ExperienceObject {
@Override @Override
public String getKey() { public String getKey() {
return "profession." + getId(); return "profession_" + getId();
} }
@Override @Override

View File

@ -122,6 +122,7 @@ public class MMOCoreDataSynchronizer extends SQLDataSynchronizer<PlayerData> {
getData().setMana(result.getDouble("mana")); getData().setMana(result.getDouble("mana"));
getData().setStamina(result.getDouble("stamina")); getData().setStamina(result.getDouble("stamina"));
getData().setStellium(result.getDouble("stellium")); getData().setStellium(result.getDouble("stellium"));
getData().setupRemovableTrigger();
if (getData().isOnline() && !getData().getPlayer().isDead()) { if (getData().isOnline() && !getData().getPlayer().isDead()) {
/* /*

View File

@ -133,7 +133,7 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA")); data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA"));
data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA")); data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA"));
data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM")); data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM"));
data.setupRemovableTrigger();
if (data.isOnline() && !data.getPlayer().isDead()) if (data.isOnline() && !data.getPlayer().isDead())
data.getPlayer().setHealth(MMOCoreUtils.fixResource(config.getDouble("health"), data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())); data.getPlayer().setHealth(MMOCoreUtils.fixResource(config.getDouble("health"), data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
} }