From 39f95634a08a73c8d402d4273045f27c08dac202 Mon Sep 17 00:00:00 2001 From: Jules Date: Fri, 14 Apr 2023 16:39:58 +0200 Subject: [PATCH] Fixed skills not unregistering on logout/changing class --- .../Indyuce/mmocore/api/player/PlayerData.java | 15 +++++++++------ .../player/profess/SavedClassInformation.java | 17 +++++------------ .../mmocore/api/player/stats/PlayerStats.java | 12 ++++++------ .../data/mysql/MMOCoreDataSynchronizer.java | 5 +---- .../mmocore/skill/binding/BoundSkillInfo.java | 7 ++++++- 5 files changed, 27 insertions(+), 29 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 25d0f5cf..426100d4 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 @@ -452,6 +452,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc // Close quest data questData.close(); + // Close bound skills + boundSkills.forEach((slot, info) -> info.close()); + // Stop skill casting if (isCasting()) leaveSkillCasting(); } @@ -1165,17 +1168,17 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc /** * Binds a skill to the player. * - * @param slot Slot to which you're binding the skill. - * Use -1 to force-register the skill + * @param slot Slot to which you're binding the skill * @param skill Skill being bound */ - public void bindSkill(int slot, ClassSkill skill) { + public void bindSkill(int slot, @NotNull ClassSkill skill) { Validate.notNull(skill, "Skill cannot be null"); - // Unbinds the previous skill (important for passive skills) - unbindSkill(slot); - if (slot >= 0) { + + // Unbinds the previous skill (important for passive skills) + unbindSkill(slot); + final SkillSlot skillSlot = getProfess().getSkillSlot(slot); boundSkills.put(slot, new BoundSkillInfo(skillSlot, skill, this)); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index 43f67d23..fca842f2 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -301,22 +301,18 @@ public class SavedClassInformation implements ClassDataContainer { player.clearSkillTreePoints(); player.clearNodeLevels(); player.clearNodeStates(); + player.clearNodeTimesClaimed(); - // We remove perm stats for nodes and class. + // Remove perm stats for nodes and class for (SkillTree skillTree : player.getProfess().getSkillTrees()) for (SkillTreeNode node : skillTree.getNodes()) node.getExperienceTable().removePermStats(player, node); if (player.getProfess().hasExperienceTable()) player.getProfess().getExperienceTable().removePermStats(player, player.getProfess()); - while (player.hasSkillBound(0)) - player.unbindSkill(0); - player.clearNodeTimesClaimed(); - /* * Reads this class info, applies it to the player. set class after - * changing level so the player stats can be calculated based on new - * level. + * changing level so the player stats can be calculated based on new level */ player.setLevel(level); player.setExperience(experience); @@ -326,6 +322,7 @@ public class SavedClassInformation implements ClassDataContainer { player.setSkillTreeReallocationPoints(skillTreeReallocationPoints); player.setSkillReallocationPoints(skillReallocationPoints); player.setUnlockedItems(unlockedItems); + player.setClass(profess); for (int slot : boundSkills.keySet()) player.bindSkill(slot, profess.getSkill(boundSkills.get(slot))); @@ -351,11 +348,7 @@ public class SavedClassInformation implements ClassDataContainer { node.getExperienceTable().claimStatTriggers(player, node); profess.getExperienceTable().claimStatTriggers(player, profess); - /* - * Unload current class information and set - * the new profess once everything is changed - */ - player.setClass(profess); + // Unload current class information player.unloadClassInfo(profess); // This needs to be done at the end to make sure the MAX_HEALTH/MAX_MANA/... stats are loaded. diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java index ed6a2e92..19070ae6 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java @@ -99,12 +99,12 @@ public class PlayerStats { */ final PassiveSkillMap skillMap = data.getMMOPlayerData().getPassiveSkillMap(); - if (!MMOCore.plugin.configManager.passiveSkillNeedBound) { - skillMap.removeModifiers("MMOCorePassiveSkill"); - for (ClassSkill skill : data.getProfess().getSkills()) - if (skill.getSkill().getTrigger().isPassive()) - skillMap.addModifier(skill.toPassive(data)); - } + //if (!MMOCore.plugin.configManager.passiveSkillNeedBound) { + // skillMap.removeModifiers("MMOCorePassiveSkill"); + // for (ClassSkill skill : data.getProfess().getSkills()) + // if (skill.getSkill().getTrigger().isPassive()) + // skillMap.addModifier(skill.toPassive(data)); + //} // This updates the player's class SCRIPTS skillMap.removeModifiers("MMOCoreClassScript"); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java index 0aa34d9e..6da7df3b 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java @@ -9,13 +9,10 @@ import net.Indyuce.mmocore.api.player.profess.PlayerClass; import net.Indyuce.mmocore.api.player.profess.SavedClassInformation; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.guild.provided.Guild; -import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skilltree.SkillTreeNode; import net.Indyuce.mmocore.skilltree.tree.SkillTree; import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; import org.bukkit.attribute.Attribute; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.Nullable; import java.sql.ResultSet; @@ -61,8 +58,8 @@ public class MMOCoreDataSynchronizer extends DataSynchronizer { data.setSkillTreePoints(skillTree.getId(), json.has(skillTree.getId()) ? json.get(skillTree.getId()).getAsInt() : 0); } data.setSkillTreePoints("global", json.has("global") ? json.get("global").getAsInt() : 0); - } + if (!isEmpty(result.getString("skill_tree_levels"))) { JsonObject json = new JsonParser().parse(result.getString("skill_tree_levels")).getAsJsonObject(); for (SkillTreeNode skillTreeNode : MMOCore.plugin.skillTreeManager.getAllNodes()) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/binding/BoundSkillInfo.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/binding/BoundSkillInfo.java index a06b0d14..3d9683d7 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/binding/BoundSkillInfo.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/binding/BoundSkillInfo.java @@ -6,6 +6,7 @@ import net.Indyuce.mmocore.api.quest.trigger.SkillModifierTrigger; import net.Indyuce.mmocore.api.util.Closable; import net.Indyuce.mmocore.skill.ClassSkill; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,6 +37,7 @@ public class BoundSkillInfo implements Closable { if (classSkill.getSkill().getTrigger().isPassive()) { registered = classSkill.toPassive(playerData); registered.register(playerData.getMMOPlayerData()); + Bukkit.broadcastMessage("Registering passive skill " + classSkill.getSkill().getHandler().getId()); } else registered = null; } @@ -64,7 +66,10 @@ public class BoundSkillInfo implements Closable { open = false; // Unregister skill if passive - if (isPassive()) registered.unregister(playerData.getMMOPlayerData()); + if (isPassive()) { + Bukkit.broadcastMessage("Unregistered passive skill " + classSkill.getSkill().getHandler().getId()); + registered.unregister(playerData.getMMOPlayerData()); + } // Remove skill buffs associated to the slot skillSlot.getSkillBuffTriggers().forEach(skillBuffTrigger -> skillBuffTrigger.remove(playerData, classSkill.getSkill().getHandler()));