From aef2aff1b7b06686b9260fa6564c4771f5de9a53 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Thu, 26 Nov 2015 19:52:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=AA=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E6=89=A7=E8=A1=8C=E9=80=89=E9=A1=B9?= =?UTF-8?q?...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 4 +- src/main/java/cn/citycraft/Yum/Yum.java | 37 +++---------------- .../java/cn/citycraft/Yum/api/YumAPI.java | 35 ++++++++++++++++-- .../citycraft/Yum/commands/CommandDelete.java | 2 +- .../citycraft/Yum/commands/CommandInfo.java | 4 +- .../Yum/commands/CommandInstall.java | 2 +- .../citycraft/Yum/commands/CommandList.java | 2 +- .../citycraft/Yum/commands/CommandLoad.java | 2 +- .../citycraft/Yum/commands/CommandReload.java | 4 +- .../citycraft/Yum/commands/CommandRepo.java | 20 +++++----- .../citycraft/Yum/commands/CommandUnload.java | 2 +- .../citycraft/Yum/commands/CommandUpdate.java | 3 -- .../Yum/commands/CommandUpdateAll.java | 3 -- .../Yum/commands/CommandUpgrade.java | 2 +- .../cn/citycraft/Yum/commands/YumCommand.java | 22 +++++++++++ src/main/resources/config.yml | 3 ++ 16 files changed, 84 insertions(+), 63 deletions(-) create mode 100644 src/main/java/cn/citycraft/Yum/commands/YumCommand.java create mode 100644 src/main/resources/config.yml diff --git a/pom.xml b/pom.xml index f03025a..f80ad1f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft Yum - 1.8.5 + 1.8.6 Yum Minecraft 服务器插件管理系统 @@ -55,7 +55,7 @@ http://ci.citycraft.cn:8080 - &c重大更新 支持一键更新老版本插件... + &c新增只允许控制台执行选项... UTF-8 diff --git a/src/main/java/cn/citycraft/Yum/Yum.java b/src/main/java/cn/citycraft/Yum/Yum.java index 2145007..a34b66a 100644 --- a/src/main/java/cn/citycraft/Yum/Yum.java +++ b/src/main/java/cn/citycraft/Yum/Yum.java @@ -5,21 +5,10 @@ package cn.citycraft.Yum; import org.bukkit.plugin.java.JavaPlugin; -import cn.citycraft.PluginHelper.commands.HandlerSubCommand; import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.utils.VersionChecker; import cn.citycraft.Yum.api.YumAPI; -import cn.citycraft.Yum.commands.CommandDelete; -import cn.citycraft.Yum.commands.CommandInfo; -import cn.citycraft.Yum.commands.CommandInstall; -import cn.citycraft.Yum.commands.CommandList; -import cn.citycraft.Yum.commands.CommandLoad; -import cn.citycraft.Yum.commands.CommandReload; -import cn.citycraft.Yum.commands.CommandRepo; -import cn.citycraft.Yum.commands.CommandUnload; -import cn.citycraft.Yum.commands.CommandUpdate; -import cn.citycraft.Yum.commands.CommandUpdateAll; -import cn.citycraft.Yum.commands.CommandUpgrade; +import cn.citycraft.Yum.commands.YumCommand; /** * MC插件仓库 @@ -28,34 +17,18 @@ import cn.citycraft.Yum.commands.CommandUpgrade; */ public class Yum extends JavaPlugin { public FileConfig config; - public YumAPI yumgr; - - public void initCommands() { - final HandlerSubCommand cmdhandler = new HandlerSubCommand(this, "yum"); - cmdhandler.registerCommand(new CommandList(this)); - cmdhandler.registerCommand(new CommandInstall(this)); - cmdhandler.registerCommand(new CommandUpdate(this)); - cmdhandler.registerCommand(new CommandUpdateAll(this)); - cmdhandler.registerCommand(new CommandDelete(this)); - cmdhandler.registerCommand(new CommandInfo(this)); - cmdhandler.registerCommand(new CommandRepo(this)); - cmdhandler.registerCommand(new CommandReload(this)); - cmdhandler.registerCommand(new CommandLoad(this)); - cmdhandler.registerCommand(new CommandUnload(this)); - cmdhandler.registerCommand(new CommandUpgrade(this)); - } @Override public void onDisable() { - YumAPI.repo.cacheToJson(config); + YumAPI.getRepo().cacheToJson(config); config.save(); } @Override public void onEnable() { - this.initCommands(); - yumgr = new YumAPI(this); - YumAPI.repo.jsonToCache(config); + new YumCommand(this); + new YumAPI(this); + YumAPI.getRepo().jsonToCache(config); YumAPI.updaterepo(); new VersionChecker(this); } diff --git a/src/main/java/cn/citycraft/Yum/api/YumAPI.java b/src/main/java/cn/citycraft/Yum/api/YumAPI.java index 7d75ef7..68db8d7 100644 --- a/src/main/java/cn/citycraft/Yum/api/YumAPI.java +++ b/src/main/java/cn/citycraft/Yum/api/YumAPI.java @@ -22,9 +22,11 @@ import cn.citycraft.Yum.manager.RepositoryManager; * 2015年9月1日上午10:59:47 */ public class YumAPI { - public static DownloadManager download; - public static PluginsManager plugman; - public static RepositoryManager repo; + private static DownloadManager download; + + private static PluginsManager plugman; + + private static RepositoryManager repo; protected static Plugin main; @@ -45,6 +47,33 @@ public class YumAPI { plugman.deletePlugin(plugin); } + /** + * 获得下载管理器 + * + * @return {@link DownloadManager} + */ + public static DownloadManager getDownload() { + return download; + } + + /** + * 获得插件管理器 + * + * @return {@link PluginsManager} + */ + public static PluginsManager getPlugman() { + return plugman; + } + + /** + * 获得仓库管理器 + * + * @return {@link RepositoryManager} + */ + public static RepositoryManager getRepo() { + return repo; + } + /** * 安装新插件 * diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandDelete.java b/src/main/java/cn/citycraft/Yum/commands/CommandDelete.java index 42220e2..fb4a44f 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandDelete.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandDelete.java @@ -37,7 +37,7 @@ public class CommandDelete extends BaseCommand { final String pluginname = args[0]; final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); if (plugin != null) { - if (YumAPI.plugman.deletePlugin(sender, plugin)) { + if (YumAPI.getPlugman().deletePlugin(sender, plugin)) { sender.sendMessage("§c删除: §a插件 " + pluginname + " 已从服务器卸载并删除!"); } else { sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!"); diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandInfo.java b/src/main/java/cn/citycraft/Yum/commands/CommandInfo.java index 1788332..1061e36 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandInfo.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandInfo.java @@ -51,7 +51,7 @@ public class CommandInfo extends BaseCommand { StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a"); sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().size() == 0 ? "无" : "")); StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a"); - sender.sendMessage("§6插件物理路径: §3" + YumAPI.plugman.getPluginFile(plugin).getAbsolutePath()); + sender.sendMessage("§6插件物理路径: §3" + YumAPI.getPlugman().getPluginFile(plugin).getAbsolutePath()); } else { sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!"); } @@ -60,7 +60,7 @@ public class CommandInfo extends BaseCommand { @Override public List onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { if (!args[0].equalsIgnoreCase("install") && !args[0].equalsIgnoreCase("repo")) { - return StringUtil.copyPartialMatches(args[1], YumAPI.plugman.getPluginNames(false), new ArrayList()); + return StringUtil.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList()); } return null; } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java b/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java index 1722996..b631a0c 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java @@ -59,7 +59,7 @@ public class CommandInstall extends BaseCommand { @Override public List onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { if (args[0].equalsIgnoreCase("install")) { - return StringUtil.copyPartialMatches(args[1], YumAPI.repo.getAllPluginName(), new ArrayList()); + return StringUtil.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList()); } return null; } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandList.java b/src/main/java/cn/citycraft/Yum/commands/CommandList.java index 456dd97..b767937 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandList.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandList.java @@ -34,7 +34,7 @@ public class CommandList extends BaseCommand { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: "); for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { - sender.sendMessage("§6 - " + YumAPI.plugman.getFormattedName(plugin, true)); + sender.sendMessage("§6 - " + YumAPI.getPlugman().getFormattedName(plugin, true)); } }; } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java b/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java index bfea42b..586bd63 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java @@ -37,7 +37,7 @@ public class CommandLoad extends BaseCommand { final String pluginname = args[0]; final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); if (plugin == null) { - YumAPI.plugman.load(sender, pluginname); + YumAPI.getPlugman().load(sender, pluginname); } else { sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!"); } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandReload.java b/src/main/java/cn/citycraft/Yum/commands/CommandReload.java index 94e85d1..4507c70 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandReload.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandReload.java @@ -36,12 +36,12 @@ public class CommandReload extends BaseCommand { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { final String pluginname = args[0]; if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) { - YumAPI.plugman.reloadAll(sender); + YumAPI.getPlugman().reloadAll(sender); return; } final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); if (plugin != null) { - YumAPI.plugman.reload(sender, plugin); + YumAPI.getPlugman().reload(sender, plugin); } else { sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java index 2b48da0..bd5ec91 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java @@ -45,8 +45,8 @@ public class CommandRepo extends BaseCommand { switch (cmd) { case "add": if (args.length == 2) { - if (YumAPI.repo.addRepositories(sender, args[1])) { - final String reponame = YumAPI.repo.getRepoCache(args[1]).name; + if (YumAPI.getRepo().addRepositories(sender, args[1])) { + final String reponame = YumAPI.getRepo().getRepoCache(args[1]).name; sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!"); } else { sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!"); @@ -57,9 +57,9 @@ public class CommandRepo extends BaseCommand { break; case "del": if (args.length == 2) { - final Repositories delrepo = YumAPI.repo.getRepoCache(args[1]); + final Repositories delrepo = YumAPI.getRepo().getRepoCache(args[1]); if (delrepo != null) { - YumAPI.repo.delRepositories(sender, args[1]); + YumAPI.getRepo().delRepositories(sender, args[1]); sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!"); } else { sender.sendMessage("§6仓库: §c源地址未找到!"); @@ -69,23 +69,23 @@ public class CommandRepo extends BaseCommand { } break; case "delall": - YumAPI.repo.getRepoCache().getRepos().clear(); + YumAPI.getRepo().getRepoCache().getRepos().clear(); sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!"); break; case "list": sender.sendMessage("§6仓库: §b缓存的插件信息如下 "); - StringUtil.sendStringArray(sender, YumAPI.repo.getAllPluginsInfo()); + StringUtil.sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo()); break; case "all": sender.sendMessage("§6仓库: §b缓存的仓库信息如下 "); - StringUtil.sendStringArray(sender, YumAPI.repo.getRepoCache().getAllRepoInfo()); + StringUtil.sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo()); break; case "clean": - YumAPI.repo.clean(); + YumAPI.getRepo().clean(); sender.sendMessage("§6仓库: §a缓存的插件信息已清理!"); break; case "update": - YumAPI.repo.updateRepositories(sender); + YumAPI.getRepo().updateRepositories(sender); sender.sendMessage("§6仓库: §a仓库缓存数据已更新!"); break; } @@ -100,7 +100,7 @@ public class CommandRepo extends BaseCommand { return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "delall", "clean", "update", "del" }), new ArrayList()); } if (args.length == 3 && (args[1] == "add" || args[1] == "del")) { - return StringUtil.copyPartialMatches(args[2], YumAPI.repo.getRepos().keySet(), new ArrayList()); + return StringUtil.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList()); } } return null; diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java b/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java index f6acaef..a607a77 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java @@ -37,7 +37,7 @@ public class CommandUnload extends BaseCommand { final String pluginname = args[0]; final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); if (plugin != null) { - YumAPI.plugman.unload(sender, plugin); + YumAPI.getPlugman().unload(sender, plugin); } else { sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java b/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java index 1f26475..99184ca 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java @@ -19,9 +19,6 @@ import cn.citycraft.Yum.api.YumAPI; public class CommandUpdate extends BaseCommand { Yum main; - /** - * @param name - */ public CommandUpdate(final Yum main) { super(); this.main = main; diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUpdateAll.java b/src/main/java/cn/citycraft/Yum/commands/CommandUpdateAll.java index 628ec65..99dcdba 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUpdateAll.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUpdateAll.java @@ -18,9 +18,6 @@ import cn.citycraft.Yum.api.YumAPI; public class CommandUpdateAll extends BaseCommand { Yum main; - /** - * @param name - */ public CommandUpdateAll(final Yum main) { super(); this.main = main; diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUpgrade.java b/src/main/java/cn/citycraft/Yum/commands/CommandUpgrade.java index d8d7a13..e8cfbc7 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUpgrade.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUpgrade.java @@ -35,7 +35,7 @@ public class CommandUpgrade extends BaseCommand { @Override public void run() { if (args.length == 0) { - YumAPI.plugman.upgrade(sender); + YumAPI.getPlugman().upgrade(sender); } else { final String pluginname = args[0]; final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); diff --git a/src/main/java/cn/citycraft/Yum/commands/YumCommand.java b/src/main/java/cn/citycraft/Yum/commands/YumCommand.java new file mode 100644 index 0000000..398eef9 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/commands/YumCommand.java @@ -0,0 +1,22 @@ +package cn.citycraft.Yum.commands; + +import cn.citycraft.PluginHelper.commands.HandlerSubCommand; +import cn.citycraft.Yum.Yum; + +public class YumCommand { + public YumCommand(final Yum yum) { + final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "yum"); + cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyCommandConsole", false)); + cmdhandler.registerCommand(new CommandList(yum)); + cmdhandler.registerCommand(new CommandInstall(yum)); + cmdhandler.registerCommand(new CommandUpdate(yum)); + cmdhandler.registerCommand(new CommandUpdateAll(yum)); + cmdhandler.registerCommand(new CommandDelete(yum)); + cmdhandler.registerCommand(new CommandInfo(yum)); + cmdhandler.registerCommand(new CommandRepo(yum)); + cmdhandler.registerCommand(new CommandReload(yum)); + cmdhandler.registerCommand(new CommandLoad(yum)); + cmdhandler.registerCommand(new CommandUnload(yum)); + cmdhandler.registerCommand(new CommandUpgrade(yum)); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..702b5c8 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,3 @@ +Version: 1.0 +#是否只允许控制台执行插件命令 +onlyCommandConsole: false \ No newline at end of file