use of io.github.nucleuspowered.nucleus.internal.command.CommandBuilder in project Nucleus by NucleusPowered.
the class StandardModule method loadCommands.
@SuppressWarnings("unchecked")
private void loadCommands() {
Set<Class<? extends AbstractCommand<?>>> cmds;
if (this.msls != null) {
cmds = new HashSet<>();
List<String> l = this.msls.get(Constants.COMMAND);
if (l == null) {
return;
}
for (String s : l) {
try {
checkPlatformOpt((Class<? extends AbstractCommand<?>>) Class.forName(s)).ifPresent(cmds::add);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
} else {
cmds = new HashSet<>(performFilter(getStreamForModule(AbstractCommand.class).map(x -> (Class<? extends AbstractCommand<?>>) x)).collect(Collectors.toSet()));
// Find all commands that are also scannable.
performFilter(plugin.getModuleContainer().getLoadedClasses().stream().filter(x -> x.getPackage().getName().startsWith(packageName)).filter(x -> x.isAnnotationPresent(Scan.class)).flatMap(x -> Arrays.stream(x.getDeclaredClasses())).filter(AbstractCommand.class::isAssignableFrom).map(x -> (Class<? extends AbstractCommand<?>>) x)).forEach(cmds::add);
}
// We all love the special injector. We just want to provide the module with more commands, in case it needs a child.
Set<Class<? extends AbstractCommand>> commandBases = cmds.stream().filter(x -> {
RegisterCommand rc = x.getAnnotation(RegisterCommand.class);
return (rc != null && rc.subcommandOf().equals(AbstractCommand.class));
}).collect(Collectors.toSet());
CommandBuilder builder = new CommandBuilder(plugin, cmds, moduleId, moduleName);
commandBases.forEach(builder::buildCommand);
try {
commandsConfig.mergeDefaults(builder.getNodeToMerge());
commandsConfig.save();
} catch (Exception e) {
plugin.getLogger().error("Could not save defaults.");
e.printStackTrace();
}
}
Aggregations