Fixed skills not updating when using /mmocore reload

This commit is contained in:
Jules 2023-04-10 17:30:50 +02:00
parent f13957b119
commit bb73fb57df
7 changed files with 62 additions and 58 deletions

View File

@ -45,9 +45,6 @@ import net.Indyuce.mmocore.script.mechanic.ManaMechanic;
import net.Indyuce.mmocore.script.mechanic.StaminaMechanic;
import net.Indyuce.mmocore.script.mechanic.StelliumMechanic;
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
import net.Indyuce.mmocore.skill.list.Ambers;
import net.Indyuce.mmocore.skill.list.Neptune_Gift;
import net.Indyuce.mmocore.skill.list.Sneaky_Picky;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -359,7 +356,7 @@ public class MMOCore extends JavaPlugin {
actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));
if (clearBefore)
PlayerData.getAll().forEach(PlayerData::update);
PlayerData.getAll().forEach(PlayerData::reload);
}
public static void log(String message) {

View File

@ -161,10 +161,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
* <p>
* It's OK if bound skills disappear because of a configuration issue
* on the user's end. After all this method is only called when using
* /reload and /reload is considered a bad practice. If any error
* happens then just don't update the player's skill.
* /mmocore reload
*/
public void update() {
public void reload() {
try {
profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId());
@ -173,13 +172,20 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data.");
}
Iterator<Integer> ite = boundSkills.keySet().iterator();
while (ite.hasNext()) try {
int slot = ite.next();
BoundSkillInfo boundSkillInfo = new BoundSkillInfo(boundSkills.get(slot));
boundSkills.put(slot, boundSkillInfo);
} catch (Exception ignored) {
}
final Iterator<Integer> ite = boundSkills.keySet().iterator();
while (ite.hasNext())
try {
final int slot = ite.next();
Bukkit.broadcastMessage("OLD " + boundSkills.get(slot).getClassSkill().getSkill().getModifierInfo("cooldown"));
boundSkills.put(slot, new BoundSkillInfo(boundSkills.get(slot)));
Bukkit.broadcastMessage("NEW " + boundSkills.get(slot).getClassSkill().getSkill().getModifierInfo("cooldown"));
} catch (Exception exception) {
exception.printStackTrace();
}
for (SkillTree skillTree : getProfess().getSkillTrees())
for (SkillTreeNode node : skillTree.getNodes())
@ -528,6 +534,13 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return sum;
}
@Deprecated
public List<ClassSkill> getUnlockedSkills() {
return getProfess().getSkills().stream()
.filter((classSkill) -> hasUnlocked(classSkill))
.collect(Collectors.toList());
}
@Override
public int getAttributePoints() {
return attributePoints;
@ -1161,22 +1174,19 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
*/
public void bindSkill(int slot, ClassSkill skill) {
Validate.notNull(skill, "Skill cannot be null");
//Unbinds the previous skill (Important for passive skills.
// Unbinds the previous skill (Important for passive skills.
String skillId = skill.getSkill().getHandler().getId();
if (boundSkills.containsKey(slot)) boundSkills.get(slot).unbind();
if (slot >= 0) {
//We apply the skill buffs associated with the slot to the skill.
// We apply the skill buffs associated with the slot to the skill.
for (SkillModifierTrigger skillBuffTrigger : profess.getSkillSlot(slot).getSkillBuffTriggers())
if (skillBuffTrigger.getTargetSkills().contains(skillId))
skillBuffTrigger.apply(this, skill.getSkill().getHandler());
if (skill.getSkill().getTrigger().isPassive()) {
PassiveSkill passiveSkill = skill.toPassive(this);
passiveSkill.register(mmoData);
boundSkills.put(slot, new BoundSkillInfo(skill, this, passiveSkill.getUniqueId()));
} else {
boundSkills.put(slot, new BoundSkillInfo(skill, this));
}
boundSkills.put(slot, new BoundSkillInfo(skill, this));
}
}

View File

@ -422,10 +422,12 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return false;
}
@Deprecated
public boolean hasSkill(RegisteredSkill skill) {
return hasSkill(skill.getHandler().getId());
}
@Deprecated
public boolean hasSkill(String id) {
return skills.containsKey(id);
}
@ -456,6 +458,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return skills.get(id);
}
@Deprecated
public Collection<ClassSkill> getSkills() {
return skills.values();
}

View File

