From 427a877b176163637c412c249ee6d2dc35446de9 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 1 Aug 2014 19:59:48 +0200 Subject: [PATCH] Add tab completion to "ncp top". --- .../command/admin/top/TopCommand.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/admin/top/TopCommand.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/admin/top/TopCommand.java index 9b4bda79..f78476ff 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/admin/top/TopCommand.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/admin/top/TopCommand.java @@ -22,12 +22,23 @@ import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.ViolationHistory; import fr.neatmonster.nocheatplus.checks.ViolationHistory.VLView; import fr.neatmonster.nocheatplus.command.BaseCommand; +import fr.neatmonster.nocheatplus.command.CommandUtil; import fr.neatmonster.nocheatplus.hooks.APIUtils; import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.utilities.FCFSComparator; public class TopCommand extends BaseCommand{ + private static final String[][] comparatorArgs = new String[][]{ + //{"-player", "-name", "-playername"}, + //{"-check", "-type", "-checktype} + {"-sumvl", "-sum", "-vl"}, + {"-n", "-number", "-num", "-nvl"}, + {"-avgvl", "-avg", "-avl", "-av", "-average", "-averagevl", "-avvl"}, + {"-maxvl", "-max", "-maximum", "-maximumvl"}, + {"-time", "-"}, + }; + protected static class PrimaryThreadWorker implements Runnable{ private final Collection checkTypes; private final CommandSender sender; @@ -197,7 +208,19 @@ public class TopCommand extends BaseCommand{ return true; } - - // TODO: Tab completion (!). + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + String arg = args[args.length - 1]; + if (arg.startsWith("-")) { + while (arg.startsWith("-")) { + arg = arg.substring(1); + } + arg = "-" + arg; + return CommandUtil.getTabMatches(arg.toLowerCase(), comparatorArgs); + } else { + return CommandUtil.getCheckTypeTabMatches(arg); + } + } }