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("\"", """);
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);
}
Aggregations