Search in sources :

Example 1 with DocGenCache

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();
}
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)

Example 2 with DocGenCache

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);
        }
    });
}
Also used : DocGenCache(io.github.nucleuspowered.nucleus.internal.docgen.DocGenCache) ListenerBase(io.github.nucleuspowered.nucleus.internal.ListenerBase) MissingDependencyException(uk.co.drnaylor.quickstart.exceptions.MissingDependencyException) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)

Aggregations

DocGenCache (io.github.nucleuspowered.nucleus.internal.docgen.DocGenCache)2 ListenerBase (io.github.nucleuspowered.nucleus.internal.ListenerBase)1 CommandDoc (io.github.nucleuspowered.nucleus.internal.docgen.CommandDoc)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 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)1 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)1 SimpleConfigurationNode (ninja.leaping.configurate.SimpleConfigurationNode)1 YAMLConfigurationLoader (ninja.leaping.configurate.yaml.YAMLConfigurationLoader)1 MissingDependencyException (uk.co.drnaylor.quickstart.exceptions.MissingDependencyException)1