diff --git a/.classpath b/.classpath index 9644a24..29fe624 100644 --- a/.classpath +++ b/.classpath @@ -27,10 +27,5 @@ - - - - - diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml deleted file mode 100644 index 9536a39..0000000 --- a/dependency-reduced-pom.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - 4.0.0 - cn.citycraft - Yum - Yum - 1.3.2 - Minecraft 服务器插件管理系统 - - - - true - src/main/resources - - - ${project.name} - - - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - maven-shade-plugin - 2.3 - - - package - - shade - - - - - - - cn.citycraft:PluginUtils - - - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - citycraft-repo - http://ci.citycraft.cn:8800/jenkins/plugin/repository/everything/ - - - - - org.spigotmc - spigot-api - 1.8.3-R0.1-SNAPSHOT - compile - - - - UTF-8 - - - diff --git a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java index 09b1d34..d2f220e 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java @@ -15,16 +15,16 @@ import java.util.Map.Entry; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; -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 com.google.common.base.Charsets; 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; + /** * 仓库管理类 * @@ -44,18 +44,22 @@ public class RepositoryManager { repos = new ArrayList(); } - public void clean() { - plugins.clear(); + public boolean addPackage(String urlstring) { + String json = getHtml(urlstring); + if (json == "") + return false; + Package pkg = jsonToPackage(json); + if (pkg == null) + return false; + updatePackage(pkg); + return true; } - public void updatePackage(Package pkg) { - for (Plugin plugin : pkg.plugins) { - PluginInfo pi = new PluginInfo(); - pi.plugin = plugin; - pi.url = pkg.url; - pi.repo = pkg.name; - plugins.put(plugin.groupId + "." + plugin.artifactId, pi); - } + public boolean addRepositories(String urlstring) { + if (urlstring == null || urlstring.isEmpty()) + return false; + repos.add(urlstring); + return updateRepositories(urlstring); } public void cacheToJson(FileConfiguration config) { @@ -63,6 +67,66 @@ public class RepositoryManager { config.set("plugincache", gson.toJson(plugins)); } + public void clean() { + plugins.clear(); + } + + public List getAllPlugin() { + List li = new ArrayList(); + for (Entry plugin : plugins.entrySet()) + li.add(plugin.getValue()); + return li; + } + + public List getAllPluginName() { + List li = new ArrayList(); + for (Entry plugin : plugins.entrySet()) + li.add(plugin.getValue().plugin.artifactId); + return li; + } + + public List getAllPluginsInfo() { + List li = new ArrayList(); + for (Entry plugin : plugins.entrySet()) { + Plugin pl = plugin.getValue().plugin; + li.add(String.format("§d%s §a%s(%s) §6- §e%s", plugin.getValue().repo, pl.artifactId, pl.version, pl.description)); + } + return li; + } + + public String getHtml(String urlstring) { + String html = ""; + try { + URL url = new URL(urlstring); + BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8)); + String line; + while ((line = br.readLine()) != null) + html += line; + return html; + } catch (IOException e) { + return null; + } + } + + public PluginInfo getPlugin(String name) { + for (Entry plugin : plugins.entrySet()) + if (plugin.getValue().plugin.artifactId.equalsIgnoreCase(name)) + return plugin.getValue(); + return null; + } + + public List getPluginInfo(String name) { + List li = new ArrayList(); + for (Entry plugin : plugins.entrySet()) + if (plugin.getValue().plugin.artifactId.equalsIgnoreCase(name)) + li.add(plugin.getValue()); + return li; + } + + public PluginInfo getPluginInfo(String groupId, String artifactId) { + return plugins.get(groupId + "." + artifactId); + } + public boolean jsonToCache(FileConfiguration config) { String repocache = config.getString("repocache"); String plugincache = config.getString("plugincache"); @@ -79,112 +143,14 @@ public class RepositoryManager { } } - public boolean updateRepositories(CommandSender sender) { - plugins.clear(); - for (String string : repos) { - if (updateRepositories(string)) { - sender.sendMessage("§6源: §e" + string + " §a更新成功!"); - } else { - sender.sendMessage("§6源: §e" + string + " §c更新失败!"); - } - } - return true; - } - - public boolean addRepositories(String urlstring) { - repos.add(urlstring); - return updateRepositories(urlstring); - } - - public boolean updateRepositories(String urlstring) { - String json = getHtml(urlstring); - if (json == "") { - return false; - } - List lrepo = jsonToRepositories(json); - if (lrepo == null) { - return false; - } - for (Repository repository : lrepo) { - addPackage(repository.url); - } - return true; - } - - public boolean addPackage(String urlstring) { - String json = getHtml(urlstring); - if (json == "") { - return false; - } - Package pkg = jsonToPackage(json); - if (pkg == null) { - return false; - } - updatePackage(pkg); - return true; - } - - public String getHtml(String urlstring) { - String html = ""; + public Package jsonToPackage(String json) { try { - URL url = new URL(urlstring); - BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8)); - String line; - while ((line = br.readLine()) != null) { - html += line; - } - return html; - } catch (IOException e) { + return gson.fromJson(json, Package.class); + } catch (JsonSyntaxException e) { return null; } } - public PluginInfo getPluginInfo(String groupId, String artifactId) { - return plugins.get(groupId + "." + artifactId); - } - - public PluginInfo getPlugin(String name) { - for (Entry plugin : plugins.entrySet()) { - if (plugin.getValue().plugin.artifactId.equalsIgnoreCase(name)) - return plugin.getValue(); - } - return null; - } - - public List getAllPlugin() { - List li = new ArrayList(); - for (Entry plugin : plugins.entrySet()) { - li.add(plugin.getValue()); - } - return li; - } - - public List getAllPluginName() { - List li = new ArrayList(); - for (Entry plugin : plugins.entrySet()) { - li.add(plugin.getValue().plugin.artifactId); - } - return li; - } - - public List getAllPluginsInfo() { - List li = new ArrayList(); - for (Entry plugin : plugins.entrySet()) { - Plugin pl = plugin.getValue().plugin; - li.add(String.format("§d%s §a%s(%s) §6- §e%s", plugin.getValue().repo, pl.artifactId, pl.version, pl.description)); - } - return li; - } - - public List getPluginInfo(String name) { - List li = new ArrayList(); - for (Entry plugin : plugins.entrySet()) { - if (plugin.getValue().plugin.artifactId.equalsIgnoreCase(name)) - li.add(plugin.getValue()); - } - return li; - } - public List jsonToRepositories(String json) { try { return gson.fromJson(json, new TypeToken>() { @@ -194,11 +160,37 @@ public class RepositoryManager { } } - public Package jsonToPackage(String json) { - try { - return gson.fromJson(json, Package.class); - } catch (JsonSyntaxException e) { - return null; + public void updatePackage(Package pkg) { + for (Plugin plugin : pkg.plugins) { + PluginInfo pi = new PluginInfo(); + pi.plugin = plugin; + pi.url = pkg.url; + pi.repo = pkg.name; + plugins.put(plugin.groupId + "." + plugin.artifactId, pi); } } + + public boolean updateRepositories(CommandSender sender) { + plugins.clear(); + for (String string : repos) + if (updateRepositories(string)) + sender.sendMessage("§6源: §e" + string + " §a更新成功!"); + else + sender.sendMessage("§6源: §e" + string + " §c更新失败!"); + return true; + } + + public boolean updateRepositories(String urlstring) { + if (!urlstring.endsWith("repo.info")) + urlstring = urlstring + "/repo.info"; + String json = getHtml(urlstring); + if (json == "") + return false; + List lrepo = jsonToRepositories(json); + if (lrepo == null) + return false; + for (Repository repository : lrepo) + addPackage(repository.url); + return true; + } }