Sort the output of the help command alphabetically.
This commit is contained in:
parent
984069ff35
commit
f3a87516d6
@ -1,6 +1,8 @@
|
|||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -10,6 +12,42 @@ import de.craftinc.gates.util.TextUtil;
|
|||||||
|
|
||||||
public class CommandHelp extends BaseCommand
|
public class CommandHelp extends BaseCommand
|
||||||
{
|
{
|
||||||
|
public static List<List<String>> helpPages;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
// sort the usage strings
|
||||||
|
List<String> allUsageStrings = new ArrayList<String>();
|
||||||
|
|
||||||
|
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<List<String>>();
|
||||||
|
|
||||||
|
while (!allUsageStrings.isEmpty())
|
||||||
|
{
|
||||||
|
int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size();
|
||||||
|
List<String> currentHelpPage = new ArrayList<String>(allUsageStrings.subList(0, toIndex));
|
||||||
|
helpPages.add(currentHelpPage);
|
||||||
|
|
||||||
|
allUsageStrings.removeAll(currentHelpPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public CommandHelp()
|
public CommandHelp()
|
||||||
{
|
{
|
||||||
@ -62,40 +100,5 @@ public class CommandHelp extends BaseCommand
|
|||||||
|
|
||||||
sendMessage(helpPages.get(page));
|
sendMessage(helpPages.get(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------//
|
|
||||||
// Build the help pages
|
|
||||||
//----------------------------------------------//
|
|
||||||
|
|
||||||
public static ArrayList<ArrayList<String>> helpPages;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
helpPages = new ArrayList<ArrayList<String>>();
|
|
||||||
ArrayList<String> pageLines;
|
|
||||||
|
|
||||||
pageLines = new ArrayList<String>();
|
|
||||||
|
|
||||||
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<String>();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user