From f3a87516d68894a1ea3da24df34346780b883898 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Tue, 19 Feb 2013 12:27:46 +0100 Subject: [PATCH] Sort the output of the help command alphabetically. --- .../craftinc/gates/commands/CommandHelp.java | 73 ++++++++++--------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/src/de/craftinc/gates/commands/CommandHelp.java b/src/de/craftinc/gates/commands/CommandHelp.java index 0d852c8..d33c519 100644 --- a/src/de/craftinc/gates/commands/CommandHelp.java +++ b/src/de/craftinc/gates/commands/CommandHelp.java @@ -1,6 +1,8 @@ package de.craftinc.gates.commands; import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import org.bukkit.command.CommandSender; @@ -10,6 +12,42 @@ import de.craftinc.gates.util.TextUtil; public class CommandHelp extends BaseCommand { + public static List> helpPages; + + static + { + // sort the usage strings + List allUsageStrings = new ArrayList(); + + allUsageStrings.add( new CommandHelp().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandCreate().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandDelete().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandSetLocation().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandSetExit().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandOpen().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandRename().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandClose().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandList().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandInfo().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandSetHidden().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandSetVisible().getUsageTemplate(true, true) ); + + Collections.sort(allUsageStrings); + + + // put 5 commands on one page + helpPages = new ArrayList>(); + + while (!allUsageStrings.isEmpty()) + { + int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size(); + List currentHelpPage = new ArrayList(allUsageStrings.subList(0, toIndex)); + helpPages.add(currentHelpPage); + + allUsageStrings.removeAll(currentHelpPage); + } + } + public CommandHelp() { @@ -62,40 +100,5 @@ public class CommandHelp extends BaseCommand sendMessage(helpPages.get(page)); } - - - //----------------------------------------------// - // Build the help pages - //----------------------------------------------// - - public static ArrayList> helpPages; - - static - { - helpPages = new ArrayList>(); - ArrayList pageLines; - - pageLines = new ArrayList(); - - pageLines.add( new CommandHelp().getUsageTemplate(true, true) ); - pageLines.add( new CommandCreate().getUsageTemplate(true, true) ); - pageLines.add( new CommandDelete().getUsageTemplate(true, true) ); - pageLines.add( new CommandSetLocation().getUsageTemplate(true, true) ); - pageLines.add( new CommandSetExit().getUsageTemplate(true, true) ); - pageLines.add( new CommandOpen().getUsageTemplate(true, true) ); - - helpPages.add(pageLines); - pageLines = new ArrayList(); - - pageLines.add( new CommandRename().getUsageTemplate(true, true) ); - pageLines.add( new CommandClose().getUsageTemplate(true, true) ); - pageLines.add( new CommandList().getUsageTemplate(true, true) ); - pageLines.add( new CommandInfo().getUsageTemplate(true, true) ); - pageLines.add( new CommandSetHidden().getUsageTemplate(true, true) ); - pageLines.add( new CommandSetVisible().getUsageTemplate(true, true) ); - - helpPages.add(pageLines); - } - }