Search in sources :

Example 1 with PermissionDoc

use of io.github.nucleuspowered.nucleus.internal.docgen.PermissionDoc 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();
}
Also used : DocGenCache(io.github.nucleuspowered.nucleus.internal.docgen.DocGenCache) TokenDoc(io.github.nucleuspowered.nucleus.internal.docgen.TokenDoc) MarkdownGenerator(io.github.nucleuspowered.nucleus.internal.docgen.generators.MarkdownGenerator) CommandDoc(io.github.nucleuspowered.nucleus.internal.docgen.CommandDoc) YAMLConfigurationLoader(ninja.leaping.configurate.yaml.YAMLConfigurationLoader) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) PermissionDoc(io.github.nucleuspowered.nucleus.internal.docgen.PermissionDoc)

Aggregations

CommandDoc (io.github.nucleuspowered.nucleus.internal.docgen.CommandDoc)1 DocGenCache (io.github.nucleuspowered.nucleus.internal.docgen.DocGenCache)1 PermissionDoc (io.github.nucleuspowered.nucleus.internal.docgen.PermissionDoc)1 TokenDoc (io.github.nucleuspowered.nucleus.internal.docgen.TokenDoc)1 MarkdownGenerator (io.github.nucleuspowered.nucleus.internal.docgen.generators.MarkdownGenerator)1 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)1 SimpleConfigurationNode (ninja.leaping.configurate.SimpleConfigurationNode)1 YAMLConfigurationLoader (ninja.leaping.configurate.yaml.YAMLConfigurationLoader)1