mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-23 00:05:52 +01:00
Fixed issue #922 related to stats related to class/profession being lost when reloading/quitting.
This commit is contained in:
parent
09ea9ab3a9
commit
2f91a58a26
@ -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) {
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,11 @@ 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
|
||||||
public void remove(PlayerData playerData) {
|
public void remove(PlayerData playerData) {
|
||||||
|
@ -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() {
|
||||||
|
@ -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
|
||||||
|
@ -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()) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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()));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user