diff options
Diffstat (limited to 'dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults')
5 files changed, 351 insertions, 351 deletions
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DefaultPageBuilder.java b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DefaultPageBuilder.java index a584e7e..e06730f 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DefaultPageBuilder.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DefaultPageBuilder.java @@ -1,115 +1,115 @@ -package io.dico.dicore.command.chat.help.defaults; - -import io.dico.dicore.command.ExecutionContext; -import io.dico.dicore.command.ICommandAddress; -import io.dico.dicore.command.chat.help.*; -import org.bukkit.permissions.Permissible; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; - -public class DefaultPageBuilder implements IPageBuilder { - - @Override - public String getPage(List<IHelpTopic> helpTopics, IPageLayout pageLayout, ICommandAddress target, - Permissible viewer, ExecutionContext context, int pageNum, int pageLen) { - if (pageLen <= 0 || pageNum < 0) { - throw new IllegalArgumentException(); - } - - List<IHelpComponent> components = new LinkedList<>(); - for (IHelpTopic topic : helpTopics) { - components.addAll(topic.getComponents(target, viewer, context, true)); - } - - PageBorders pageBorders = null; - int componentStartIdx = -1; - int componentEndIdx = -1; - int totalPageCount = 0; - int curPageLines = 0; - - ListIterator<IHelpComponent> iterator = components.listIterator(); - - while (iterator.hasNext()) { - if (curPageLines == 0) { - - if (pageBorders != null) { - iterator.add(pageBorders.getFooter()); - } - - if (pageNum == totalPageCount) { - componentStartIdx = iterator.nextIndex(); - } else if (pageNum + 1 == totalPageCount) { - componentEndIdx = iterator.nextIndex(); - } - - pageBorders = pageLayout.getPageBorders(target, viewer, context, totalPageCount + 1); - - if (pageBorders != null) { - iterator.add(pageBorders.getHeader()); - iterator.previous(); - - curPageLines += pageBorders.getFooter().lineCount(); - } - - totalPageCount++; - } - - IHelpComponent component = iterator.next(); - int lineCount = component.lineCount(); - curPageLines += lineCount; - - if (curPageLines >= pageLen) { - curPageLines = 0; - } - } - - if (componentStartIdx == -1) { - // page does not exist - return ""; - } - - if (componentEndIdx == -1) { - componentEndIdx = components.size(); - } - - StringBuilder sb = new StringBuilder(); - iterator = components.listIterator(componentStartIdx); - int count = componentEndIdx - componentStartIdx; - boolean first = true; - - while (count-- > 0) { - IHelpComponent component = iterator.next(); - if (component instanceof IPageBorder) { - ((IPageBorder) component).setPageCount(totalPageCount); - } - if (first) { - first = false; - } else { - sb.append('\n'); - } - component.appendTo(sb); - - } - - return sb.toString(); - } - - public static String combine(List<IHelpComponent> components) { - StringBuilder rv = new StringBuilder(); - - Iterator<IHelpComponent> iterator = components.iterator(); - if (iterator.hasNext()) { - iterator.next().appendTo(rv); - } - while (iterator.hasNext()) { - rv.append('\n'); - iterator.next().appendTo(rv); - } - - return rv.toString(); - } - -} +package io.dico.dicore.command.chat.help.defaults;
+
+import io.dico.dicore.command.ExecutionContext;
+import io.dico.dicore.command.ICommandAddress;
+import io.dico.dicore.command.chat.help.*;
+import org.bukkit.permissions.Permissible;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+public class DefaultPageBuilder implements IPageBuilder {
+
+ @Override
+ public String getPage(List<IHelpTopic> helpTopics, IPageLayout pageLayout, ICommandAddress target,
+ Permissible viewer, ExecutionContext context, int pageNum, int pageLen) {
+ if (pageLen <= 0 || pageNum < 0) {
+ throw new IllegalArgumentException();
+ }
+
+ List<IHelpComponent> components = new LinkedList<>();
+ for (IHelpTopic topic : helpTopics) {
+ components.addAll(topic.getComponents(target, viewer, context, true));
+ }
+
+ PageBorders pageBorders = null;
+ int componentStartIdx = -1;
+ int componentEndIdx = -1;
+ int totalPageCount = 0;
+ int curPageLines = 0;
+
+ ListIterator<IHelpComponent> iterator = components.listIterator();
+
+ while (iterator.hasNext()) {
+ if (curPageLines == 0) {
+
+ if (pageBorders != null) {
+ iterator.add(pageBorders.getFooter());
+ }
+
+ if (pageNum == totalPageCount) {
+ componentStartIdx = iterator.nextIndex();
+ } else if (pageNum + 1 == totalPageCount) {
+ componentEndIdx = iterator.nextIndex();
+ }
+
+ pageBorders = pageLayout.getPageBorders(target, viewer, context, totalPageCount + 1);
+
+ if (pageBorders != null) {
+ iterator.add(pageBorders.getHeader());
+ iterator.previous();
+
+ curPageLines += pageBorders.getFooter().lineCount();
+ }
+
+ totalPageCount++;
+ }
+
+ IHelpComponent component = iterator.next();
+ int lineCount = component.lineCount();
+ curPageLines += lineCount;
+
+ if (curPageLines >= pageLen) {
+ curPageLines = 0;
+ }
+ }
+
+ if (componentStartIdx == -1) {
+ // page does not exist
+ return "";
+ }
+
+ if (componentEndIdx == -1) {
+ componentEndIdx = components.size();
+ }
+
+ StringBuilder sb = new StringBuilder();
+ iterator = components.listIterator(componentStartIdx);
+ int count = componentEndIdx - componentStartIdx;
+ boolean first = true;
+
+ while (count-- > 0) {
+ IHelpComponent component = iterator.next();
+ if (component instanceof IPageBorder) {
+ ((IPageBorder) component).setPageCount(totalPageCount);
+ }
+ if (first) {
+ first = false;
+ } else {
+ sb.append('\n');
+ }
+ component.appendTo(sb);
+
+ }
+
+ return sb.toString();
+ }
+
+ public static String combine(List<IHelpComponent> components) {
+ StringBuilder rv = new StringBuilder();
+
+ Iterator<IHelpComponent> iterator = components.iterator();
+ if (iterator.hasNext()) {
+ iterator.next().appendTo(rv);
+ }
+ while (iterator.hasNext()) {
+ rv.append('\n');
+ iterator.next().appendTo(rv);
+ }
+
+ return rv.toString();
+ }
+
+}
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DefaultPageLayout.java b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DefaultPageLayout.java index 8d3d004..d950b09 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DefaultPageLayout.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DefaultPageLayout.java @@ -1,40 +1,40 @@ -package io.dico.dicore.command.chat.help.defaults; - -import io.dico.dicore.command.EMessageType; -import io.dico.dicore.command.ExecutionContext; -import io.dico.dicore.command.ICommandAddress; -import io.dico.dicore.command.ModifiableCommandAddress; -import io.dico.dicore.Formatting; -import io.dico.dicore.command.chat.IChatHandler; -import io.dico.dicore.command.chat.help.IPageBorder; -import io.dico.dicore.command.chat.help.IPageLayout; -import io.dico.dicore.command.chat.help.PageBorders; -import org.bukkit.permissions.Permissible; - -public class DefaultPageLayout implements IPageLayout { - - @Override - public PageBorders getPageBorders(ICommandAddress target, Permissible viewer, ExecutionContext context, int pageNum) { - IChatHandler c = context.getAddress().getChatHandler(); - String prefix = c.getMessagePrefixForType(EMessageType.INFORMATIVE); - Formatting informative = c.getChatFormatForType(EMessageType.INFORMATIVE); - Formatting number = c.getChatFormatForType(EMessageType.NEUTRAL); - - String nextPageCommand; - ICommandAddress executor = context.getAddress(); - if (((ModifiableCommandAddress) executor).hasHelpCommand()) { - nextPageCommand = ((ModifiableCommandAddress) executor).getHelpCommand().getAddress() + ' ' + (pageNum + 1); - } else { - nextPageCommand = executor.getAddress() + ' ' + (pageNum + 1); - } - - String header = prefix + informative + "Help page " + number + pageNum + informative + - '/' + number + "%pageCount%" + informative + " for /" + target.getAddress(); - String footer = informative + "Type /" + nextPageCommand + " for the next page"; - - IPageBorder headerBorder = PageBorders.simpleBorder("", header); - IPageBorder footerBorder = PageBorders.disappearingBorder(pageNum, footer); - return new PageBorders(headerBorder, footerBorder); - } - -} +package io.dico.dicore.command.chat.help.defaults;
+
+import io.dico.dicore.command.EMessageType;
+import io.dico.dicore.command.ExecutionContext;
+import io.dico.dicore.command.ICommandAddress;
+import io.dico.dicore.command.ModifiableCommandAddress;
+import io.dico.dicore.Formatting;
+import io.dico.dicore.command.chat.IChatHandler;
+import io.dico.dicore.command.chat.help.IPageBorder;
+import io.dico.dicore.command.chat.help.IPageLayout;
+import io.dico.dicore.command.chat.help.PageBorders;
+import org.bukkit.permissions.Permissible;
+
+public class DefaultPageLayout implements IPageLayout {
+
+ @Override
+ public PageBorders getPageBorders(ICommandAddress target, Permissible viewer, ExecutionContext context, int pageNum) {
+ IChatHandler c = context.getAddress().getChatHandler();
+ String prefix = c.getMessagePrefixForType(EMessageType.INFORMATIVE);
+ Formatting informative = c.getChatFormatForType(EMessageType.INFORMATIVE);
+ Formatting number = c.getChatFormatForType(EMessageType.NEUTRAL);
+
+ String nextPageCommand;
+ ICommandAddress executor = context.getAddress();
+ if (((ModifiableCommandAddress) executor).hasHelpCommand()) {
+ nextPageCommand = ((ModifiableCommandAddress) executor).getHelpCommand().getAddress() + ' ' + (pageNum + 1);
+ } else {
+ nextPageCommand = executor.getAddress() + ' ' + (pageNum + 1);
+ }
+
+ String header = prefix + informative + "Help page " + number + pageNum + informative +
+ '/' + number + "%pageCount%" + informative + " for /" + target.getAddress();
+ String footer = informative + "Type /" + nextPageCommand + " for the next page";
+
+ IPageBorder headerBorder = PageBorders.simpleBorder("", header);
+ IPageBorder footerBorder = PageBorders.disappearingBorder(pageNum, footer);
+ return new PageBorders(headerBorder, footerBorder);
+ }
+
+}
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DescriptionHelpTopic.java b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DescriptionHelpTopic.java index ae88ea2..0899db4 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DescriptionHelpTopic.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/DescriptionHelpTopic.java @@ -1,45 +1,45 @@ -package io.dico.dicore.command.chat.help.defaults; - -import io.dico.dicore.command.Command; -import io.dico.dicore.command.EMessageType; -import io.dico.dicore.command.ExecutionContext; -import io.dico.dicore.command.ICommandAddress; -import io.dico.dicore.Formatting; -import io.dico.dicore.command.chat.help.IHelpComponent; -import io.dico.dicore.command.chat.help.IHelpTopic; -import io.dico.dicore.command.chat.help.SimpleHelpComponent; -import org.bukkit.permissions.Permissible; - -import java.util.ArrayList; -import java.util.List; - -public class DescriptionHelpTopic implements IHelpTopic { - - @Override - public List<IHelpComponent> getComponents(ICommandAddress target, Permissible viewer, ExecutionContext context, boolean isForPage) { - List<IHelpComponent> out = new ArrayList<>(); - Formatting format = context.getFormat(EMessageType.DESCRIPTION); - - if (!target.hasCommand()) { - return out; - } - Command command = target.getCommand(); - String[] description = command.getDescription(); - if (description.length == 0) { - String shortDescription = command.getShortDescription(); - if (shortDescription == null) { - return out; - } - - description = new String[]{shortDescription}; - } - - for (int i = 0; i < description.length; i++) { - description[i] = format + description[i]; - } - - out.add(new SimpleHelpComponent(description)); - return out; - } - -} +package io.dico.dicore.command.chat.help.defaults;
+
+import io.dico.dicore.command.Command;
+import io.dico.dicore.command.EMessageType;
+import io.dico.dicore.command.ExecutionContext;
+import io.dico.dicore.command.ICommandAddress;
+import io.dico.dicore.Formatting;
+import io.dico.dicore.command.chat.help.IHelpComponent;
+import io.dico.dicore.command.chat.help.IHelpTopic;
+import io.dico.dicore.command.chat.help.SimpleHelpComponent;
+import org.bukkit.permissions.Permissible;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DescriptionHelpTopic implements IHelpTopic {
+
+ @Override
+ public List<IHelpComponent> getComponents(ICommandAddress target, Permissible viewer, ExecutionContext context, boolean isForPage) {
+ List<IHelpComponent> out = new ArrayList<>();
+ Formatting format = context.getFormat(EMessageType.DESCRIPTION);
+
+ if (!target.hasCommand()) {
+ return out;
+ }
+ Command command = target.getCommand();
+ String[] description = command.getDescription();
+ if (description.length == 0) {
+ String shortDescription = command.getShortDescription();
+ if (shortDescription == null) {
+ return out;
+ }
+
+ description = new String[]{shortDescription};
+ }
+
+ for (int i = 0; i < description.length; i++) {
+ description[i] = format + description[i];
+ }
+
+ out.add(new SimpleHelpComponent(description));
+ return out;
+ }
+
+}
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SubcommandsHelpTopic.java b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SubcommandsHelpTopic.java index 0e680ae..b302769 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SubcommandsHelpTopic.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SubcommandsHelpTopic.java @@ -1,59 +1,59 @@ -package io.dico.dicore.command.chat.help.defaults; - -import io.dico.dicore.command.EMessageType; -import io.dico.dicore.command.ExecutionContext; -import io.dico.dicore.command.ICommandAddress; -import io.dico.dicore.Formatting; -import io.dico.dicore.command.chat.help.IHelpComponent; -import io.dico.dicore.command.chat.help.IHelpTopic; -import io.dico.dicore.command.chat.help.SimpleHelpComponent; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permissible; - -import java.util.*; - -public class SubcommandsHelpTopic implements IHelpTopic { - - @Override - public List<IHelpComponent> getComponents(ICommandAddress target, Permissible viewer, ExecutionContext context, boolean isForPage) { - Collection<String> mainKeys = target.getChildrenMainKeys(); - if (mainKeys.isEmpty()) { - return Collections.emptyList(); - } - - List<IHelpComponent> result = new ArrayList<>(); - - mainKeys = new ArrayList<>(target.getChildrenMainKeys()); - ((ArrayList<String>) mainKeys).sort(null); - - CommandSender sender = viewer instanceof CommandSender ? (CommandSender) viewer : context.getSender(); - for (String key : mainKeys) { - ICommandAddress child = target.getChild(key); - if ((child.hasChildren() || child.hasUserDeclaredCommand()) && child.getCommand().isVisibleTo(sender)) { - result.add(getComponent(child, viewer, context)); - } - } - - return result; - } - - public IHelpComponent getComponent(ICommandAddress child, Permissible viewer, ExecutionContext context) { - Formatting subcommand = colorOf(context, EMessageType.SUBCOMMAND); - Formatting highlight = colorOf(context, EMessageType.HIGHLIGHT); - - String address = subcommand + "/" + child.getParent().getAddress() + ' ' + highlight + child.getMainKey(); - - String description = child.hasCommand() ? child.getCommand().getShortDescription() : null; - if (description != null) { - Formatting descriptionFormat = colorOf(context, EMessageType.DESCRIPTION); - return new SimpleHelpComponent(address, descriptionFormat + description); - } - - return new SimpleHelpComponent(address); - } - - private static Formatting colorOf(ExecutionContext context, EMessageType type) { - return context.getAddress().getChatHandler().getChatFormatForType(type); - } - -} +package io.dico.dicore.command.chat.help.defaults;
+
+import io.dico.dicore.command.EMessageType;
+import io.dico.dicore.command.ExecutionContext;
+import io.dico.dicore.command.ICommandAddress;
+import io.dico.dicore.Formatting;
+import io.dico.dicore.command.chat.help.IHelpComponent;
+import io.dico.dicore.command.chat.help.IHelpTopic;
+import io.dico.dicore.command.chat.help.SimpleHelpComponent;
+import org.bukkit.command.CommandSender;
+import org.bukkit.permissions.Permissible;
+
+import java.util.*;
+
+public class SubcommandsHelpTopic implements IHelpTopic {
+
+ @Override
+ public List<IHelpComponent> getComponents(ICommandAddress target, Permissible viewer, ExecutionContext context, boolean isForPage) {
+ Collection<String> mainKeys = target.getChildrenMainKeys();
+ if (mainKeys.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ List<IHelpComponent> result = new ArrayList<>();
+
+ mainKeys = new ArrayList<>(target.getChildrenMainKeys());
+ ((ArrayList<String>) mainKeys).sort(null);
+
+ CommandSender sender = viewer instanceof CommandSender ? (CommandSender) viewer : context.getSender();
+ for (String key : mainKeys) {
+ ICommandAddress child = target.getChild(key);
+ if ((child.hasChildren() || child.hasUserDeclaredCommand()) && child.getCommand().isVisibleTo(sender)) {
+ result.add(getComponent(child, viewer, context));
+ }
+ }
+
+ return result;
+ }
+
+ public IHelpComponent getComponent(ICommandAddress child, Permissible viewer, ExecutionContext context) {
+ Formatting subcommand = colorOf(context, EMessageType.SUBCOMMAND);
+ Formatting highlight = colorOf(context, EMessageType.HIGHLIGHT);
+
+ String address = subcommand + "/" + child.getParent().getAddress() + ' ' + highlight + child.getMainKey();
+
+ String description = child.hasCommand() ? child.getCommand().getShortDescription() : null;
+ if (description != null) {
+ Formatting descriptionFormat = colorOf(context, EMessageType.DESCRIPTION);
+ return new SimpleHelpComponent(address, descriptionFormat + description);
+ }
+
+ return new SimpleHelpComponent(address);
+ }
+
+ private static Formatting colorOf(ExecutionContext context, EMessageType type) {
+ return context.getAddress().getChatHandler().getChatFormatForType(type);
+ }
+
+}
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SyntaxHelpTopic.java b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SyntaxHelpTopic.java index d0e3ebe..f0f820f 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SyntaxHelpTopic.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SyntaxHelpTopic.java @@ -1,92 +1,92 @@ -package io.dico.dicore.command.chat.help.defaults; - -import io.dico.dicore.command.Command; -import io.dico.dicore.command.EMessageType; -import io.dico.dicore.command.ExecutionContext; -import io.dico.dicore.command.ICommandAddress; -import io.dico.dicore.Formatting; -import io.dico.dicore.command.chat.help.IHelpComponent; -import io.dico.dicore.command.chat.help.IHelpTopic; -import io.dico.dicore.command.chat.help.SimpleHelpComponent; -import io.dico.dicore.command.parameter.Parameter; -import io.dico.dicore.command.parameter.ParameterList; -import org.bukkit.permissions.Permissible; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public class SyntaxHelpTopic implements IHelpTopic { - - @Override - public List<IHelpComponent> getComponents(ICommandAddress target, Permissible viewer, ExecutionContext context, boolean isForPage) { - if (!target.hasCommand()) { - return Collections.emptyList(); - } - - if (target.hasChildren()) { - if (!isForPage) { - // HelpPages will send help instead of syntax, which might in turn include syntax as well. - return Collections.emptyList(); - } - - if (!target.hasUserDeclaredCommand() && !target.getCommand().getParameterList().hasAnyParameters()) { - // no point adding syntax at all - return Collections.emptyList(); - } - } - - StringBuilder line = new StringBuilder(); - if (isForPage) - line.append(context.getFormat(EMessageType.SYNTAX)) - .append("Syntax: "); - - line.append('/') - .append(context.getFormat(EMessageType.INSTRUCTION)) - .append(target.getAddress()) - .append(' '); - - addShortSyntax(line, target, context); - - return Collections.singletonList(new SimpleHelpComponent(line.toString())); - } - - private static void addShortSyntax(StringBuilder builder, ICommandAddress address, ExecutionContext ctx) { - if (address.hasCommand()) { - Formatting syntaxColor = ctx.getFormat(EMessageType.SYNTAX); - Formatting highlight = ctx.getFormat(EMessageType.HIGHLIGHT); - builder.append(syntaxColor); - - Command command = address.getCommand(); - ParameterList list = command.getParameterList(); - Parameter<?, ?> repeated = list.getRepeatedParameter(); - - int requiredCount = list.getRequiredCount(); - List<Parameter<?, ?>> indexedParameters = list.getIndexedParameters(); - for (int i = 0, n = indexedParameters.size(); i < n; i++) { - builder.append(i < requiredCount ? " <" : " ["); - Parameter<?, ?> param = indexedParameters.get(i); - builder.append(param.getName()); - if (param == repeated) { - builder.append(highlight).append("...").append(syntaxColor); - } - builder.append(i < requiredCount ? '>' : ']'); - } - - Map<String, Parameter<?, ?>> parametersByName = list.getParametersByName(); - for (Parameter<?, ?> param : parametersByName.values()) { - if (param.isFlag()) { - builder.append(" [").append(param.getName()); - if (param.expectsInput()) { - builder.append(" <").append(param.getName()).append(">"); - } - builder.append(']'); - } - } - - } else { - builder.append(' '); - } - } - -} +package io.dico.dicore.command.chat.help.defaults;
+
+import io.dico.dicore.command.Command;
+import io.dico.dicore.command.EMessageType;
+import io.dico.dicore.command.ExecutionContext;
+import io.dico.dicore.command.ICommandAddress;
+import io.dico.dicore.Formatting;
+import io.dico.dicore.command.chat.help.IHelpComponent;
+import io.dico.dicore.command.chat.help.IHelpTopic;
+import io.dico.dicore.command.chat.help.SimpleHelpComponent;
+import io.dico.dicore.command.parameter.Parameter;
+import io.dico.dicore.command.parameter.ParameterList;
+import org.bukkit.permissions.Permissible;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class SyntaxHelpTopic implements IHelpTopic {
+
+ @Override
+ public List<IHelpComponent> getComponents(ICommandAddress target, Permissible viewer, ExecutionContext context, boolean isForPage) {
+ if (!target.hasCommand()) {
+ return Collections.emptyList();
+ }
+
+ if (target.hasChildren()) {
+ if (!isForPage) {
+ // HelpPages will send help instead of syntax, which might in turn include syntax as well.
+ return Collections.emptyList();
+ }
+
+ if (!target.hasUserDeclaredCommand() && !target.getCommand().getParameterList().hasAnyParameters()) {
+ // no point adding syntax at all
+ return Collections.emptyList();
+ }
+ }
+
+ StringBuilder line = new StringBuilder();
+ if (isForPage)
+ line.append(context.getFormat(EMessageType.SYNTAX))
+ .append("Syntax: ");
+
+ line.append('/')
+ .append(context.getFormat(EMessageType.INSTRUCTION))
+ .append(target.getAddress())
+ .append(' ');
+
+ addShortSyntax(line, target, context);
+
+ return Collections.singletonList(new SimpleHelpComponent(line.toString()));
+ }
+
+ private static void addShortSyntax(StringBuilder builder, ICommandAddress address, ExecutionContext ctx) {
+ if (address.hasCommand()) {
+ Formatting syntaxColor = ctx.getFormat(EMessageType.SYNTAX);
+ Formatting highlight = ctx.getFormat(EMessageType.HIGHLIGHT);
+ builder.append(syntaxColor);
+
+ Command command = address.getCommand();
+ ParameterList list = command.getParameterList();
+ Parameter<?, ?> repeated = list.getRepeatedParameter();
+
+ int requiredCount = list.getRequiredCount();
+ List<Parameter<?, ?>> indexedParameters = list.getIndexedParameters();
+ for (int i = 0, n = indexedParameters.size(); i < n; i++) {
+ builder.append(i < requiredCount ? " <" : " [");
+ Parameter<?, ?> param = indexedParameters.get(i);
+ builder.append(param.getName());
+ if (param == repeated) {
+ builder.append(highlight).append("...").append(syntaxColor);
+ }
+ builder.append(i < requiredCount ? '>' : ']');
+ }
+
+ Map<String, Parameter<?, ?>> parametersByName = list.getParametersByName();
+ for (Parameter<?, ?> param : parametersByName.values()) {
+ if (param.isFlag()) {
+ builder.append(" [").append(param.getName());
+ if (param.expectsInput()) {
+ builder.append(" <").append(param.getName()).append(">");
+ }
+ builder.append(']');
+ }
+ }
+
+ } else {
+ builder.append(' ');
+ }
+ }
+
+}
|