From 8b137104976615b6c346429fb2be294a430489ed Mon Sep 17 00:00:00 2001 From: 502647092 Date: Fri, 18 Sep 2015 08:30:35 +0800 Subject: [PATCH] Release Version... --- pom.xml | 2 +- .../citycraft/Yum/commands/CommandRepo.java | 2 +- .../cn/citycraft/Yum/manager/PluginInfo.java | 32 +++++++++++++++ .../citycraft/Yum/manager/Repositories.java | 40 +++++++++++++++++++ .../Yum/manager/RepositoryManager.java | 33 ++++++++------- .../cn/citycraft/Yum/manager/YumManager.java | 2 - .../cn/citycraft/Yum/repository/Package.java | 19 --------- .../cn/citycraft/Yum/repository/Plugin.java | 17 -------- .../citycraft/Yum/repository/PluginInfo.java | 26 ------------ .../citycraft/Yum/repository/Repository.java | 16 -------- 10 files changed, 92 insertions(+), 97 deletions(-) create mode 100644 src/main/java/cn/citycraft/Yum/manager/PluginInfo.java create mode 100644 src/main/java/cn/citycraft/Yum/manager/Repositories.java delete mode 100644 src/main/java/cn/citycraft/Yum/repository/Package.java delete mode 100644 src/main/java/cn/citycraft/Yum/repository/Plugin.java delete mode 100644 src/main/java/cn/citycraft/Yum/repository/PluginInfo.java delete mode 100644 src/main/java/cn/citycraft/Yum/repository/Repository.java diff --git a/pom.xml b/pom.xml index 195973d..f8822a3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft Yum - 1.3.2 + 1.4 Yum Minecraft 服务器插件管理系统 diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java index e2c2d39..e0cf8b4 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java @@ -32,7 +32,7 @@ public class CommandRepo extends BaseCommand { switch (cmd) { case "add": if (args.length == 2) { - if (YumManager.repo.addRepositories(args[1])) + if (YumManager.repo.addRepositories(sender, args[1])) sender.sendMessage("§6仓库: §a插件信息已缓存!"); else sender.sendMessage("§6仓库: §c源地址未找到仓库信息或无法访问!"); diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java b/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java new file mode 100644 index 0000000..ea9ce5f --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/manager/PluginInfo.java @@ -0,0 +1,32 @@ +package cn.citycraft.Yum.manager; + +import java.util.List; + +import cn.citycraft.Yum.manager.Repositories.Plugin; +import cn.citycraft.Yum.manager.Repositories.TagInfo; + +public class PluginInfo { + public Plugin plugin; + public String url; + public String repo; + public List tags; + + public String getFileName() { + return String.format("%1$s-%2$s.jar", plugin.artifactId, plugin.version); + } + + public String getMavenUrl() { + return getMavenUrl(null); + } + + public String getMavenUrl(String version) { + String ver = version; + if (ver == null && tags != null) + for (TagInfo tagInfo : tags) + if (tagInfo.tag.equalsIgnoreCase("1.7.10")) { + ver = tagInfo.version; + break; + } + 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); + } +} \ No newline at end of file diff --git a/src/main/java/cn/citycraft/Yum/manager/Repositories.java b/src/main/java/cn/citycraft/Yum/manager/Repositories.java new file mode 100644 index 0000000..e0e5495 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/manager/Repositories.java @@ -0,0 +1,40 @@ +/** + * + */ +package cn.citycraft.Yum.manager; + +import java.util.ArrayList; +import java.util.List; + +/** + * 源仓库序列化类 + * + * @author 蒋天蓓 + * 2015年8月31日下午7:41:53 + */ +public class Repositories { + public class PackageInfo { + public String name; + public String url; + public List plugins = new ArrayList<>(); + } + + public class Plugin { + public String groupId; + public String artifactId; + public String description; + public String version; + public List tags; + } + + public class Repository { + public String id; + public String url; + public String type; + } + + public class TagInfo { + public String tag; + 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 d2f220e..236af23 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map.Entry; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -20,10 +21,9 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; -import cn.citycraft.Yum.repository.Package; -import cn.citycraft.Yum.repository.Plugin; -import cn.citycraft.Yum.repository.PluginInfo; -import cn.citycraft.Yum.repository.Repository; +import cn.citycraft.Yum.manager.Repositories.PackageInfo; +import cn.citycraft.Yum.manager.Repositories.Plugin; +import cn.citycraft.Yum.manager.Repositories.Repository;; /** * 仓库管理类 @@ -44,22 +44,22 @@ public class RepositoryManager { repos = new ArrayList(); } - public boolean addPackage(String urlstring) { + public boolean addPackage(CommandSender sender, String urlstring) { String json = getHtml(urlstring); if (json == "") return false; - Package pkg = jsonToPackage(json); + PackageInfo pkg = jsonToPackage(json); if (pkg == null) return false; - updatePackage(pkg); + updatePackage(sender, pkg); return true; } - public boolean addRepositories(String urlstring) { + public boolean addRepositories(CommandSender sender, String urlstring) { if (urlstring == null || urlstring.isEmpty()) return false; repos.add(urlstring); - return updateRepositories(urlstring); + return updateRepositories(sender, urlstring); } public void cacheToJson(FileConfiguration config) { @@ -143,9 +143,9 @@ public class RepositoryManager { } } - public Package jsonToPackage(String json) { + public PackageInfo jsonToPackage(String json) { try { - return gson.fromJson(json, Package.class); + return gson.fromJson(json, PackageInfo.class); } catch (JsonSyntaxException e) { return null; } @@ -160,7 +160,7 @@ public class RepositoryManager { } } - public void updatePackage(Package pkg) { + public void updatePackage(CommandSender sender, PackageInfo pkg) { for (Plugin plugin : pkg.plugins) { PluginInfo pi = new PluginInfo(); pi.plugin = plugin; @@ -168,19 +168,22 @@ public class RepositoryManager { pi.repo = pkg.name; plugins.put(plugin.groupId + "." + plugin.artifactId, pi); } + sender.sendMessage("仓库: §e" + pkg.name + " §a更新成功!"); } public boolean updateRepositories(CommandSender sender) { plugins.clear(); for (String string : repos) - if (updateRepositories(string)) + if (updateRepositories(sender, string)) sender.sendMessage("§6源: §e" + string + " §a更新成功!"); else sender.sendMessage("§6源: §e" + string + " §c更新失败!"); return true; } - public boolean updateRepositories(String urlstring) { + public boolean updateRepositories(CommandSender sender, String urlstring) { + if (sender == null) + sender = Bukkit.getConsoleSender(); if (!urlstring.endsWith("repo.info")) urlstring = urlstring + "/repo.info"; String json = getHtml(urlstring); @@ -190,7 +193,7 @@ public class RepositoryManager { if (lrepo == null) return false; for (Repository repository : lrepo) - addPackage(repository.url); + addPackage(sender, repository.url); return true; } } diff --git a/src/main/java/cn/citycraft/Yum/manager/YumManager.java b/src/main/java/cn/citycraft/Yum/manager/YumManager.java index b7ea6bd..d5f221d 100644 --- a/src/main/java/cn/citycraft/Yum/manager/YumManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/YumManager.java @@ -6,8 +6,6 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; -import cn.citycraft.Yum.repository.PluginInfo; - /** * 自动更新类 * diff --git a/src/main/java/cn/citycraft/Yum/repository/Package.java b/src/main/java/cn/citycraft/Yum/repository/Package.java deleted file mode 100644 index ba258cc..0000000 --- a/src/main/java/cn/citycraft/Yum/repository/Package.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * - */ -package cn.citycraft.Yum.repository; - -import java.util.ArrayList; -import java.util.List; - -/** - * TODO - * - * @author 蒋天蓓 - * 2015年8月31日下午7:42:22 - */ -public class Package { - public String name; - public String url; - public List plugins = new ArrayList<>(); -} diff --git a/src/main/java/cn/citycraft/Yum/repository/Plugin.java b/src/main/java/cn/citycraft/Yum/repository/Plugin.java deleted file mode 100644 index 3b4c9ef..0000000 --- a/src/main/java/cn/citycraft/Yum/repository/Plugin.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * - */ -package cn.citycraft.Yum.repository; - -/** - * TODO - * - * @author 蒋天蓓 - * 2015年8月31日下午7:42:54 - */ -public class Plugin { - public String groupId; - public String artifactId; - public String description; - public String version; -} diff --git a/src/main/java/cn/citycraft/Yum/repository/PluginInfo.java b/src/main/java/cn/citycraft/Yum/repository/PluginInfo.java deleted file mode 100644 index 280d482..0000000 --- a/src/main/java/cn/citycraft/Yum/repository/PluginInfo.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.citycraft.Yum.repository; - -/** - * TODO - * - * @author 蒋天蓓 - * 2015年8月31日下午7:43:19 - */ -public class PluginInfo { - public Plugin plugin; - public String url; - public String repo; - - public String getMavenUrl() { - return getMavenUrl(null); - } - - public String getMavenUrl(String version) { - return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", plugin.groupId.replace(".", "/"), - plugin.artifactId, version == null ? plugin.version : version); - } - - public String getFileName() { - return String.format("%1$s-%2$s.jar", plugin.artifactId, plugin.version); - } -} diff --git a/src/main/java/cn/citycraft/Yum/repository/Repository.java b/src/main/java/cn/citycraft/Yum/repository/Repository.java deleted file mode 100644 index 0ea12a3..0000000 --- a/src/main/java/cn/citycraft/Yum/repository/Repository.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * - */ -package cn.citycraft.Yum.repository; - -/** - * TODO - * - * @author 蒋天蓓 - * 2015年8月31日下午7:41:53 - */ -public class Repository { - public String id; - public String url; - public String type; -}