From 98801a4870cb2aea4432369a2bfbeebc31985011 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Mon, 27 Dec 2021 13:55:20 +0100 Subject: [PATCH] fixed /mmocore admin level set --- .../mmocore/api/player/PlayerData.java | 5 ++- .../Indyuce/mmocore/manager/SkillManager.java | 43 +++++++++++-------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index cf142602..dbf199b3 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -246,12 +246,13 @@ public class PlayerData extends OfflinePlayerData implements Closable { public void setLevel(int level) { this.level = Math.max(1, level); + getStats().updateStats(); + refreshVanillaExp(); } public void takeLevels(int value) { - this.level = Math.max(1, level - value); - getStats().updateStats(); + setLevel(level - value); } public void giveLevels(int value, EXPSource source) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java b/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java index e6f64c7a..c9d21c57 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java @@ -2,11 +2,8 @@ package net.Indyuce.mmocore.manager; import java.io.File; import java.io.IOException; -import java.util.Collection; -import java.util.Enumeration; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; +import java.lang.reflect.InvocationTargetException; +import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.logging.Level; @@ -21,9 +18,11 @@ import net.Indyuce.mmocore.skill.Skill; import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.comp.mythicmobs.MythicSkill; -public class SkillManager { +public class SkillManager implements MMOCoreManager { private final Map skills = new LinkedHashMap<>(); + private boolean hasLoadedDefaultSkills; + public void register(Skill skill) { skills.put(skill.getId().toUpperCase(), skill); } @@ -48,24 +47,31 @@ public class SkillManager { return skills.keySet(); } - /* - * Skills are initialized when MMOCore enables but SkillManager must be - * instanced when MMOCore loads so that extra plugins can register skills - * before CLASSES are loaded - */ - public void reload() { + @Override + public void initialize(boolean clearBefore) { - if (skills.isEmpty()) + if (clearBefore) { + + // Only remove custom skills + Iterator ite = skills.values().iterator(); + while (ite.hasNext()) { + Skill next = ite.next(); + if (next instanceof MythicSkill) + ite.remove(); + } + } + + if (!hasLoadedDefaultSkills) try { + hasLoadedDefaultSkills = true; JarFile jarFile = new JarFile(MMOCore.plugin.getJarFile()); JarEntry entry; for (Enumeration en = jarFile.entries(); en.hasMoreElements();) if ((entry = en.nextElement()).getName().startsWith("net/Indyuce/mmocore/skill/list/") && !entry.isDirectory() && !entry.getName().contains("$")) - register((Skill) Class.forName(entry.getName().replace("/", ".").replace(".class", "")) - .newInstance()); + register((Skill) Class.forName(entry.getName().replace("/", ".").replace(".class", "")).getDeclaredConstructor().newInstance()); jarFile.close(); - } catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException exception) { + } catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException exception) { exception.printStackTrace(); MMOCore.log(Level.WARNING, "Could not load skills! Careful with player data :("); } @@ -88,6 +94,7 @@ public class SkillManager { } } + // Load configuration for default skills for (Skill skill : getAll()) if (!(skill instanceof MythicSkill)) { File file = new File(MMOCore.plugin.getDataFolder() + "/skills", skill.getLowerCaseId() + ".yml"); @@ -98,7 +105,7 @@ public class SkillManager { config.getConfig().set("lore", skill.getLore()); /* - * it does support custom modeled items but it does not + * It does support custom modeled items but it does not * provide default configs for that. */ config.getConfig().set("material", skill.getIcon().getType().name()); @@ -112,10 +119,10 @@ public class SkillManager { if (value.hasMin()) config.getConfig().set(mod + ".min", value.getMin()); } + config.save(); } skill.update(config.getConfig()); - config.save(); } } }