From f9fdbfa1272c332e3caad54e41579163e2abb288 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 16 Apr 2023 21:13:43 +0100 Subject: [PATCH] Fixed bug #782. --- .../net/Indyuce/mmocore/api/player/PlayerData.java | 11 ++++++----- .../mmocore/api/quest/trigger/StatTrigger.java | 5 ----- 2 files changed, 6 insertions(+), 10 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 b65e774e..7b688d54 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 @@ -19,6 +19,7 @@ import net.Indyuce.mmocore.api.player.profess.PlayerClass; import net.Indyuce.mmocore.api.player.profess.SavedClassInformation; import net.Indyuce.mmocore.api.player.profess.Subclass; import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; +import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.skill.binding.BoundSkillInfo; import net.Indyuce.mmocore.api.player.social.FriendRequest; import net.Indyuce.mmocore.api.player.stats.PlayerStats; @@ -163,14 +164,15 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * /mmocore reload */ public void reload() { - try { profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId()); getStats().updateStats(); } 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. + mmoData.getStatMap().getInstances().forEach(statInstance -> statInstance.removeIf(key ->key.startsWith(Trigger.TRIGGER_PREFIX))); + mmoData.getSkillModifierMap().getInstances().forEach(skillModifierInstance -> skillModifierInstance.removeIf(key ->key.startsWith(Trigger.TRIGGER_PREFIX))); final Iterator> ite = boundSkills.entrySet().iterator(); while (ite.hasNext()) try { @@ -180,9 +182,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc final @Nullable ClassSkill classSkill = getProfess().getSkill(skillId); Validate.notNull(skillSlot, "Could not find skill slot n" + entry.getKey()); Validate.notNull(classSkill, "Could not find skill with ID '" + skillId + "'"); - - entry.getValue().close(); - boundSkills.put(entry.getKey(), new BoundSkillInfo(skillSlot, classSkill, this)); + unbindSkill(entry.getKey()); + bindSkill(entry.getKey(), classSkill); } catch (Exception exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not reload data of '" + getPlayer().getName() + "': " + exception.getMessage()); } 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 1348ffc5..d99d0289 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 @@ -37,11 +37,6 @@ public class StatTrigger extends Trigger implements Removable { prevModifier.add(amount).register(player.getMMOPlayerData()); } - /** - * Removes the effect of the trigger to the player by registering the - * opposite amount. (Little corrective term for the relative to have the inverse. - * Not a problem to store twice the stat modifiers are there only remain in the RAM. - */ @Override public void remove(PlayerData playerData) { playerData.getMMOPlayerData().getStatMap().getInstance(stat).remove(modifierKey);