From 7c2f6f0bcc0f864decbeac4132a4a5139c19d796 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 30 Jun 2014 23:22:04 -0700 Subject: [PATCH] Sort commands for Dispatchers in CommandUsageBox. --- .../util/formatting/components/CommandUsageBox.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/util/formatting/components/CommandUsageBox.java b/src/main/java/com/sk89q/worldedit/util/formatting/components/CommandUsageBox.java index a4470c010..b8fa617a3 100644 --- a/src/main/java/com/sk89q/worldedit/util/formatting/components/CommandUsageBox.java +++ b/src/main/java/com/sk89q/worldedit/util/formatting/components/CommandUsageBox.java @@ -20,14 +20,18 @@ package com.sk89q.worldedit.util.formatting.components; import com.sk89q.minecraft.util.commands.CommandLocals; +import com.sk89q.worldedit.extension.platform.CommandManager; import com.sk89q.worldedit.util.command.CommandCallable; import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Description; import com.sk89q.worldedit.util.command.Dispatcher; -import com.sk89q.worldedit.util.formatting.Style; +import com.sk89q.worldedit.util.command.PrimaryAliasComparator; import com.sk89q.worldedit.util.formatting.StyledFragment; import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import static com.google.common.base.Preconditions.checkNotNull; @@ -66,7 +70,11 @@ public class CommandUsageBox extends StyledFragment { private void attachDispatcherUsage(Dispatcher dispatcher, String commandString, @Nullable CommandLocals locals) { CommandListBox box = new CommandListBox("Subcommands"); String prefix = !commandString.isEmpty() ? commandString + " " : ""; - for (CommandMapping mapping : dispatcher.getCommands()) { + + List list = new ArrayList(dispatcher.getCommands()); + Collections.sort(list, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); + + for (CommandMapping mapping : list) { if (locals == null || mapping.getCallable().testPermission(locals)) { box.appendCommand(prefix + mapping.getPrimaryAlias(), mapping.getDescription().getShortDescription()); }