Fixed skills not unregistering on logout/changing class

This commit is contained in:
Jules 2023-04-14 16:39:58 +02:00
parent 0bcd11cf68
commit 39f95634a0
5 changed files with 27 additions and 29 deletions

View File

@ -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));
}

View File

@ -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.

View File

@ -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");

View File

@ -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()) {

View File

@ -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()));