diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 5ecf8c7f..c53c9f6b 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -105,12 +105,12 @@ public class MMOCore extends JavaPlugin { public RestrictionManager restrictionManager; public RequestManager requestManager; public ConfigItemManager configItems; - public SkillManager skillManager; public VaultEconomy economy; public HologramSupport hologramSupport; public InventoryManager inventoryManager; public RegionHandler regionHandler; public PlayerActionBar actionBarManager; + public final SkillManager skillManager = new SkillManager(); public PlaceholderParser placeholderParser = new DefaultParser(); public DataProvider dataProvider = new YAMLDataProvider(); public final ClassManager classManager = new ClassManager(); @@ -381,7 +381,8 @@ public class MMOCore extends JavaPlugin { public void reloadPlugin() { configManager = new ConfigManager(); - skillManager = new SkillManager(); + + skillManager.reload(); mineManager.clear(); mineManager.reload(); diff --git a/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java b/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java index 10c5a05c..d7ed9396 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java @@ -22,15 +22,21 @@ import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.comp.mythicmobs.MythicMobSkill; public class SkillManager { - private Map skills = new LinkedHashMap<>(); + private final Map skills = new LinkedHashMap<>(); - public SkillManager() { + /* + * 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() { if (skills.isEmpty()) try { JarEntry entry; for (Enumeration en = new JarFile(MMOCore.plugin.getJarFile()).entries(); en.hasMoreElements();) - if ((entry = en.nextElement()).getName().startsWith("net/Indyuce/mmocore/skill/") && !entry.isDirectory() && !entry.getName().contains("$")) + if ((entry = en.nextElement()).getName().startsWith("net/Indyuce/mmocore/skill/") && !entry.isDirectory() + && !entry.getName().contains("$")) register((Skill) Class.forName(entry.getName().replace("/", ".").replace(".class", "")).newInstance()); } catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException exception) { exception.printStackTrace(); @@ -50,7 +56,8 @@ public class SkillManager { if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) for (File file : mythicMobs.listFiles()) { try { - register(new MythicMobSkill(file.getName().substring(0, file.getName().length() - 4).toUpperCase(), YamlConfiguration.loadConfiguration(file))); + register(new MythicMobSkill(file.getName().substring(0, file.getName().length() - 4).toUpperCase(), + YamlConfiguration.loadConfiguration(file))); } catch (Exception exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill from " + file.getName() + ": " + exception.getMessage()); }