Other plugins can register skills

This commit is contained in:
Indyuce 2020-04-19 21:21:05 +02:00
parent 1923bff73c
commit f829d7c1be
2 changed files with 14 additions and 6 deletions

View File

@ -105,12 +105,12 @@ public class MMOCore extends JavaPlugin {
public RestrictionManager restrictionManager; public RestrictionManager restrictionManager;
public RequestManager requestManager; public RequestManager requestManager;
public ConfigItemManager configItems; public ConfigItemManager configItems;
public SkillManager skillManager;
public VaultEconomy economy; public VaultEconomy economy;
public HologramSupport hologramSupport; public HologramSupport hologramSupport;
public InventoryManager inventoryManager; public InventoryManager inventoryManager;
public RegionHandler regionHandler; public RegionHandler regionHandler;
public PlayerActionBar actionBarManager; public PlayerActionBar actionBarManager;
public final SkillManager skillManager = new SkillManager();
public PlaceholderParser placeholderParser = new DefaultParser(); public PlaceholderParser placeholderParser = new DefaultParser();
public DataProvider dataProvider = new YAMLDataProvider(); public DataProvider dataProvider = new YAMLDataProvider();
public final ClassManager classManager = new ClassManager(); public final ClassManager classManager = new ClassManager();
@ -381,7 +381,8 @@ public class MMOCore extends JavaPlugin {
public void reloadPlugin() { public void reloadPlugin() {
configManager = new ConfigManager(); configManager = new ConfigManager();
skillManager = new SkillManager();
skillManager.reload();
mineManager.clear(); mineManager.clear();
mineManager.reload(); mineManager.reload();

View File

@ -22,15 +22,21 @@ import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.comp.mythicmobs.MythicMobSkill; import net.Indyuce.mmocore.comp.mythicmobs.MythicMobSkill;
public class SkillManager { public class SkillManager {
private Map<String, Skill> skills = new LinkedHashMap<>(); private final Map<String, Skill> 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()) if (skills.isEmpty())
try { try {
JarEntry entry; JarEntry entry;
for (Enumeration<JarEntry> en = new JarFile(MMOCore.plugin.getJarFile()).entries(); en.hasMoreElements();) for (Enumeration<JarEntry> 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()); register((Skill) Class.forName(entry.getName().replace("/", ".").replace(".class", "")).newInstance());
} catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException exception) { } catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException exception) {
exception.printStackTrace(); exception.printStackTrace();
@ -50,7 +56,8 @@ public class SkillManager {
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null)
for (File file : mythicMobs.listFiles()) { for (File file : mythicMobs.listFiles()) {
try { 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) { } catch (Exception exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill from " + file.getName() + ": " + exception.getMessage()); MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill from " + file.getName() + ": " + exception.getMessage());
} }