diff options
Diffstat (limited to 'dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SubcommandsHelpTopic.java')
-rw-r--r-- | dicore3/command/src/main/java/io/dico/dicore/command/chat/help/defaults/SubcommandsHelpTopic.java | 30 |
1 files changed, 16 insertions, 14 deletions
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 1e9922f..59912cd 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 @@ -11,29 +11,31 @@ import io.dico.dicore.command.predef.PredefinedCommand; import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permissible; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; public class SubcommandsHelpTopic implements IHelpTopic { @Override - public List<IHelpComponent> getComponents(ICommandAddress target, Permissible viewer, ExecutionContext context) { - List<IHelpComponent> out = new ArrayList<>(); - Map<String, ? extends ICommandAddress> children = target.getChildren(); - if (children.isEmpty()) { - //System.out.println("No subcommands"); - return out; + 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(); - children.values().stream().distinct().forEach(child -> { - if ((!child.hasCommand() || child.getCommand().isVisibleTo(sender)) && !(child instanceof PredefinedCommand)) { - out.add(getComponent(child, viewer, context)); + 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 out; + return result; } public IHelpComponent getComponent(ICommandAddress child, Permissible viewer, ExecutionContext context) { |