diff --git a/pom.xml b/pom.xml index 9ad9603..f03025a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft Yum - 1.8.3 + 1.8.5 Yum Minecraft 服务器插件管理系统 @@ -55,7 +55,7 @@ http://ci.citycraft.cn:8080 - &b默认使用国内源数据 添加仓库查看命令... + &c重大更新 支持一键更新老版本插件... UTF-8 diff --git a/src/main/java/cn/citycraft/Yum/Yum.java b/src/main/java/cn/citycraft/Yum/Yum.java index c17dc6c..2145007 100644 --- a/src/main/java/cn/citycraft/Yum/Yum.java +++ b/src/main/java/cn/citycraft/Yum/Yum.java @@ -8,6 +8,7 @@ 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; @@ -19,7 +20,6 @@ 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.manager.YumManager; /** * MC插件仓库 @@ -28,7 +28,7 @@ import cn.citycraft.Yum.manager.YumManager; */ public class Yum extends JavaPlugin { public FileConfig config; - public YumManager yumgr; + public YumAPI yumgr; public void initCommands() { final HandlerSubCommand cmdhandler = new HandlerSubCommand(this, "yum"); @@ -47,16 +47,16 @@ public class Yum extends JavaPlugin { @Override public void onDisable() { - YumManager.repo.cacheToJson(config); + YumAPI.repo.cacheToJson(config); config.save(); } @Override public void onEnable() { this.initCommands(); - yumgr = new YumManager(this); - YumManager.repo.jsonToCache(config); - YumManager.updaterepo(); + yumgr = new YumAPI(this); + YumAPI.repo.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 new file mode 100644 index 0000000..7d75ef7 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/api/YumAPI.java @@ -0,0 +1,250 @@ +package cn.citycraft.Yum.api; + +import java.io.File; +import java.net.URL; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; + +import cn.citycraft.CommonData.UpdatePlugin; +import cn.citycraft.Yum.manager.DownloadManager; +import cn.citycraft.Yum.manager.PluginInfo; +import cn.citycraft.Yum.manager.PluginsManager; +import cn.citycraft.Yum.manager.RepositoryManager; + +/** + * Yum管理中心 + * + * @author 蒋天蓓 + * 2015年9月1日上午10:59:47 + */ +public class YumAPI { + public static DownloadManager download; + public static PluginsManager plugman; + public static RepositoryManager repo; + + protected static Plugin main; + + public YumAPI(final Plugin plugin) { + YumAPI.main = plugin; + plugman = new PluginsManager(main); + download = new DownloadManager(main); + repo = new RepositoryManager(main); + } + + /** + * 删除插件 + * + * @param plugin + * - 插件实体 + */ + public static void delete(final Plugin plugin) { + plugman.deletePlugin(plugin); + } + + /** + * 安装新插件 + * + * @param sender + * - 命令发送者 + * @param pluginname + * - 插件名称 + * @param version + * - 插件版本 + * @return 是否安装成功 + */ + public static boolean install(final CommandSender sender, final String pluginname, final String url) { + if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile().getParentFile(), pluginname + ".jar"))) { + return plugman.load(sender, pluginname); + } + return false; + } + + /** + * 安装新插件 + * + * @param pluginname + * - 插件名称 + * @param version + * - 插件版本 + * @return 是否安装成功 + */ + public static boolean install(final String pluginname, final String url) { + return install(null, pluginname, url); + } + + /** + * 安装新插件 + * + * @param sender + * - 命令发送者 + * @param pluginname + * - 插件名称 + * @return 是否安装成功 + */ + public static boolean installfromyum(final CommandSender sender, final String pluginname) { + return installfromyum(sender, pluginname, null); + } + + /** + * 安装新插件 + * + * @param sender + * - 命令发送者 + * @param pluginname + * - 插件名称 + * @param version + * - 插件版本 + * @return 是否安装成功 + */ + public static boolean installfromyum(final CommandSender sender, final String pluginname, final String version) { + final PluginInfo pi = repo.getPlugin(pluginname); + if (pi != null) { + return install(sender, pi.name, pi.getMavenUrl(sender, version)); + } + return false; + } + + /** + * 载入插件 + * + * @param pluginname + * - 插件名称 + */ + public static void load(final String pluginname) { + plugman.load(pluginname); + } + + /** + * 卸载插件 + * + * @param plugin + * - 插件实体 + */ + public static void reload(final Plugin plugin) { + plugman.unload(plugin); + } + + /** + * 重载插件 + * + * @param plugin + * - 插件实体 + */ + public static void unload(final Plugin plugin) { + plugman.reload(plugin); + } + + /** + * 更新插件 + * + * @param sender + * - 命令发送者 + * @param plugin + * - 插件实体 + * @param url + * - 新插件的下载地址 + * @return 是否更新成功 + */ + public static boolean update(final CommandSender sender, final Plugin plugin, final URL url) { + if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { + sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!"); + return true; + } + return false; + } + + /** + * 更新插件 + * + * @param plugin + * - 插件实体 + * @param url + * - 新插件的下载地址 + * @return 是否更新成功 + */ + public static boolean update(final Plugin plugin, final URL url) { + return update(null, plugin, url); + } + + /** + * 更新支持Yum的插件 + * + * @param sender + * - 命令发送者 + */ + public static void updateall(final CommandSender sender) { + final Map updatelist = UpdatePlugin.getList(); + if (updatelist.size() > 0) { + for (final Entry updateplugin : UpdatePlugin.getList().entrySet()) { + updatefromyum(sender, updateplugin.getKey(), updateplugin.getValue()); + } + UpdatePlugin.getList().clear(); + sender.sendMessage("§6更新: §c已下载所有需要插件的插件到 到update文件夹 重启后自动更新(或使用/yum upgrade直接升级)!"); + } else { + sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!"); + } + } + + /** + * 更新插件 + * + * @param sender + * - 命令发送者 + * @param plugin + * - 插件实体 + * @return 是否更新成功 + */ + public static boolean updatefromyum(final CommandSender sender, final Plugin plugin) { + return updatefromyum(sender, plugin, null); + } + + /** + * 从Yum内部更新插件 + * + * @param sender + * - 命令发送者 + * @param plugin + * - 插件实体 + * @param version + * - 插件版本(null则自动获取) + * @return + */ + public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) { + final PluginInfo pi = repo.getPlugin(plugin.getName()); + if (pi != null) { + if (download.run(sender, pi.getMavenUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { + sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!"); + return true; + } + } else { + sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName()); + } + return false; + } + + /** + * 更新Yum源数据 + */ + public static void updaterepo() { + main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() { + @Override + public void run() { + repo.updateRepositories(Bukkit.getConsoleSender()); + } + }); + } + + /** + * @param sender + * - 命令发送者 + * @param plugin + * - 插件实体 + */ + public static void upgrade(final CommandSender sender, final Plugin plugin) { + plugman.upgrade(sender, plugin); + } +} diff --git a/src/main/java/cn/citycraft/Yum/api/YumApi.java b/src/main/java/cn/citycraft/Yum/api/YumApi.java deleted file mode 100644 index 4dfdf46..0000000 --- a/src/main/java/cn/citycraft/Yum/api/YumApi.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - */ -package cn.citycraft.Yum.api; - -import java.net.URL; - -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; - -import cn.citycraft.Yum.manager.YumManager; - -/** - * Yum仓库插件API - * - * @author 蒋天蓓 - * @since 2015年8月22日下午4:43:41 - */ -public class YumApi { - public static boolean update(final CommandSender sender, final Plugin plugin, final URL url, final String version) { - return YumManager.update(sender, plugin, url, version); - } -} diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandDelete.java b/src/main/java/cn/citycraft/Yum/commands/CommandDelete.java index 353071d..42220e2 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandDelete.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandDelete.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * 插件删除命令类 @@ -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 (YumManager.plugman.deletePlugin(sender, plugin)) { + if (YumAPI.plugman.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 5a60a39..1788332 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandInfo.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandInfo.java @@ -16,7 +16,7 @@ import org.bukkit.plugin.PluginDescriptionFile; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.PluginHelper.utils.StringUtil; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * 插件删除命令类 @@ -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" + YumManager.plugman.getPluginFile(plugin).getAbsolutePath()); + sender.sendMessage("§6插件物理路径: §3" + YumAPI.plugman.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], YumManager.plugman.getPluginNames(false), new ArrayList()); + return StringUtil.copyPartialMatches(args[1], YumAPI.plugman.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 f5465a0..1722996 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java @@ -15,7 +15,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.PluginHelper.utils.StringUtil; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * 插件安装命令类 @@ -45,9 +45,9 @@ public class CommandInstall extends BaseCommand { @Override public void run() { if (args.length < 2) { - YumManager.install(sender, pluginname); + YumAPI.installfromyum(sender, pluginname); } else { - YumManager.install(sender, pluginname, args[1]); + YumAPI.installfromyum(sender, pluginname, args[1]); } } }); @@ -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], YumManager.repo.getAllPluginName(), new ArrayList()); + return StringUtil.copyPartialMatches(args[1], YumAPI.repo.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 fe0c89d..456dd97 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandList.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandList.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * 插件查看命令类 @@ -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 - " + YumManager.plugman.getFormattedName(plugin, true)); + sender.sendMessage("§6 - " + YumAPI.plugman.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 afee23e..bfea42b 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * 插件删除命令类 @@ -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) { - YumManager.plugman.load(sender, pluginname); + YumAPI.plugman.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 350b5f5..94e85d1 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandReload.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandReload.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * 插件删除命令类 @@ -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("*")) { - YumManager.plugman.reloadAll(sender); + YumAPI.plugman.reloadAll(sender); return; } final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); if (plugin != null) { - YumManager.plugman.reload(sender, plugin); + YumAPI.plugman.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 b9715bb..d2e3fb3 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java @@ -14,7 +14,7 @@ import org.bukkit.command.CommandSender; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.PluginHelper.utils.StringUtil; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * 插件删除命令类 @@ -44,8 +44,8 @@ public class CommandRepo extends BaseCommand { switch (cmd) { case "add": if (args.length == 2) { - if (YumManager.repo.addRepositories(sender, args[1])) { - final String reponame = YumManager.repo.getRepoCache(args[1]).name; + if (YumAPI.repo.addRepositories(sender, args[1])) { + final String reponame = YumAPI.repo.getRepoCache(args[1]).name; sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!"); } else { sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!"); @@ -56,8 +56,8 @@ public class CommandRepo extends BaseCommand { break; case "del": if (args.length == 2) { - if (YumManager.repo.delRepositories(sender, args[1])) { - final String reponame = YumManager.repo.getRepoCache(args[1]).name; + if (YumAPI.repo.delRepositories(sender, args[1])) { + final String reponame = YumAPI.repo.getRepoCache(args[1]).name; sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!"); } else { sender.sendMessage("§6仓库: §c源地址未找到!"); @@ -68,18 +68,18 @@ public class CommandRepo extends BaseCommand { break; case "list": sender.sendMessage("§6仓库: §b缓存的插件信息如下 "); - StringUtil.sendStringArray(sender, YumManager.repo.getAllPluginsInfo()); + StringUtil.sendStringArray(sender, YumAPI.repo.getAllPluginsInfo()); break; case "all": sender.sendMessage("§6仓库: §b缓存的仓库信息如下 "); - StringUtil.sendStringArray(sender, YumManager.repo.getRepoCache().getAllRepoInfo()); + StringUtil.sendStringArray(sender, YumAPI.repo.getRepoCache().getAllRepoInfo()); break; case "clean": - YumManager.repo.clean(); + YumAPI.repo.clean(); sender.sendMessage("§6仓库: §a缓存的插件信息已清理!"); break; case "update": - YumManager.repo.updateRepositories(sender); + YumAPI.repo.updateRepositories(sender); sender.sendMessage("§6仓库: §a仓库缓存数据已更新!"); break; } @@ -94,7 +94,7 @@ public class CommandRepo extends BaseCommand { return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "clean", "update", "del" }), new ArrayList()); } if (args.length == 3 && (args[1] == "add" || args[1] == "del")) { - return StringUtil.copyPartialMatches(args[2], YumManager.repo.getRepos().keySet(), new ArrayList()); + return StringUtil.copyPartialMatches(args[2], YumAPI.repo.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 0ebde89..f6acaef 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * 插件删除命令类 @@ -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) { - YumManager.plugman.unload(sender, plugin); + YumAPI.plugman.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 dbb5af9..1f26475 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * @author 蒋天蓓 2015年8月12日下午2:04:05 @@ -40,9 +40,9 @@ public class CommandUpdate extends BaseCommand { @Override public void run() { if (args.length < 2) { - YumManager.update(sender, plugin); + YumAPI.updatefromyum(sender, plugin); } else { - YumManager.update(sender, plugin, args[1]); + YumAPI.updatefromyum(sender, plugin, args[1]); } } }); diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUpdateAll.java b/src/main/java/cn/citycraft/Yum/commands/CommandUpdateAll.java index 0944deb..628ec65 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUpdateAll.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUpdateAll.java @@ -7,11 +7,10 @@ import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * @author 蒋天蓓 2015年8月12日下午2:04:05 @@ -30,22 +29,12 @@ public class CommandUpdateAll extends BaseCommand { @Override public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { - final String pluginname = args[0]; - final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); - sender.sendMessage("§a开始更新服务器可更新插件"); - if (plugin != null) { - Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { - @Override - public void run() { - if (args.length < 2) { - YumManager.update(sender, plugin); - } else { - YumManager.update(sender, plugin, args[1]); - } - } - }); - } else { - sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!"); - } + sender.sendMessage("§d开始更新服务器可更新插件"); + Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { + @Override + public void run() { + YumAPI.updateall(sender); + } + }); }; } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUpgrade.java b/src/main/java/cn/citycraft/Yum/commands/CommandUpgrade.java index 7d8fd3d..d8d7a13 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUpgrade.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUpgrade.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.Yum.Yum; -import cn.citycraft.Yum.manager.YumManager; +import cn.citycraft.Yum.api.YumAPI; /** * @author 蒋天蓓 2015年8月12日下午2:04:05 @@ -35,13 +35,13 @@ public class CommandUpgrade extends BaseCommand { @Override public void run() { if (args.length == 0) { - YumManager.plugman.upgrade(sender); + YumAPI.plugman.upgrade(sender); } else { final String pluginname = args[0]; final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); sender.sendMessage("§a开始升级插件: " + pluginname); if (plugin != null) { - YumManager.plugman.upgrade(sender, plugin); + YumAPI.upgrade(sender, plugin); } else { sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!"); } diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java b/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java index 3587f0f..1a0fa07 100644 --- a/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java +++ b/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java @@ -25,6 +25,15 @@ public class PluginInfo { return String.format("%1$s-%2$s.jar", plugin.artifactId, version); } + /** + * 获取Maven仓库指定插件的下载地址 + * + * @param sender + * - 命令发送者 + * @param version + * - 需要更新的版本 + * @return 更新地址 + */ public String getMavenUrl(final CommandSender sender, final String version) { String ver = version; if (ver == null) { diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java index 35cbde8..bbe6cf8 100644 --- a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java @@ -363,7 +363,7 @@ public class PluginsManager { * * @param sender * - 命令发送者 - * @param plugin + * @param main * - 插件 * @return 是否成功 */ diff --git a/src/main/java/cn/citycraft/Yum/manager/YumManager.java b/src/main/java/cn/citycraft/Yum/manager/YumManager.java deleted file mode 100644 index e3d1cc6..0000000 --- a/src/main/java/cn/citycraft/Yum/manager/YumManager.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.citycraft.Yum.manager; - -import java.io.File; -import java.net.URL; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; - -/** - * 自动更新类 - * - * @author 蒋天蓓 - * 2015年9月1日上午10:59:47 - */ -public class YumManager { - public static DownloadManager download; - public static PluginsManager plugman; - public static RepositoryManager repo; - - protected static Plugin plugin; - - public YumManager(final Plugin plugin) { - YumManager.plugin = plugin; - plugman = new PluginsManager(plugin); - download = new DownloadManager(plugin); - repo = new RepositoryManager(plugin); - } - - public static boolean install(final CommandSender sender, final String pluginname) { - return install(sender, pluginname, null); - } - - public static boolean install(final CommandSender sender, final String pluginname, final String version) { - final PluginInfo pi = repo.getPlugin(pluginname); - if (pi != null) { - if (download.run(sender, pi.getMavenUrl(sender, version), new File("plugins", pi.name + ".jar"))) { - return plugman.load(sender, pluginname); - } - } - return false; - } - - public static boolean update(final CommandSender sender, final Plugin plugin) { - return update(sender, plugin, null); - } - - public static boolean update(final CommandSender sender, final Plugin plugin, final String version) { - final PluginInfo pi = repo.getPlugin(plugin.getName()); - if (pi != null) { - if (download.run(sender, pi.getMavenUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { - sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!"); - return true; - } - } else { - sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName()); - } - return false; - } - - public static boolean update(final CommandSender sender, final Plugin plugin, final URL url, final String version) { - if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { - sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!"); - return true; - } - return false; - } - - public static void updaterepo() { - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - repo.updateRepositories(Bukkit.getConsoleSender()); - } - }); - } -}