use of pl.themolka.arcade.module.ModulesLoadEvent in project Arcade2 by ShootGame.
the class ArcadePlugin method loadModules.
private void loadModules() {
Node ignoredModules = this.getSettings().getData().child("ignored-modules");
if (ignoredModules == null) {
ignoredModules = Node.empty();
}
List<String> ignoredModuleList = new ArrayList<>();
for (Node ignoredModule : ignoredModules.children("module")) {
String id = ignoredModule.getValue();
if (id != null && !id.isEmpty()) {
ignoredModuleList.add(id);
}
}
List<Module<?>> moduleList = new ArrayList<>();
try (InputStream input = this.getClass().getClassLoader().getResourceAsStream(ModulesFile.DEFAULT_FILENAME)) {
ModulesFile file = new ModulesFile(this, input);
for (Module<?> module : file.getModules()) {
ModuleInfo infoAnnotation = module.getClass().getAnnotation(ModuleInfo.class);
if (infoAnnotation == null) {
continue;
}
if (!ignoredModuleList.contains(infoAnnotation.id().toLowerCase())) {
moduleList.add(module);
}
}
} catch (DOMException | IOException ex) {
ex.printStackTrace();
}
ModulesLoadEvent loadEvent = new ModulesLoadEvent(this, moduleList);
this.getEventBus().publish(loadEvent);
List<Module<?>> success = new ArrayList<>();
for (Module<?> module : loadEvent.getModules()) {
try {
module.initialize(this);
module.registerCommandObject(module);
success.add(module);
} catch (Throwable th) {
this.getLogger().log(Level.SEVERE, "Could not load module '" + module.getId() + "': " + th.getMessage(), th);
}
}
this.getLogger().info("Successfully loaded " + success.size() + " of " + loadEvent.getModules().size() + " available modules.");
this.getModules().register(success.toArray(new Module<?>[success.size()]));
Node globalModules = this.getSettings().getData().child("modules");
if (globalModules == null) {
globalModules = Node.empty();
}
for (Module<?> module : this.getModules().getModules()) {
try {
Node moduleNode = globalModules.child(module.getId());
module.setGlobal(moduleNode != null);
module.registerListeners();
module.onEnable(moduleNode);
} catch (Throwable th) {
this.getLogger().log(Level.SEVERE, "Could not enable module '" + module.getId() + "': " + th.getMessage(), th);
}
}
}
Aggregations