forked from Upstream/mmocore
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.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<Map.Entry<Integer, BoundSkillInfo>> 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() {
|
||||
|
@ -300,7 +300,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "class." + getId();
|
||||
return "class_" + getId();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -107,7 +107,7 @@ public class SavedClassInformation implements ClassDataContainer {
|
||||
for (Entry<String, JsonElement> 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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -100,14 +100,6 @@ public class PlayerProfessions {
|
||||
if (obj.has("timesClaimed"))
|
||||
for (Entry<String, JsonElement> 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() {
|
||||
|
@ -93,7 +93,7 @@ public class Profession extends PostLoadObject implements ExperienceObject {
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "profession." + getId();
|
||||
return "profession_" + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,6 +122,7 @@ public class MMOCoreDataSynchronizer extends SQLDataSynchronizer<PlayerData> {
|
||||
getData().setMana(result.getDouble("mana"));
|
||||
getData().setStamina(result.getDouble("stamina"));
|
||||
getData().setStellium(result.getDouble("stellium"));
|
||||
getData().setupRemovableTrigger();
|
||||
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.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.setupRemovableTrigger();
|
||||
if (data.isOnline() && !data.getPlayer().isDead())
|
||||
data.getPlayer().setHealth(MMOCoreUtils.fixResource(config.getDouble("health"), data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user