From 63dda660c87199c784ed20aec65c087bd216673b Mon Sep 17 00:00:00 2001 From: 502647092 Date: Sat, 12 Dec 2015 18:15:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9B=B4=E9=93=BE=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=A8=A1=E5=BC=8F...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/cn/citycraft/Yum/api/YumAPI.java | 4 +- .../cn/citycraft/Yum/manager/PluginInfo.java | 61 +++++++++++++++++-- .../Yum/manager/RepoSerialization.java | 9 +++ .../Yum/manager/RepositoryManager.java | 4 +- 4 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/main/java/cn/citycraft/Yum/api/YumAPI.java b/src/main/java/cn/citycraft/Yum/api/YumAPI.java index 1de41a8..c31f148 100644 --- a/src/main/java/cn/citycraft/Yum/api/YumAPI.java +++ b/src/main/java/cn/citycraft/Yum/api/YumAPI.java @@ -139,7 +139,7 @@ public class YumAPI { 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 install(sender, pi.name, pi.getUrl(sender, version)); } return false; } @@ -286,7 +286,7 @@ public class YumAPI { 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()))) { + if (download.run(sender, pi.getUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹"); sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!"); return true; diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java b/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java index 375d88e..3624bff 100644 --- a/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java +++ b/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java @@ -8,6 +8,7 @@ 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; +import cn.citycraft.Yum.manager.RepoSerialization.URLType; public class PluginInfo { public static final String NMSVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; @@ -16,14 +17,53 @@ public class PluginInfo { public String name; public Plugin plugin; public String pom; + public URLType type; public String repo; public List tags; public String url; + /** + * 获得下载直链 + * + * @param sender + * 命令发送者 + * @param version + * 版本 + * @return 下载直链 + */ + public String getDirectUrl() { + return url; + } + + /** + * 获得下载直链 + * + * @param sender + * 命令发送者 + * @param version + * 版本 + * @return 下载直链 + */ + public String getDirectUrl(final String version) { + return url.replace("[version]", version); + } + + /** + * 获得文件名称 + * + * @return 文件名称 + */ public String getFileName() { return getFileName(plugin.version); } + /** + * 获得文件名称 + * + * @param version + * 插件版本 + * @return 文件名称 + */ public String getFileName(final String version) { return String.format("%1$s-%2$s.jar", plugin.artifactId, version); } @@ -37,7 +77,14 @@ public class PluginInfo { * - 需要更新的版本 * @return 更新地址 */ - public String getMavenUrl(final CommandSender sender, final String version) { + public String getMavenUrl(final String 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); + } + + public String getUrl(final CommandSender sender, final String version) { String ver = version; if (ver == null) { if (tags != null) { @@ -61,9 +108,13 @@ public class PluginInfo { ver = plugin.version; sender.sendMessage("§6版本: §a使用缓存的版本 §e" + ver + " §a..."); } - 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); + switch (type) { + case DirectUrl: + return getDirectUrl(ver); + case Maven: + return getMavenUrl(ver); + default: + return null; + } } } \ No newline at end of file diff --git a/src/main/java/cn/citycraft/Yum/manager/RepoSerialization.java b/src/main/java/cn/citycraft/Yum/manager/RepoSerialization.java index 5115c01..965bdbf 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepoSerialization.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepoSerialization.java @@ -18,6 +18,7 @@ public class RepoSerialization { public List plugins = new ArrayList<>(); public String pom; public String url; + public String type; } public class Plugin { @@ -26,9 +27,11 @@ public class RepoSerialization { public String description; public String groupId; public String name; + public String url; public String pom; public List tags; public String version; + public String type; } public class Repositories { @@ -45,5 +48,11 @@ public class RepoSerialization { public class TagInfo { public String tag; public String version; + public String url; + } + + public enum URLType { + Maven, + DirectUrl; } } diff --git a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java index bc09438..e918898 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java @@ -23,6 +23,7 @@ import cn.citycraft.Yum.manager.RepoSerialization.PackageInfo; import cn.citycraft.Yum.manager.RepoSerialization.Plugin; import cn.citycraft.Yum.manager.RepoSerialization.Repositories; import cn.citycraft.Yum.manager.RepoSerialization.Repository; +import cn.citycraft.Yum.manager.RepoSerialization.URLType; /** * 仓库管理类 @@ -178,8 +179,9 @@ public class RepositoryManager { pi.name = StringUtil.getNotNull(plugin.name, plugin.artifactId); pi.branch = StringUtil.getNotNull(plugin.branch, "master"); pi.pom = StringUtil.getNotNull(plugin.pom, pkg.pom); + pi.url = StringUtil.getNotNull(plugin.url, pkg.url); + pi.type = URLType.valueOf(StringUtil.getNotNull(StringUtil.getNotNull(plugin.type, pkg.type), URLType.Maven.name())); pi.plugin = plugin; - pi.url = pkg.url; pi.repo = pkg.name; repocache.getPlugins().put(plugin.groupId + "." + plugin.artifactId, pi); }