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

View File

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

View File

@ -70,7 +70,7 @@ public class MonitorCommand implements Executor {
private double um = 1000000.00;
public MonitorCommand(Yum yum) {
new CommandSub("monitor", this, PluginTabComplete.instence);
new CommandSub("monitor", this, PluginTabComplete.INSTANCE);
}
@Cmd(aliases = "c", minimumArguments = 1)
@ -116,7 +116,7 @@ public class MonitorCommand implements Executor {
@Cmd(aliases = "e", minimumArguments = 1)
@Help(value = "查看插件事件能耗", possibleArguments = "[插件名称]")
@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);
if (plugin == null) {
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不存在!";
public NetCommand(Yum yum) {
new CommandSub("net", this, PluginTabComplete.instence);
new CommandSub("net", this, PluginTabComplete.INSTANCE);
}
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.YumCore.commands.annotation.Tab;
import pw.yumc.YumCore.commands.interfaces.Executor;
import pw.yumc.YumCore.kit.StrKit;
/**
*
* @since 2016年7月7日 上午8:36:47
* @author
* @since 2016年7月7日 上午8:36:47
*/
public class PluginTabComplete implements Executor {
public static PluginTabComplete instence = new PluginTabComplete();
public static PluginTabComplete INSTANCE = new PluginTabComplete();
@Tab
public List<String> listtab(CommandSender sender, String label, String[] args) {
if (args.length > 1 && 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") || args[0].equalsIgnoreCase("r")) {
if (args.length == 2) { return StrKit.copyPartialMatches(args[1], Arrays.asList("add", "all", "list", "delall", "clean", "update", "del"), new ArrayList<String>()); }
if (args.length == 3 && ("add".equals(args[1]) || "del".equals(args[1]))) { return StrKit.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>()); }
} else if (args[0].equalsIgnoreCase("bukkitrepo") || args[0].equalsIgnoreCase("br")) {
return StrKit.copyPartialMatches(args[1], Arrays.asList("look", "install"), new ArrayList<String>());
} else {
return StrKit.copyPartialMatches(args[args.length - 1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>());
public List<String> listTab(CommandSender sender, String label, String[] args) {
if (args.length > 0) {
switch (args[0]) {
case "install":
case "i":
return YumAPI.getRepo().getAllPluginName();
case "repo":
case "r":
if (args.length == 2) {
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命令基类
*
* @since 2016年1月9日 上午10:02:24
* @author
* @since 2016年1月9日 上午10:02:24
*/
public class YumCommand implements Executor {
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 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 bukkitlistprefix = " §6插件ID §3插件名称 §d发布类型 §a操作";
private String bukkitlist = "§6- §e%-6s §b%-25s §d%-10s";
private String bukkitListPrefix = " §6插件ID §3插件名称 §d发布类型 §a操作";
private String bukkitList = "§6- §e%-6s §b%-25s §d%-10s";
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 filelistprefix = " §6插件名称 §3游戏版本 §d发布类型 §a操作";
private String filelist = "§6- §b%-20s §3%-15s §d%-10s";
private String notFoundIdFromBukkit = prefix + "§c未在 §eBukkitDev §c搜索到ID为 §b%s §c的相关插件!";
private String fileListPrefix = " §6插件名称 §3游戏版本 §d发布类型 §a操作";
private String fileList = "§6- §b%-20s §3%-15s §d%-10s";
private String del = "§c删除: §a插件 §b%s §a版本 §d%s §a已从服务器卸载并删除!";
private String delFailed = "§c删除: §a插件 §b%s §c卸载或删除时发生错误 删除失败!";
private String look = "§6查看";
private String install = "§a安装";
private String install_tip = "§a点击安装";
private String installTip = "§a点击安装";
private String update = "§a更新";
private String unload = "§d卸载";
private String reload = "§6重载";
@ -73,7 +73,7 @@ public class YumCommand implements Executor {
public YumCommand(Yum yum) {
main = yum;
new CommandSub("yum", this, PluginTabComplete.instence);
new CommandSub("yum", this, PluginTabComplete.INSTANCE);
}
@Async
@ -81,73 +81,71 @@ public class YumCommand implements Executor {
@Help(value = "从BukkitDev查看安装插件", possibleArguments = "<操作符> <项目ID|项目名称> [地址]")
public void bukkitrepo(final CommandSender sender, final String opt, final String id, String url) {
switch (opt) {
case "look": {
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(not_found_id_from_bukkit, id));
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);
case "look": {
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;
}
});
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(not_found_id_from_bukkit, 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);
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(installTip);
tr.send(sender);
}
});
break;
}
default:
break;
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);
}
});
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
public void repo(CommandSender sender, String cmd, String arg1) {
switch (cmd) {
case "add":
if (arg1 != null) {
if (YumAPI.getRepo().addRepositories(sender, arg1)) {
String reponame = YumAPI.getRepo().getRepoCache(arg1).name;
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
case "add":
if (arg1 != null) {
if (YumAPI.getRepo().addRepositories(sender, arg1)) {
String reponame = YumAPI.getRepo().getRepoCache(arg1).name;
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
} else {
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
}
} else {
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
sender.sendMessage("§6仓库: §c请输入需要添加的源地址!");
}
} else {
sender.sendMessage("§6仓库: §c请输入需要添加的源地址!");
}
break;
case "del":
if (arg1 != null) {
Repositories delrepo = YumAPI.getRepo().getRepoCache(arg1);
if (delrepo != null) {
YumAPI.getRepo().delRepositories(sender, arg1);
sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
break;
case "del":
if (arg1 != null) {
Repositories delrepo = YumAPI.getRepo().getRepoCache(arg1);
if (delrepo != null) {
YumAPI.getRepo().delRepositories(sender, arg1);
sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
} else {
sender.sendMessage("§6仓库: §c源地址未找到!");
}
} else {
sender.sendMessage("§6仓库: §c源地址未找到!");
sender.sendMessage("§6仓库: §c请输入需要删除的源地址!");
}
} else {
sender.sendMessage("§6仓库: §c请输入需要删除的源地址!");
}
break;
case "delall":
YumAPI.getRepo().getRepoCache().getRepos().clear();
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
break;
case "list":
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
break;
case "all":
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
break;
case "clean":
YumAPI.getRepo().clean();
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
break;
case "update":
YumAPI.getRepo().updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break;
break;
case "delall":
YumAPI.getRepo().getRepoCache().getRepos().clear();
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
break;
case "list":
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
break;
case "all":
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
break;
case "clean":
YumAPI.getRepo().clean();
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
break;
case "update":
YumAPI.getRepo().updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break;
}
}
@ -388,20 +386,20 @@ public class YumCommand implements Executor {
@Async
public void search(CommandSender sender, String pname) {
if (pname.length() < 3) {
sender.sendMessage(searchlimit);
sender.sendMessage(searchLimit);
return;
}
sender.sendMessage(String.format(searching, pname));
List<Projects> list = Projects.parseList(HttpKit.get(String.format(BukkitDev.SEARCH, pname.toLowerCase())));
if (list.isEmpty()) {
sender.sendMessage(String.format(not_found_from_bukkit, pname));
sender.sendMessage(String.format(notFoundFromBukkit, pname));
return;
}
sender.sendMessage(String.format(result, pname));
sender.sendMessage(bukkitlistprefix);
sender.sendMessage(bukkitListPrefix);
for (Projects p : list) {
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(look).cmd_tip("/yum br look " + p.id, look);
fm.send(sender);
@ -432,23 +430,23 @@ public class YumCommand implements Executor {
}
String[] args = argstring.split(" ");
switch (args.length) {
case 1:
case 2:
String pluginname = args[0];
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始更新插件: " + pluginname);
if (plugin != null) {
if (args.length < 2) {
YumAPI.updateFromYum(sender, plugin);
case 1:
case 2:
String pluginname = args[0];
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始更新插件: " + pluginname);
if (plugin != null) {
if (args.length < 2) {
YumAPI.updateFromYum(sender, plugin);
} else {
YumAPI.updateFromYum(sender, plugin, args[1]);
}
} else {
YumAPI.updateFromYum(sender, plugin, args[1]);
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用 §b/yum install " + pluginname + "!");
}
} else {
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用 §b/yum install " + pluginname + "!");
}
break;
default:
sender.sendMessage("§c命令参数错误!");
break;
default:
sender.sendMessage("§c命令参数错误!");
}
}
@ -477,18 +475,18 @@ public class YumCommand implements Executor {
* 发生实体消息
*
* @param sender
* 命令发送者
* 命令发送者
* @param prefix
* 实体前缀
* 实体前缀
* @param map
* 实体
* 实体
* @param key
* 实体Key
* 实体Key
*/
private void sendEntry(CommandSender sender, String prefix, Map<String, Object> map, String key) {
Object value = map.get(key);
if (value != null) {
sender.sendMessage(prefix + (String) value);
sender.sendMessage(prefix + value);
}
}
@ -496,13 +494,13 @@ public class YumCommand implements Executor {
* 发生实体消息
*
* @param sender
* 命令发送者
* 命令发送者
* @param prefix
* 实体前缀
* 实体前缀
* @param map
* 实体
* 实体
* @param key
* 实体Key
* 实体Key
*/
private void sendEntryList(CommandSender sender, String prefix, Map<String, Object> map, String key) {
List<String> values = (List<String>) map.get(key);
@ -517,9 +515,9 @@ public class YumCommand implements Executor {
* 给玩家或控制台发送消息组
*
* @param sender
* 接收消息的玩家
* 接收消息的玩家
* @param msg
* 消息组
* 消息组
*/
public static void sendStringArray(CommandSender sender, Collection<String> msg) {
for (String string : msg) {
@ -531,11 +529,11 @@ public class YumCommand implements Executor {
* 给玩家或控制台发送消息组
*
* @param sender
* 接收消息的玩家
* 接收消息的玩家
* @param msg
* 消息组
* 消息组
* @param prefix
* 消息前缀
* 消息前缀
*/
public static void sendStringArray(CommandSender sender, Collection<String> msg, String prefix) {
for (String string : msg) {
@ -547,13 +545,13 @@ public class YumCommand implements Executor {
* 给玩家或控制台发送消息组
*
* @param sender
* 接收消息的玩家
* 接收消息的玩家
* @param msg
* 消息组
* 消息组
* @param prefix
* 消息前缀
* 消息前缀
* @param suffix
* 消息后缀
* 消息后缀
*/
public static void sendStringArray(CommandSender sender, Collection<String> msg, String prefix, String suffix) {
for (String string : msg) {