Search in sources :

Example 1 with EssentialsEquivalent

use of io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent in project Nucleus by NucleusPowered.

the class DocGenCache method addCommand.

public void addCommand(final String moduleID, final AbstractCommand<?> abstractCommand) {
    if (abstractCommand.getClass().isAnnotationPresent(NoDocumentation.class)) {
        return;
    }
    CommandDoc cmd = new CommandDoc();
    String cmdPath = abstractCommand.getCommandPath().replaceAll("\\.", " ");
    cmd.setCommandName(cmdPath);
    cmd.setAliases(String.join(", ", Lists.newArrayList(abstractCommand.getAliases())));
    if (abstractCommand.getRootCommandAliases().length > 0) {
        cmd.setRootAliases(String.join(", ", Arrays.asList(abstractCommand.getRootCommandAliases())));
    }
    cmd.setPermissionbase(abstractCommand.getPermissionHandler().getBase());
    Class<? extends AbstractCommand> cac = abstractCommand.getClass();
    Permissions s = cac.getAnnotation(Permissions.class);
    if (s == null) {
        cmd.setDefaultLevel(cac.isAnnotationPresent(NoPermissions.class) ? SuggestedLevel.USER.name() : SuggestedLevel.ADMIN.name());
    } else {
        cmd.setDefaultLevel(s.suggestedLevel().name());
    }
    cmd.setModule(moduleID);
    if (!cac.isAnnotationPresent(NoModifiers.class)) {
        cmd.setCooldown(!cac.isAnnotationPresent(NoCooldown.class));
        cmd.setCost(!cac.isAnnotationPresent(NoCost.class));
        cmd.setWarmup(!cac.isAnnotationPresent(NoWarmup.class));
    }
    cmd.setSince(cac.getAnnotation(Since.class));
    String desc = abstractCommand.getDescription();
    if (!desc.contains(" ")) {
        logger.warn("Cannot generate description for: " + abstractCommand.getCommandPath() + ": " + desc);
    }
    cmd.setOneLineDescription(desc);
    String extendedDescription = abstractCommand.getExtendedDescription().replace("\n", "|br|").replace("\"", "&quot;");
    if (!extendedDescription.isEmpty()) {
        cmd.setExtendedDescription(extendedDescription);
    }
    List<PermissionDoc> lp = new ArrayList<>();
    abstractCommand.getPermissionHandler().getSuggestedPermissions().forEach((k, v) -> lp.add(addPermissionDocs(moduleID, k, v)));
    cmd.setPermissions(lp);
    cmd.setUsageString(abstractCommand.getUsageString(Sponge.getServer().getConsole()));
    cmd.setSubcommands(abstractCommand.getChildrenUsage(Sponge.getServer().getConsole()).map(Text::toPlain).orElse(""));
    cmd.setSimpleUsage(abstractCommand.getSimpleUsage(Sponge.getServer().getConsole()));
    // Essentials
    EssentialsEquivalent ee = abstractCommand.getClass().getAnnotation(EssentialsEquivalent.class);
    if (ee != null) {
        List<String> ss = Arrays.asList(ee.value());
        cmd.setEssentialsEquivalents(ss);
        cmd.setEssNotes(ee.notes());
        cmd.setExactEssEquiv(ee.isExact());
        EssentialsDoc doc = new EssentialsDoc();
        doc.setEssentialsCommands(ss);
        int i = cmdPath.lastIndexOf(" ");
        String c;
        if (i > -1) {
            c = cmdPath.substring(0, i) + " ";
        } else {
            c = "";
        }
        List<String> a = Lists.newArrayList(abstractCommand.getAliases()).stream().map(x -> c + x).collect(Collectors.toList());
        if (abstractCommand.getRootCommandAliases().length > 0) {
            a.addAll(Arrays.asList(abstractCommand.getRootCommandAliases()));
        }
        doc.setNucleusEquiv(a);
        doc.setExact(ee.isExact());
        doc.setNotes(ee.notes());
        essentialsDocs.add(doc);
    }
    commandDocs.add(cmd);
}
Also used : ConfigurationOptions(ninja.leaping.configurate.ConfigurationOptions) Arrays(java.util.Arrays) NoCost(io.github.nucleuspowered.nucleus.internal.annotations.command.NoCost) NoPermissions(io.github.nucleuspowered.nucleus.internal.annotations.command.NoPermissions) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) Since(io.github.nucleuspowered.nucleus.internal.annotations.Since) TypeToken(com.google.common.reflect.TypeToken) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Text(org.spongepowered.api.text.Text) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) NucleusConfigAdapter(io.github.nucleuspowered.nucleus.internal.qsml.NucleusConfigAdapter) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) AbstractConfigAdapter(uk.co.drnaylor.quickstart.config.AbstractConfigAdapter) NoCooldown(io.github.nucleuspowered.nucleus.internal.annotations.command.NoCooldown) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) Collection(java.util.Collection) NoDocumentation(io.github.nucleuspowered.nucleus.internal.annotations.command.NoDocumentation) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) NoWarmup(io.github.nucleuspowered.nucleus.internal.annotations.command.NoWarmup) ConfigurableModule(io.github.nucleuspowered.nucleus.internal.qsml.module.ConfigurableModule) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) EssentialsEquivalent(io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent) ConfigurateHelper(io.github.nucleuspowered.nucleus.configurate.ConfigurateHelper) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) EssentialsEquivalent(io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent) NoPermissions(io.github.nucleuspowered.nucleus.internal.annotations.command.NoPermissions) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) Since(io.github.nucleuspowered.nucleus.internal.annotations.Since)

Aggregations

Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 TypeToken (com.google.common.reflect.TypeToken)1 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 ConfigurateHelper (io.github.nucleuspowered.nucleus.configurate.ConfigurateHelper)1 Since (io.github.nucleuspowered.nucleus.internal.annotations.Since)1 NoCooldown (io.github.nucleuspowered.nucleus.internal.annotations.command.NoCooldown)1 NoCost (io.github.nucleuspowered.nucleus.internal.annotations.command.NoCost)1 NoDocumentation (io.github.nucleuspowered.nucleus.internal.annotations.command.NoDocumentation)1 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)1 NoPermissions (io.github.nucleuspowered.nucleus.internal.annotations.command.NoPermissions)1 NoWarmup (io.github.nucleuspowered.nucleus.internal.annotations.command.NoWarmup)1 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)1 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)1 EssentialsEquivalent (io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent)1 PermissionInformation (io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation)1 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)1 NucleusConfigAdapter (io.github.nucleuspowered.nucleus.internal.qsml.NucleusConfigAdapter)1 ConfigurableModule (io.github.nucleuspowered.nucleus.internal.qsml.module.ConfigurableModule)1 BufferedWriter (java.io.BufferedWriter)1