From 31cb47578fe9446cd8adfc1d764d02928f94ea38 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Thu, 19 Nov 2015 16:47:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=AC=E5=8A=9F=E8=83=BD?= =?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 +- .../cn/citycraft/Yum/manager/PluginInfo.java | 43 ++++++++++++++----- .../citycraft/Yum/manager/PluginsManager.java | 6 +-- .../Yum/manager/RepoSerialization.java | 3 ++ .../Yum/manager/RepositoryManager.java | 9 ++-- .../cn/citycraft/Yum/manager/YumManager.java | 4 +- 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index a67ea36..6b3968c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft Yum - 1.8 + 1.8.1 Yum Minecraft 服务器插件管理系统 @@ -55,7 +55,7 @@ http://ci.citycraft.cn:8080 - &c大版本更新 &a全版本兼容... + &b新增自动获取最新版本功能... UTF-8 diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java b/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java index da81788..dab6b26 100644 --- a/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java +++ b/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java @@ -2,33 +2,56 @@ package cn.citycraft.Yum.manager; import java.util.List; +import org.bukkit.command.CommandSender; + +import cn.citycraft.PluginHelper.utils.IOUtil; import cn.citycraft.Yum.manager.RepoSerialization.Plugin; import cn.citycraft.Yum.manager.RepoSerialization.TagInfo; public class PluginInfo { + public String branch; + public String name; public Plugin plugin; + public String pom; public String repo; public List tags; public String url; public String getFileName() { - return String.format("%1$s-%2$s.jar", plugin.artifactId, plugin.version); + return getFileName(plugin.version); } - public String getMavenUrl() { - return getMavenUrl(null); + public String getFileName(final String version) { + return String.format("%1$s-%2$s.jar", plugin.artifactId, version); } - public String getMavenUrl(final String version) { + public String getMavenUrl(final CommandSender sender, final String version) { String ver = version; - if (ver == null && tags != null) { - for (final TagInfo tagInfo : tags) { - if (tagInfo.tag.equalsIgnoreCase("1.7.10")) { - ver = tagInfo.version; - break; + if (ver == null) { + if (tags != null) { + for (final TagInfo tagInfo : tags) { + if (tagInfo.tag.equalsIgnoreCase("1.7.10")) { + sender.sendMessage("§6版本: §b从Tag标签中获取最新版本..."); + ver = tagInfo.version; + break; + } + } + } else if (pom != null && !pom.isEmpty()) { + pom = pom.replace("[name]", plugin.name).replace("[branch]", branch); + sender.sendMessage("§6版本: §b尝试从在线POM文件获取最新版本..."); + ver = IOUtil.getXMLTag(pom, "version", plugin.version); + if (ver != null) { + sender.sendMessage("§6版本: §a成功获取到最新版本 " + ver + " ..."); } } } - return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", plugin.groupId.replace(".", "/"), plugin.artifactId, ver == null ? plugin.version : ver); + if (ver == null) { + ver = plugin.version; + sender.sendMessage("§6版本: §a使用缓存的版本 " + ver + " ..."); + } + return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", + plugin.groupId.replace(".", "/"), + plugin.artifactId, + (ver == null || ver.isEmpty()) ? plugin.version : ver); } } \ No newline at end of file diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java index eb03427..35cbde8 100644 --- a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java @@ -309,7 +309,7 @@ public class PluginsManager { target = Bukkit.getPluginManager().loadPlugin(pluginFile); } catch (final InvalidDescriptionException e) { sender.sendMessage("§4异常: §c" + e.getMessage()); - sender.sendMessage("§c插件: " + name + " 的plugin.yml文件存在错误!"); + sender.sendMessage("§c插件: " + name + " 的 plugin.yml 文件存在错误!"); return false; } catch (final UnsupportedClassVersionError e) { sender.sendMessage("§4异常: §c" + e.getMessage()); @@ -320,8 +320,8 @@ public class PluginsManager { sender.sendMessage("§c文件: " + name + " 不是一个可载入的插件!"); return false; } catch (final UnknownDependencyException e) { - sender.sendMessage("§4异常: §c" + e.getMessage()); - sender.sendMessage("§c插件: " + name + " 缺少部分依赖项目!"); + sender.sendMessage("§4异常: §c服务器未安装必须依赖: " + e.getMessage()); + sender.sendMessage("§c插件: " + name + " 载入失败 缺少部分依赖项目!"); return false; } diff --git a/src/main/java/cn/citycraft/Yum/manager/RepoSerialization.java b/src/main/java/cn/citycraft/Yum/manager/RepoSerialization.java index f844c17..5115c01 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepoSerialization.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepoSerialization.java @@ -16,14 +16,17 @@ public class RepoSerialization { public class PackageInfo { public String name; public List plugins = new ArrayList<>(); + public String pom; public String url; } public class Plugin { public String artifactId; + public String branch; public String description; public String groupId; public String name; + public String pom; public List tags; public String version; } diff --git a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java index 96791dd..f86486b 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java @@ -89,7 +89,7 @@ public class RepositoryManager { public List getAllPluginName() { final List li = new ArrayList(); for (final Entry plugin : repocache.getPlugins().entrySet()) { - li.add(plugin.getValue().plugin.name); + li.add(plugin.getValue().name); } return li; } @@ -105,7 +105,7 @@ public class RepositoryManager { public PluginInfo getPlugin(final String name) { for (final Entry plugin : repocache.getPlugins().entrySet()) { - if (plugin.getValue().plugin.name.equalsIgnoreCase(name)) { + if (plugin.getValue().name.equalsIgnoreCase(name)) { return plugin.getValue(); } } @@ -115,7 +115,7 @@ public class RepositoryManager { public List getPluginInfo(final String name) { final List li = new ArrayList(); for (final Entry plugin : repocache.getPlugins().entrySet()) { - if (plugin.getValue().plugin.name.equalsIgnoreCase(name)) { + if (plugin.getValue().name.equalsIgnoreCase(name)) { li.add(plugin.getValue()); } } @@ -161,6 +161,9 @@ public class RepositoryManager { public void updatePackage(final CommandSender sender, final PackageInfo pkg) { for (final Plugin plugin : pkg.plugins) { final PluginInfo pi = new PluginInfo(); + pi.name = plugin.name == null ? plugin.artifactId : plugin.name; + pi.branch = plugin.branch == null ? "master" : plugin.branch; + pi.pom = plugin.pom == null ? pkg.pom : plugin.pom; pi.plugin = plugin; pi.url = pkg.url; pi.repo = pkg.name; diff --git a/src/main/java/cn/citycraft/Yum/manager/YumManager.java b/src/main/java/cn/citycraft/Yum/manager/YumManager.java index 16134a8..d63949e 100644 --- a/src/main/java/cn/citycraft/Yum/manager/YumManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/YumManager.java @@ -34,7 +34,7 @@ public class YumManager { 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(version), new File("plugins", pi.plugin.name + ".jar"))) { + if (download.run(sender, pi.getMavenUrl(sender, version), new File("plugins", pi.plugin.name + ".jar"))) { return plugman.load(sender, pluginname); } } @@ -48,7 +48,7 @@ public class YumManager { 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(version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { + 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; }