fix: tabComplete Error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-10-02 01:12:04 +08:00
parent 9f54734414
commit 37fb899e95
6 changed files with 181 additions and 174 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>Yum</artifactId> <artifactId>Yum</artifactId>
<version>2.8.3</version> <version>2.9.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>Minecraft 服务器插件管理系统</description> <description>Minecraft 服务器插件管理系统</description>
@ -16,8 +16,9 @@
</parent> </parent>
<properties> <properties>
<update.description>§a补丁包 2.8.3 版本</update.description> <update.description>§a补丁包 2.9.0 版本</update.description>
<update.changes> <update.changes>
§619-09-30 §cfix: tabComplete error;
§619-08-28 §cfix: knownCommands not compatible; §619-08-28 §cfix: knownCommands not compatible;
       §cfix: async event on primary thread;        §cfix: async event on primary thread;
§619-08-26 §cfix: 修复不兼容 1.14.4 的问题; §619-08-26 §cfix: 修复不兼容 1.14.4 的问题;

View File

@ -49,7 +49,7 @@ public class FileCommand implements Executor {
public FileCommand(Yum yum) { public FileCommand(Yum yum) {
plugin = yum; plugin = yum;
new CommandSub("file", this, PluginTabComplete.instence); new CommandSub("file", this, PluginTabComplete.INSTANCE);
} }
@Cmd(aliases = "cp", minimumArguments = 2) @Cmd(aliases = "cp", minimumArguments = 2)

View File

@ -70,7 +70,7 @@ public class MonitorCommand implements Executor {
private double um = 1000000.00; private double um = 1000000.00;
public MonitorCommand(Yum yum) { public MonitorCommand(Yum yum) {
new CommandSub("monitor", this, PluginTabComplete.instence); new CommandSub("monitor", this, PluginTabComplete.INSTANCE);
} }
@Cmd(aliases = "c", minimumArguments = 1) @Cmd(aliases = "c", minimumArguments = 1)
@ -116,7 +116,7 @@ public class MonitorCommand implements Executor {
@Cmd(aliases = "e", minimumArguments = 1) @Cmd(aliases = "e", minimumArguments = 1)
@Help(value = "查看插件事件能耗", possibleArguments = "[插件名称]") @Help(value = "查看插件事件能耗", possibleArguments = "[插件名称]")
@Async @Async
public void event(CommandSender sender, String pname) throws InstantiationException, IllegalAccessException, NoSuchFieldException { public void event(CommandSender sender, String pname) throws IllegalAccessException, NoSuchFieldException {
Plugin plugin = Bukkit.getPluginManager().getPlugin(pname); Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
if (plugin == null) { if (plugin == null) {
sender.sendMessage(String.format(p_n_f, pname)); sender.sendMessage(String.format(p_n_f, pname));

View File

@ -28,7 +28,7 @@ public class NetCommand implements Executor {
private String p_n_f = prefix + "§c插件 §b%s §c不存在!"; private String p_n_f = prefix + "§c插件 §b%s §c不存在!";
public NetCommand(Yum yum) { public NetCommand(Yum yum) {
new CommandSub("net", this, PluginTabComplete.instence); new CommandSub("net", this, PluginTabComplete.INSTANCE);
} }
public static void addNetCount(String pname) { public static void addNetCount(String pname) {

View File

@ -9,28 +9,36 @@ import org.bukkit.command.CommandSender;
import pw.yumc.Yum.api.YumAPI; import pw.yumc.Yum.api.YumAPI;
import pw.yumc.YumCore.commands.annotation.Tab; import pw.yumc.YumCore.commands.annotation.Tab;
import pw.yumc.YumCore.commands.interfaces.Executor; import pw.yumc.YumCore.commands.interfaces.Executor;
import pw.yumc.YumCore.kit.StrKit;
/** /**
*
* @since 2016年7月7日 上午8:36:47
* @author * @author
* @since 2016年7月7日 上午8:36:47
*/ */
public class PluginTabComplete implements Executor { public class PluginTabComplete implements Executor {
public static PluginTabComplete instence = new PluginTabComplete(); public static PluginTabComplete INSTANCE = new PluginTabComplete();
@Tab @Tab
public List<String> listtab(CommandSender sender, String label, String[] args) { public List<String> listTab(CommandSender sender, String label, String[] args) {
if (args.length > 1 && args[0].equalsIgnoreCase("install") || args[0].equalsIgnoreCase("i")) { if (args.length > 0) {
return StrKit.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList<String>()); switch (args[0]) {
} else if (args[0].equalsIgnoreCase("repo") || args[0].equalsIgnoreCase("r")) { case "install":
if (args.length == 2) { return StrKit.copyPartialMatches(args[1], Arrays.asList("add", "all", "list", "delall", "clean", "update", "del"), new ArrayList<String>()); } case "i":
if (args.length == 3 && ("add".equals(args[1]) || "del".equals(args[1]))) { return StrKit.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>()); } return YumAPI.getRepo().getAllPluginName();
} else if (args[0].equalsIgnoreCase("bukkitrepo") || args[0].equalsIgnoreCase("br")) { case "repo":
return StrKit.copyPartialMatches(args[1], Arrays.asList("look", "install"), new ArrayList<String>()); case "r":
} else { if (args.length == 2) {
return StrKit.copyPartialMatches(args[args.length - 1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>()); return Arrays.asList("add", "all", "list", "delall", "clean", "update", "del");
}
if (args.length == 3) {
return new ArrayList<>(YumAPI.getRepo().getRepos().keySet());
}
break;
case "bukkitrepo":
case "br":
return Arrays.asList("look", "install");
default:
}
} }
return null; return YumAPI.getPlugman().getPluginNames(false);
} }
} }

View File

@ -38,30 +38,30 @@ import pw.yumc.YumCore.tellraw.Tellraw;
/** /**
* Yum命令基类 * Yum命令基类
* *
* @since 2016年1月9日 上午10:02:24
* @author * @author
* @since 2016年1月9日 上午10:02:24
*/ */
public class YumCommand implements Executor { public class YumCommand implements Executor {
private String prefix = "§6[§bYum §a插件管理§6] "; private String prefix = "§6[§bYum §a插件管理§6] ";
private String searchlimit = prefix + "§c为保证搜索速度和准确性 关键词必须大于 3 个字符!"; private String searchLimit = prefix + "§c为保证搜索速度和准确性 关键词必须大于 3 个字符!";
private String searching = prefix + "§a正在从 §eBukkitDev §a获取 §b%s §a的相关数据..."; private String searching = prefix + "§a正在从 §eBukkitDev §a获取 §b%s §a的相关数据...";
private String not_found_from_bukkit = prefix + "§c未在 §eBukkitDev §c搜索到 §b%s §c的相关插件!"; private String notFoundFromBukkit = prefix + "§c未在 §eBukkitDev §c搜索到 §b%s §c的相关插件!";
private String result = prefix + "§6关键词 §b%s §6的搜索结果如下:"; private String result = prefix + "§6关键词 §b%s §6的搜索结果如下:";
private String bukkitlistprefix = " §6插件ID §3插件名称 §d发布类型 §a操作"; private String bukkitListPrefix = " §6插件ID §3插件名称 §d发布类型 §a操作";
private String bukkitlist = "§6- §e%-6s §b%-25s §d%-10s"; private String bukkitList = "§6- §e%-6s §b%-25s §d%-10s";
private String fsearching = prefix + "§a正在从 §eBukkitDev §a获取ID §b%s §a的文件列表..."; private String fsearching = prefix + "§a正在从 §eBukkitDev §a获取ID §b%s §a的文件列表...";
private String not_found_id_from_bukkit = prefix + "§c未在 §eBukkitDev §c搜索到ID为 §b%s §c的相关插件!"; private String notFoundIdFromBukkit = prefix + "§c未在 §eBukkitDev §c搜索到ID为 §b%s §c的相关插件!";
private String filelistprefix = " §6插件名称 §3游戏版本 §d发布类型 §a操作"; private String fileListPrefix = " §6插件名称 §3游戏版本 §d发布类型 §a操作";
private String filelist = "§6- §b%-20s §3%-15s §d%-10s"; private String fileList = "§6- §b%-20s §3%-15s §d%-10s";
private String del = "§c删除: §a插件 §b%s §a版本 §d%s §a已从服务器卸载并删除!"; private String del = "§c删除: §a插件 §b%s §a版本 §d%s §a已从服务器卸载并删除!";
private String delFailed = "§c删除: §a插件 §b%s §c卸载或删除时发生错误 删除失败!"; private String delFailed = "§c删除: §a插件 §b%s §c卸载或删除时发生错误 删除失败!";
private String look = "§6查看"; private String look = "§6查看";
private String install = "§a安装"; private String install = "§a安装";
private String install_tip = "§a点击安装"; private String installTip = "§a点击安装";
private String update = "§a更新"; private String update = "§a更新";
private String unload = "§d卸载"; private String unload = "§d卸载";
private String reload = "§6重载"; private String reload = "§6重载";
@ -73,7 +73,7 @@ public class YumCommand implements Executor {
public YumCommand(Yum yum) { public YumCommand(Yum yum) {
main = yum; main = yum;
new CommandSub("yum", this, PluginTabComplete.instence); new CommandSub("yum", this, PluginTabComplete.INSTANCE);
} }
@Async @Async
@ -81,73 +81,71 @@ public class YumCommand implements Executor {
@Help(value = "从BukkitDev查看安装插件", possibleArguments = "<操作符> <项目ID|项目名称> [地址]") @Help(value = "从BukkitDev查看安装插件", possibleArguments = "<操作符> <项目ID|项目名称> [地址]")
public void bukkitrepo(final CommandSender sender, final String opt, final String id, String url) { public void bukkitrepo(final CommandSender sender, final String opt, final String id, String url) {
switch (opt) { switch (opt) {
case "look": { case "look": {
sender.sendMessage(String.format(fsearching, id)); sender.sendMessage(String.format(fsearching, id));
List<Files> lf = Files.parseList(HttpKit.get(String.format(BukkitDev.PLUGIN, id))); List<Files> lf = Files.parseList(HttpKit.get(String.format(BukkitDev.PLUGIN, id)));
if (lf.isEmpty()) { if (lf.isEmpty()) {
sender.sendMessage(String.format(not_found_id_from_bukkit, id)); sender.sendMessage(String.format(notFoundIdFromBukkit, id));
return; return;
}
sender.sendMessage(filelistprefix);
for (int i = 0; i < lf.size() || i < 8; i++) {
Files f = lf.get(i);
Tellraw tr = Tellraw.create();
tr.text(String.format(filelist, f.name, f.gameVersion, f.releaseType));
tr.then(" ");
tr.then(install).command(String.format("/yum br ai %s %s", f.name, f.downloadUrl));
tr.tip(install_tip);
tr.send(sender);
}
break;
}
case "ai": {
if (url == null) { return; }
File file = new File(Bukkit.getUpdateFolderFile(), YumAPI.getDownload().getFileName(url));
YumAPI.getDownload().run(sender, url, file, new One<File>() {
@Override
public void run(File file) {
if (file.getName().endsWith(".zip")) {
try {
ZipKit.unzip(file, Bukkit.getUpdateFolderFile(), ".jar");
file.delete();
} catch (IOException e) {
sender.sendMessage(unzip_error);
}
}
YumAPI.upgrade(sender);
} }
}); sender.sendMessage(fileListPrefix);
break; for (int i = 0; i < lf.size() || i < 8; i++) {
} Files f = lf.get(i);
case "i": Tellraw tr = Tellraw.create();
case "install": { tr.text(String.format(fileList, f.name, f.gameVersion, f.releaseType));
sender.sendMessage(String.format(fsearching, id)); tr.then(" ");
List<Files> lf = Files.parseList(HttpKit.get(String.format(BukkitDev.PLUGIN, id))); tr.then(install).command(String.format("/yum br ai %s %s", f.name, f.downloadUrl));
if (lf.isEmpty()) { tr.tip(installTip);
sender.sendMessage(String.format(not_found_id_from_bukkit, id)); tr.send(sender);
return;
}
Files f = lf.get(0);
url = f.downloadUrl;
File file = new File(Bukkit.getUpdateFolderFile(), YumAPI.getDownload().getFileName(url));
YumAPI.getDownload().run(sender, url, file, new One<File>() {
@Override
public void run(File file) {
if (file.getName().endsWith(".zip")) {
try {
ZipKit.unzip(file, Bukkit.getUpdateFolderFile(), ".jar");
} catch (IOException e) {
sender.sendMessage(unzip_error);
}
}
YumAPI.upgrade(sender);
} }
}); break;
break; }
} case "ai": {
default: if (url == null) { return; }
break; File file = new File(Bukkit.getUpdateFolderFile(), YumAPI.getDownload().getFileName(url));
YumAPI.getDownload().run(sender, url, file, new One<File>() {
@Override
public void run(File file) {
if (file.getName().endsWith(".zip")) {
try {
ZipKit.unzip(file, Bukkit.getUpdateFolderFile(), ".jar");
file.delete();
} catch (IOException e) {
sender.sendMessage(unzip_error);
}
}
YumAPI.upgrade(sender);
}
});
break;
}
case "i":
case "install": {
sender.sendMessage(String.format(fsearching, id));
List<Files> lf = Files.parseList(HttpKit.get(String.format(BukkitDev.PLUGIN, id)));
if (lf.isEmpty()) {
sender.sendMessage(String.format(notFoundIdFromBukkit, id));
return;
}
Files f = lf.get(0);
url = f.downloadUrl;
File file = new File(Bukkit.getUpdateFolderFile(), YumAPI.getDownload().getFileName(url));
YumAPI.getDownload().run(sender, url, file, new One<File>() {
@Override
public void run(File file) {
if (file.getName().endsWith(".zip")) {
try {
ZipKit.unzip(file, Bukkit.getUpdateFolderFile(), ".jar");
} catch (IOException e) {
sender.sendMessage(unzip_error);
}
}
YumAPI.upgrade(sender);
}
});
break;
}
default:
} }
} }
@ -334,51 +332,51 @@ public class YumCommand implements Executor {
@Async @Async
public void repo(CommandSender sender, String cmd, String arg1) { public void repo(CommandSender sender, String cmd, String arg1) {
switch (cmd) { switch (cmd) {
case "add": case "add":
if (arg1 != null) { if (arg1 != null) {
if (YumAPI.getRepo().addRepositories(sender, arg1)) { if (YumAPI.getRepo().addRepositories(sender, arg1)) {
String reponame = YumAPI.getRepo().getRepoCache(arg1).name; String reponame = YumAPI.getRepo().getRepoCache(arg1).name;
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!"); sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
} else {
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
}
} else { } else {
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!"); sender.sendMessage("§6仓库: §c请输入需要添加的源地址!");
} }
} else { break;
sender.sendMessage("§6仓库: §c请输入需要添加的源地址!"); case "del":
} if (arg1 != null) {
break; Repositories delrepo = YumAPI.getRepo().getRepoCache(arg1);
case "del": if (delrepo != null) {
if (arg1 != null) { YumAPI.getRepo().delRepositories(sender, arg1);
Repositories delrepo = YumAPI.getRepo().getRepoCache(arg1); sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
if (delrepo != null) { } else {
YumAPI.getRepo().delRepositories(sender, arg1); sender.sendMessage("§6仓库: §c源地址未找到!");
sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!"); }
} else { } else {
sender.sendMessage("§6仓库: §c源地址未找到!"); sender.sendMessage("§6仓库: §c请输入需要删除的源地址!");
} }
} else { break;
sender.sendMessage("§6仓库: §c请输入需要删除的源地址!"); case "delall":
} YumAPI.getRepo().getRepoCache().getRepos().clear();
break; sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
case "delall": break;
YumAPI.getRepo().getRepoCache().getRepos().clear(); case "list":
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!"); sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
break; sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
case "list": break;
sender.sendMessage("§6仓库: §b缓存的插件信息如下 "); case "all":
sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo()); sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
break; sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
case "all": break;
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 "); case "clean":
sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo()); YumAPI.getRepo().clean();
break; sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
case "clean": break;
YumAPI.getRepo().clean(); case "update":
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!"); YumAPI.getRepo().updateRepositories(sender);
break; sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
case "update": break;
YumAPI.getRepo().updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break;
} }
} }
@ -388,20 +386,20 @@ public class YumCommand implements Executor {
@Async @Async
public void search(CommandSender sender, String pname) { public void search(CommandSender sender, String pname) {
if (pname.length() < 3) { if (pname.length() < 3) {
sender.sendMessage(searchlimit); sender.sendMessage(searchLimit);
return; return;
} }
sender.sendMessage(String.format(searching, pname)); sender.sendMessage(String.format(searching, pname));
List<Projects> list = Projects.parseList(HttpKit.get(String.format(BukkitDev.SEARCH, pname.toLowerCase()))); List<Projects> list = Projects.parseList(HttpKit.get(String.format(BukkitDev.SEARCH, pname.toLowerCase())));
if (list.isEmpty()) { if (list.isEmpty()) {
sender.sendMessage(String.format(not_found_from_bukkit, pname)); sender.sendMessage(String.format(notFoundFromBukkit, pname));
return; return;
} }
sender.sendMessage(String.format(result, pname)); sender.sendMessage(String.format(result, pname));
sender.sendMessage(bukkitlistprefix); sender.sendMessage(bukkitListPrefix);
for (Projects p : list) { for (Projects p : list) {
Tellraw fm = Tellraw.create(); Tellraw fm = Tellraw.create();
fm.text(String.format(bukkitlist, p.id, p.name, p.stage)); fm.text(String.format(bukkitList, p.id, p.name, p.stage));
fm.then(" "); fm.then(" ");
fm.then(look).cmd_tip("/yum br look " + p.id, look); fm.then(look).cmd_tip("/yum br look " + p.id, look);
fm.send(sender); fm.send(sender);
@ -432,23 +430,23 @@ public class YumCommand implements Executor {
} }
String[] args = argstring.split(" "); String[] args = argstring.split(" ");
switch (args.length) { switch (args.length) {
case 1: case 1:
case 2: case 2:
String pluginname = args[0]; String pluginname = args[0];
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始更新插件: " + pluginname); sender.sendMessage("§a开始更新插件: " + pluginname);
if (plugin != null) { if (plugin != null) {
if (args.length < 2) { if (args.length < 2) {
YumAPI.updateFromYum(sender, plugin); YumAPI.updateFromYum(sender, plugin);
} else {
YumAPI.updateFromYum(sender, plugin, args[1]);
}
} else { } else {
YumAPI.updateFromYum(sender, plugin, args[1]); sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用 §b/yum install " + pluginname + "!");
} }
} else { break;
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用 §b/yum install " + pluginname + "!"); default:
} sender.sendMessage("§c命令参数错误!");
break;
default:
sender.sendMessage("§c命令参数错误!");
} }
} }
@ -477,18 +475,18 @@ public class YumCommand implements Executor {
* 发生实体消息 * 发生实体消息
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param prefix * @param prefix
* 实体前缀 * 实体前缀
* @param map * @param map
* 实体 * 实体
* @param key * @param key
* 实体Key * 实体Key
*/ */
private void sendEntry(CommandSender sender, String prefix, Map<String, Object> map, String key) { private void sendEntry(CommandSender sender, String prefix, Map<String, Object> map, String key) {
Object value = map.get(key); Object value = map.get(key);
if (value != null) { if (value != null) {
sender.sendMessage(prefix + (String) value); sender.sendMessage(prefix + value);
} }
} }
@ -496,13 +494,13 @@ public class YumCommand implements Executor {
* 发生实体消息 * 发生实体消息
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param prefix * @param prefix
* 实体前缀 * 实体前缀
* @param map * @param map
* 实体 * 实体
* @param key * @param key
* 实体Key * 实体Key
*/ */
private void sendEntryList(CommandSender sender, String prefix, Map<String, Object> map, String key) { private void sendEntryList(CommandSender sender, String prefix, Map<String, Object> map, String key) {
List<String> values = (List<String>) map.get(key); List<String> values = (List<String>) map.get(key);
@ -517,9 +515,9 @@ public class YumCommand implements Executor {
* 给玩家或控制台发送消息组 * 给玩家或控制台发送消息组
* *
* @param sender * @param sender
* 接收消息的玩家 * 接收消息的玩家
* @param msg * @param msg
* 消息组 * 消息组
*/ */
public static void sendStringArray(CommandSender sender, Collection<String> msg) { public static void sendStringArray(CommandSender sender, Collection<String> msg) {
for (String string : msg) { for (String string : msg) {
@ -531,11 +529,11 @@ public class YumCommand implements Executor {
* 给玩家或控制台发送消息组 * 给玩家或控制台发送消息组
* *
* @param sender * @param sender
* 接收消息的玩家 * 接收消息的玩家
* @param msg * @param msg
* 消息组 * 消息组
* @param prefix * @param prefix
* 消息前缀 * 消息前缀
*/ */
public static void sendStringArray(CommandSender sender, Collection<String> msg, String prefix) { public static void sendStringArray(CommandSender sender, Collection<String> msg, String prefix) {
for (String string : msg) { for (String string : msg) {
@ -547,13 +545,13 @@ public class YumCommand implements Executor {
* 给玩家或控制台发送消息组 * 给玩家或控制台发送消息组
* *
* @param sender * @param sender
* 接收消息的玩家 * 接收消息的玩家
* @param msg * @param msg
* 消息组 * 消息组
* @param prefix * @param prefix
* 消息前缀 * 消息前缀
* @param suffix * @param suffix
* 消息后缀 * 消息后缀
*/ */
public static void sendStringArray(CommandSender sender, Collection<String> msg, String prefix, String suffix) { public static void sendStringArray(CommandSender sender, Collection<String> msg, String prefix, String suffix) {
for (String string : msg) { for (String string : msg) {