use of io.github.nucleuspowered.nucleus.internal.docgen.DocGenCache in project Nucleus by NucleusPowered.
the class DocGenCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.docgen.start"));
DocGenCache genCache = plugin.getDocGenCache().get();
// Generate command file.
YAMLConfigurationLoader configurationLoader = YAMLConfigurationLoader.builder().setPath(plugin.getDataPath().resolve("commands.yml")).setFlowStyle(DumperOptions.FlowStyle.BLOCK).build();
List<CommandDoc> lcd = getAndSort(genCache.getCommandDocs(), (first, second) -> {
int m = first.getModule().compareToIgnoreCase(second.getModule());
if (m == 0) {
return first.getCommandName().compareToIgnoreCase(second.getCommandName());
}
return m;
});
ConfigurationNode commandConfigurationNode = SimpleConfigurationNode.root().setValue(ttlcd, lcd);
configurationLoader.save(commandConfigurationNode);
// Markdown
new MarkdownGenerator.CommandMarkdownGenerator().create(plugin.getDataPath().resolve("commands.md"), lcd);
// Generate permission file.
YAMLConfigurationLoader permissionsConfigurationLoader = YAMLConfigurationLoader.builder().setPath(plugin.getDataPath().resolve("permissions.yml")).setFlowStyle(DumperOptions.FlowStyle.BLOCK).build();
List<PermissionDoc> lpd = getAndSort(Lists.newArrayList(genCache.getPermissionDocs()), (first, second) -> {
int m = first.getModule().compareToIgnoreCase(second.getModule());
if (m == 0) {
return first.getPermission().compareToIgnoreCase(second.getPermission());
}
return m;
});
ConfigurationNode permissionConfigurationNode = SimpleConfigurationNode.root().setValue(ttlpd, lpd.stream().filter(PermissionDoc::isNormal).collect(Collectors.toList()));
permissionsConfigurationLoader.save(permissionConfigurationNode);
// Markdown
new MarkdownGenerator.PermissionMarkdownGenerator().create(plugin.getDataPath().resolve("permissions.md"), lpd.stream().filter(PermissionDoc::isOre).collect(Collectors.toList()));
YAMLConfigurationLoader tokenConfigurationLoader = YAMLConfigurationLoader.builder().setPath(plugin.getDataPath().resolve("tokens.yml")).setFlowStyle(DumperOptions.FlowStyle.BLOCK).build();
ConfigurationNode tokenConfigurationNode = SimpleConfigurationNode.root().setValue(ttltd, getAndSort(genCache.getTokenDocs(), Comparator.comparing(TokenDoc::getName)));
tokenConfigurationLoader.save(tokenConfigurationNode);
YAMLConfigurationLoader essentialsConfigurationLoader = YAMLConfigurationLoader.builder().setPath(plugin.getDataPath().resolve("ess.yml")).setFlowStyle(DumperOptions.FlowStyle.BLOCK).build();
ConfigurationNode essentialsConfigurationNode = SimpleConfigurationNode.root().setValue(tted, getAndSort(genCache.getEssentialsDocs(), Comparator.comparing(x -> x.getEssentialsCommands().get(0))));
essentialsConfigurationLoader.save(essentialsConfigurationNode);
YAMLConfigurationLoader configurationConfigurationLoader = YAMLConfigurationLoader.builder().setPath(plugin.getDataPath().resolve("conf.yml")).setFlowStyle(DumperOptions.FlowStyle.BLOCK).build();
ConfigurationNode configurationConfigurationNode = SimpleConfigurationNode.root().setValue(genCache.getConfigDocs());
configurationConfigurationLoader.save(configurationConfigurationNode);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.docgen.complete"));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.docgen.DocGenCache 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