@ -71,7 +71,7 @@ public class PlayerStats {
* MythicLib. Must be ran everytime the player levels up or changes class.
* <p>
* This is also called when reloading the plugin to make class setup easier,
* see {@link PlayerData#update()} for more info
* see {@link PlayerData#reload()} for more info
*/
public synchronized void updateStats() {
for (String stat : MMOCore.plugin.statManager.getRegistered()) {

View File

@ -108,15 +108,6 @@ public class ClassSkill implements CooldownObject, Unlockable {
return Objects.requireNonNull(modifiers.get(modifier), "Could not find modifier '" + modifier + "'").calculate(level);
}
/**
* Gives the delay to launch the skill
*
* @return
*/
public int getDelay(PlayerData data) {
return modifiers.containsKey("delay") ? (int) modifiers.get("delay").calculate(data.getSkillLevel(getSkill())) : 0;
}
public List<String> calculateLore(PlayerData data) {
return calculateLore(data, data.getSkillLevel(skill));
}

View File

@ -3,7 +3,9 @@ package net.Indyuce.mmocore.skill.binding;
import io.lumine.mythic.lib.player.skill.PassiveSkill;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.skill.ClassSkill;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
import java.util.UUID;
@ -12,17 +14,21 @@ public class BoundSkillInfo {
private final PlayerData playerData;
private final ClassSkill classSkill;
private UUID passiveSkillId;
/**
* Private skills must be registered inside of MythicLib when bound.
* When set to null, the skill is NOT registered.
*/
@Nullable
private PassiveSkill registered;
public BoundSkillInfo(ClassSkill classSkill, PlayerData playerData) {
this.classSkill = classSkill;
this.playerData = playerData;
}
public BoundSkillInfo(ClassSkill classSkill, PlayerData playerData, UUID passiveSkillId) {
this.classSkill = classSkill;
this.playerData = playerData;
this.passiveSkillId = passiveSkillId;
if (classSkill.getSkill().getTrigger().isPassive()) {
registered = classSkill.toPassive(playerData);
registered.register(playerData.getMMOPlayerData());
}
}
/**
@ -31,10 +37,12 @@ public class BoundSkillInfo {
public BoundSkillInfo(BoundSkillInfo info) {
this.playerData = info.getPlayerData();
this.classSkill = Objects.requireNonNull(playerData.getProfess().getSkill(info.getClassSkill().getSkill()));
info.unbind();
PassiveSkill passiveSkill = classSkill.toPassive(playerData);
passiveSkill.register(playerData.getMMOPlayerData());
this.passiveSkillId = passiveSkill.getUniqueId();
if (classSkill.getSkill().getTrigger().isPassive()) {
info.unbind();
registered = classSkill.toPassive(playerData);
registered.register(playerData.getMMOPlayerData());
}
}
@NotNull
@ -47,25 +55,23 @@ public class BoundSkillInfo {
return playerData;
}
@NotNull
public UUID getPassiveSkillId() {
return passiveSkillId;
public boolean isPassive() {
return registered != null;
}
/**
* This is used to refresh the PassiveSkill playerModifier so it is always associated to the
* This is used to refresh the PassiveSkill playerModifier
* so it is always associated to the right skill level.
*/
public void refresh() {
if (classSkill.getSkill().getTrigger().isPassive()) {
playerData.getMMOPlayerData().getPassiveSkillMap().removeModifier(passiveSkillId);
PassiveSkill passiveSkill = classSkill.toPassive(playerData);
passiveSkill.register(playerData.getMMOPlayerData());
this.passiveSkillId = passiveSkill.getUniqueId();
if (isPassive()) {
registered.unregister(playerData.getMMOPlayerData());
registered = classSkill.toPassive(playerData);
registered.register(playerData.getMMOPlayerData());
}
}
public void unbind() {
if (classSkill.getSkill().getTrigger().isPassive())
playerData.getMMOPlayerData().getPassiveSkillMap().removeModifier(passiveSkillId);
if (isPassive()) registered.unregister(playerData.getMMOPlayerData());
}
}

View File

@ -49,10 +49,7 @@ items:
slot:
slots: [ 8,17,26,35,44,53 ]
function: slot
item: BOOK
# Material used when the slot is empty
empty-item: GRAY_DYE
item: GRAY_DYE
name: '&aSkill Slot {slot}'
no-skill: '&cNone'