feat: 统一处理Tab补全操作

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-07 10:23:26 +08:00
parent 7985ff3433
commit c86aff521b
4 changed files with 42 additions and 32 deletions

View File

@ -1,6 +1,5 @@
package pw.yumc.Yum.commands; package pw.yumc.Yum.commands;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -19,13 +18,10 @@ import org.bukkit.scheduler.BukkitTask;
import cn.citycraft.PluginHelper.commands.HandlerCommand; import cn.citycraft.PluginHelper.commands.HandlerCommand;
import cn.citycraft.PluginHelper.commands.HandlerCommands; import cn.citycraft.PluginHelper.commands.HandlerCommands;
import cn.citycraft.PluginHelper.commands.HandlerTabComplete;
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent; import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
import cn.citycraft.PluginHelper.commands.InvokeSubCommand; import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
import cn.citycraft.PluginHelper.ext.kit.Reflect; import cn.citycraft.PluginHelper.ext.kit.Reflect;
import cn.citycraft.PluginHelper.utils.StrKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.Yum.api.YumAPI;
import pw.yumc.Yum.inject.CommandInjector; import pw.yumc.Yum.inject.CommandInjector;
import pw.yumc.Yum.inject.TaskInjector; import pw.yumc.Yum.inject.TaskInjector;
@ -42,6 +38,7 @@ public class MonitorCommand implements HandlerCommands {
final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "monitor"); final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "monitor");
cmdhandler.setAllCommandOnlyConsole(yum.getConfig().getBoolean("onlyFileCommandConsole", true)); cmdhandler.setAllCommandOnlyConsole(yum.getConfig().getBoolean("onlyFileCommandConsole", true));
cmdhandler.registerCommands(this); cmdhandler.registerCommands(this);
cmdhandler.registerCommands(PluginTabComplete.instence);
} }
@HandlerCommand(name = "a") @HandlerCommand(name = "a")
@ -91,13 +88,7 @@ public class MonitorCommand implements HandlerCommands {
} }
} }
@HandlerTabComplete() @HandlerCommand(name = "task", minimumArguments = 1, possibleArguments = "插件名称")
public List<String> listtab(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
return StrKit.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>());
}
@HandlerCommand(name = "task")
public void task(final InvokeCommandEvent e) { public void task(final InvokeCommandEvent e) {
final String pname = e.getArgs()[0]; final String pname = e.getArgs()[0];
final CommandSender sender = e.getSender(); final CommandSender sender = e.getSender();

View File

@ -12,6 +12,7 @@ public class NetCommand implements HandlerCommands {
final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "net"); final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "net");
cmdhandler.setAllCommandOnlyConsole(yum.getConfig().getBoolean("onlyNetCommandConsole", false)); cmdhandler.setAllCommandOnlyConsole(yum.getConfig().getBoolean("onlyNetCommandConsole", false));
cmdhandler.registerCommands(this); cmdhandler.registerCommands(this);
cmdhandler.registerCommands(PluginTabComplete.instence);
} }
@HandlerCommand(name = "list", aliases = "l", permission = "", description = "列出联网的插件") @HandlerCommand(name = "list", aliases = "l", permission = "", description = "列出联网的插件")

View File

@ -0,0 +1,38 @@
package pw.yumc.Yum.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import cn.citycraft.PluginHelper.commands.HandlerCommands;
import cn.citycraft.PluginHelper.commands.HandlerTabComplete;
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
import cn.citycraft.PluginHelper.utils.StrKit;
import pw.yumc.Yum.api.YumAPI;
/**
*
* @since 2016年7月7日 上午8:36:47
* @author
*/
public class PluginTabComplete implements HandlerCommands {
public static PluginTabComplete instence = new PluginTabComplete();
@HandlerTabComplete()
public List<String> listtab(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
if (args[0].equalsIgnoreCase("install") || args[0].equalsIgnoreCase("i")) {
return StrKit.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList<String>());
} else if (args[0].equalsIgnoreCase("repo")) {
if (args.length == 2) {
return StrKit.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "delall", "clean", "update", "del" }), new ArrayList<String>());
}
if (args.length == 3 && (args[1] == "add" || args[1] == "del")) {
return StrKit.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>());
}
} else {
return StrKit.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>());
}
return null;
}
}

View File

@ -1,8 +1,6 @@
package pw.yumc.Yum.commands; package pw.yumc.Yum.commands;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -20,7 +18,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.commands.HandlerCommand; import cn.citycraft.PluginHelper.commands.HandlerCommand;
import cn.citycraft.PluginHelper.commands.HandlerCommands; import cn.citycraft.PluginHelper.commands.HandlerCommands;
import cn.citycraft.PluginHelper.commands.HandlerTabComplete;
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent; import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
import cn.citycraft.PluginHelper.commands.InvokeSubCommand; import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
import cn.citycraft.PluginHelper.utils.StrKit; import cn.citycraft.PluginHelper.utils.StrKit;
@ -44,6 +41,7 @@ public class YumCommand implements HandlerCommands, Listener {
final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "yum"); final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "yum");
cmdhandler.setAllCommandOnlyConsole(yum.getConfig().getBoolean("onlyCommandConsole", false)); cmdhandler.setAllCommandOnlyConsole(yum.getConfig().getBoolean("onlyCommandConsole", false));
cmdhandler.registerCommands(this); cmdhandler.registerCommands(this);
cmdhandler.registerCommands(PluginTabComplete.instence);
} }
@HandlerCommand(name = "delete", aliases = { "del" }, minimumArguments = 1, description = "删除插件", possibleArguments = "<插件名称>") @HandlerCommand(name = "delete", aliases = { "del" }, minimumArguments = 1, description = "删除插件", possibleArguments = "<插件名称>")
@ -165,24 +163,6 @@ public class YumCommand implements HandlerCommands, Listener {
} }
} }
@HandlerTabComplete()
public List<String> listtab(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
if (args[0].equalsIgnoreCase("install") || args[0].equalsIgnoreCase("i")) {
return StrKit.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList<String>());
} else if (args[0].equalsIgnoreCase("repo")) {
if (args.length == 2) {
return StrKit.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "delall", "clean", "update", "del" }), new ArrayList<String>());
}
if (args.length == 3 && (args[1] == "add" || args[1] == "del")) {
return StrKit.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>());
}
} else {
return StrKit.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>());
}
return null;
}
@HandlerCommand(name = "load", minimumArguments = 1, description = "载入插件", possibleArguments = "<插件名称>") @HandlerCommand(name = "load", minimumArguments = 1, description = "载入插件", possibleArguments = "<插件名称>")
public void load(final InvokeCommandEvent e) { public void load(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender(); final CommandSender sender = e.getSender();