use of io.github.nucleuspowered.nucleus.internal.ListenerBase in project Nucleus by NucleusPowered.
the class StandardModule method loadEvents.
@SuppressWarnings("unchecked")
private void loadEvents() {
Set<Class<? extends ListenerBase>> listenersToLoad;
if (msls != null) {
listenersToLoad = new HashSet<>();
List<String> l = this.msls.get(Constants.LISTENER);
if (l == null) {
return;
}
for (String s : l) {
try {
checkPlatformOpt((Class<? extends ListenerBase>) Class.forName(s)).ifPresent(listenersToLoad::add);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
} else {
listenersToLoad = getStreamForModule(ListenerBase.class).collect(Collectors.toSet());
}
Optional<DocGenCache> docGenCache = plugin.getDocGenCache();
listenersToLoad.stream().map(x -> this.getInstance(x, true)).filter(Objects::nonNull).forEach(c -> {
// Register suggested permissions
c.getPermissions().forEach((k, v) -> plugin.getPermissionRegistry().registerOtherPermission(k, v));
docGenCache.ifPresent(x -> x.addPermissionDocs(moduleId, c.getPermissions()));
if (c instanceof ListenerBase.Conditional) {
// Add reloadable to load in the listener dynamically if required.
Reloadable tae = () -> {
Sponge.getEventManager().unregisterListeners(c);
if (c instanceof Reloadable) {
((Reloadable) c).onReload();
}
if (((ListenerBase.Conditional) c).shouldEnable()) {
Sponge.getEventManager().registerListeners(plugin, c);
}
};
plugin.registerReloadable(tae);
try {
tae.onReload();
} catch (Exception e) {
e.printStackTrace();
}
} else if (c instanceof Reloadable) {
plugin.registerReloadable(((Reloadable) c));
Sponge.getEventManager().registerListeners(plugin, c);
} else {
Sponge.getEventManager().registerListeners(plugin, c);
}
});
}
Aggregations