From b2a53bb921c4303cf3c1a845112eecd621dcf500 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Sun, 23 Aug 2015 21:50:37 +0800 Subject: [PATCH] fix reinstall unregister... Signed-off-by: j502647092 --- .../Yum/commands/CommandHandler.java | 123 +++++++++--------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandHandler.java b/src/main/java/cn/citycraft/Yum/commands/CommandHandler.java index 2c7f99f..85d745b 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandHandler.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandHandler.java @@ -1,5 +1,5 @@ /** - * + * */ package cn.citycraft.Yum.commands; @@ -20,27 +20,60 @@ import cn.citycraft.Yum.utils.PluginsManager; /** * 子命令处理类 - * - * @author 蒋天蓓 - * 2015年8月22日上午8:29:44 + * + * @author 蒋天蓓 2015年8月22日上午8:29:44 */ public class CommandHandler implements CommandExecutor, TabCompleter { + /** + * 转移数组 + * + * @param args + * - 原数组 + * @param start + * - 数组开始位置 + * @return 转移后的数组字符串 + */ + public static String[] moveStrings(String[] args, int start) { + String[] ret = new String[args.length - start]; + System.arraycopy(args, args.length - start, ret, 0, ret.length); + return ret; + } + /** * 已注册命令列表(包括别名) */ - List RegisterCommandList = new ArrayList(); + List RegisterCommandList = new ArrayList();; /** * 命令监听类列表 */ - private List commandlist = new ArrayList();; + private List commandlist = new ArrayList(); + /** * 插件主类 */ Yum plugin; + /** + * 注册子命令 + * + * @param yum + * - 插件主类 + */ + public CommandHandler(Yum yum) { + this.plugin = yum; + registerCommand(new CommandList(yum)); + registerCommand(new CommandInstall(yum)); + registerCommand(new CommandUpdate(yum)); + registerCommand(new CommandRemove(yum)); + registerCommand(new CommandInfo(yum)); + registerCommand(new CommandReinstall(yum)); + + RegisterCommandList = getRegisterCommands(); + } + /** * 获得已注册的命令列表 - * + * * @return - 返回已注册的命令List */ public List getRegisterCommands() { @@ -51,49 +84,10 @@ public class CommandHandler implements CommandExecutor, TabCompleter { return cmds; } - @Override - public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { - if (sender.isOp() || sender.hasPermission("yum.admin") || sender.hasPermission("yum." + args[0])) { - List completions = new ArrayList<>(); - if (args.length == 1) { - String partialCommand = args[0]; - List commands = RegisterCommandList; - StringUtil.copyPartialMatches(partialCommand, commands, completions); - } - if (args.length == 2) { - String partialPlugin = args[1]; - List plugins = PluginsManager.getPluginNames(false); - StringUtil.copyPartialMatches(partialPlugin, plugins, completions); - } - Collections.sort(completions); - return completions; - } - return null; - } - - /** - * 注册子命令 - * - * @param yum - * - 插件主类 - */ - public CommandHandler(Yum yum) { - this.plugin = yum; - registerCommand(new CommandList(yum)); - registerCommand(new CommandInstall(yum)); - registerCommand(new CommandUpdate(yum)); - registerCommand(new CommandRemove(yum)); - registerCommand(new CommandInfo(yum)); - - RegisterCommandList = getRegisterCommands(); - } - @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (args.length == 0) { - + if (args.length == 0) return true; - } String subcmd = args[0]; String[] subargs = moveStrings(args, 1); for (BaseCommand command : commandlist) { @@ -121,6 +115,26 @@ public class CommandHandler implements CommandExecutor, TabCompleter { return false; } + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (sender.isOp() || sender.hasPermission("yum.admin") || sender.hasPermission("yum." + args[0])) { + List completions = new ArrayList<>(); + if (args.length == 1) { + String partialCommand = args[0]; + List commands = RegisterCommandList; + StringUtil.copyPartialMatches(partialCommand, commands, completions); + } + if (args.length == 2) { + String partialPlugin = args[1]; + List plugins = PluginsManager.getPluginNames(false); + StringUtil.copyPartialMatches(partialPlugin, plugins, completions); + } + Collections.sort(completions); + return completions; + } + return null; + } + /** * 注册命令 * @@ -131,19 +145,4 @@ public class CommandHandler implements CommandExecutor, TabCompleter { commandlist.add(command); } - /** - * 转移数组 - * - * @param args - * - 原数组 - * @param start - * - 数组开始位置 - * @return 转移后的数组字符串 - */ - public static String[] moveStrings(String[] args, int start) { - String[] ret = new String[args.length - start]; - System.arraycopy(args, args.length - start, ret, 0, ret.length); - return ret; - } - }