From 281e09b496d532e18878e27ac1a6a524f44bf806 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 24 Nov 2015 20:55:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=9B=BD=E5=86=85=E6=BA=90?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=20=E6=B7=BB=E5=8A=A0=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=91=BD=E4=BB=A4...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 4 +- .../citycraft/Yum/commands/CommandRepo.java | 14 ++++-- .../cn/citycraft/Yum/manager/RepoCache.java | 11 +++++ .../Yum/manager/RepositoryManager.java | 47 ++++++++++++++----- 4 files changed, 59 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 8d8003e..9ad9603 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft Yum - 1.8.2 + 1.8.3 Yum Minecraft 服务器插件管理系统 @@ -55,7 +55,7 @@ http://ci.citycraft.cn:8080 - &c修复自动获取版本错误... + &b默认使用国内源数据 添加仓库查看命令... UTF-8 diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java index 6bfb699..27c2206 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 { this.main = main; setMinimumArguments(1); setDescription("插件源命令"); - setPossibleArguments(" <仓库名称>"); + setPossibleArguments(" <仓库名称>"); } @Override @@ -45,7 +45,8 @@ public class CommandRepo extends BaseCommand { case "add": if (args.length == 2) { if (YumManager.repo.addRepositories(sender, args[1])) { - sender.sendMessage("§6仓库: §a§a源地址 " + args[1] + " 的插件信息已缓存!"); + final String reponame = YumManager.repo.getRepoCache(args[1]).name; + sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!"); } else { sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!"); } @@ -56,7 +57,8 @@ public class CommandRepo extends BaseCommand { case "del": if (args.length == 2) { if (YumManager.repo.delRepositories(sender, args[1])) { - sender.sendMessage("§6仓库: §a源地址 " + args[1] + " 已删除 请使用 yum repo update 更新缓存!"); + final String reponame = YumManager.repo.getRepoCache(args[1]).name; + sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!"); } else { sender.sendMessage("§6仓库: §c源地址未找到!"); } @@ -68,6 +70,10 @@ public class CommandRepo extends BaseCommand { sender.sendMessage("§6仓库: §b缓存的插件信息如下 "); StringUtil.sendStringArray(sender, YumManager.repo.getAllPluginsInfo()); break; + case "all": + sender.sendMessage("§6仓库: §b缓存的仓库信息如下 "); + StringUtil.sendStringArray(sender, YumManager.repo.getRepoCache().getAllRepoInfo()); + break; case "clean": YumManager.repo.clean(); sender.sendMessage("§6仓库: §a缓存的插件信息已清理!"); @@ -85,7 +91,7 @@ public class CommandRepo extends BaseCommand { public List onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { if (args[0].equalsIgnoreCase("repo")) { if (args.length == 2) { - return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "list", "clean", "update", "del" }), new ArrayList()); + 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()); diff --git a/src/main/java/cn/citycraft/Yum/manager/RepoCache.java b/src/main/java/cn/citycraft/Yum/manager/RepoCache.java index 5bedcd2..44f42de 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepoCache.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepoCache.java @@ -1,7 +1,10 @@ package cn.citycraft.Yum.manager; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import cn.citycraft.PluginHelper.jsonresult.JsonResult; import cn.citycraft.PluginHelper.utils.IOUtil; @@ -33,6 +36,14 @@ public class RepoCache { } + public List getAllRepoInfo() { + final List repoinfo = new ArrayList(); + for (final Entry repo : repos.entrySet()) { + repoinfo.add(String.format("§d仓库: §e%s §6- §3%s", repo.getValue().name, repo.getKey())); + } + return repoinfo; + } + public Map getPlugins() { return plugins; } diff --git a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java index b05f1dc..b7fd73c 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java @@ -52,15 +52,8 @@ public class RepositoryManager { } public boolean addRepositories(final CommandSender sender, final String urlstring) { - final int urllength = urlstring.length(); - String url = urlstring.substring(0, urlstring.endsWith("/") ? urllength - 1 : urllength); - if (!url.startsWith("http://")) { - url = "http://" + url; - } - if (!url.endsWith("repo.info")) { - url = url + "/repo.info"; - } - final Repositories repo = repocache.addRepo(urlstring); + final String url = handerRepoUrl(urlstring); + final Repositories repo = repocache.addRepo(url); if (repo == null) { return false; } @@ -76,7 +69,7 @@ public class RepositoryManager { } public boolean delRepositories(final CommandSender sender, final String urlstring) { - return repocache.removeRepo(urlstring); + return repocache.removeRepo(handerRepoUrl(urlstring)); } public List getAllPlugin() { @@ -131,10 +124,29 @@ public class RepositoryManager { return repocache.getPlugins(); } + public RepoCache getRepoCache() { + return repocache; + } + + public Repositories getRepoCache(final String urlstring) { + return repocache.repos.get(handerRepoUrl(urlstring)); + } + public Map getRepos() { return repocache.getRepos(); } + public boolean getRepositories(final CommandSender sender, final String urlstring) { + final int urllength = urlstring.length(); + final String url = urlstring.substring(0, urlstring.endsWith("/") ? urllength - 1 : urllength); + handerRepoUrl(url); + final Repositories repo = repocache.addRepo(urlstring); + if (repo == null) { + return false; + } + return updateRepositories(sender, repo); + } + public boolean jsonToCache(final FileConfiguration config) { try { final String reposcache = config.getString("reposcache"); @@ -176,7 +188,7 @@ public class RepositoryManager { public boolean updateRepositories(final CommandSender sender) { repocache.getPlugins().clear(); if (repocache.getRepos().isEmpty()) { - repocache.addRepo("http://citycraft.cn/yumcenter/repo.info"); + repocache.addRepo("https://coding.net/u/502647092/p/YumData/git/raw/master/yumcenter/repo.info"); } final Iterator> keys = repocache.getRepos().entrySet().iterator(); while (keys.hasNext()) { @@ -204,4 +216,17 @@ public class RepositoryManager { } return true; } + + private String handerRepoUrl(String url) { + final int urllength = url.length(); + url = url.substring(0, url.endsWith("/") ? urllength - 1 : urllength); + if (!url.startsWith("http://")) { + url = "http://" + url; + } + if (!url.endsWith("repo.info")) { + url = url + "/repo.info"; + } + return url; + } + }