diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java index e5863b8..b2b0ac5 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java @@ -45,12 +45,23 @@ public class CommandRepo extends BaseCommand { case "add": if (args.length == 2) { if (YumManager.repo.addRepositories(sender, args[1])) { - sender.sendMessage("§6仓库: §a插件信息已缓存!"); + sender.sendMessage("§6仓库: §a§a源地址 " + args[1] + " 的插件信息已缓存!"); } else { - sender.sendMessage("§6仓库: §c源地址未找到仓库信息或无法访问!"); + sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!"); } } else { - sender.sendMessage("§6仓库: §c请输入源地址!"); + sender.sendMessage("§6仓库: §c请输入需要添加的源地址!"); + } + break; + case "del": + if (args.length == 2) { + if (YumManager.repo.delRepositories(sender, args[1])) { + sender.sendMessage("§6仓库: §a源地址 " + args[1] + " 已删除 请使用 yum repo update 更新缓存!"); + } else { + sender.sendMessage("§6仓库: §c源地址未找到!"); + } + } else { + sender.sendMessage("§6仓库: §c请输入需要删除的源地址!"); } break; case "list": @@ -73,7 +84,12 @@ public class CommandRepo extends BaseCommand { @Override public List onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { if (args[0].equalsIgnoreCase("repo")) { - return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "list", "clean", "update" }), new ArrayList()); + if (args.length == 2) { + return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "list", "clean", "update", "del" }), new ArrayList()); + } + if (args.length == 3 && (args[1] == "add" || args[1] == "del")) { + return StringUtil.copyPartialMatches(args[2], YumManager.repo.getRepos(), new ArrayList()); + } } return null; } diff --git a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java index 19fd1d8..924f7d0 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java @@ -58,7 +58,8 @@ public class RepositoryManager { } public boolean addRepositories(final CommandSender sender, final String urlstring) { - if (urlstring.isEmpty()) { + final int urllength = urlstring.length(); + if (urllength == 0 || repos.contains(urlstring.substring(0, urlstring.endsWith("/") ? urllength - 1 : urllength))) { return false; } repos.add(urlstring); @@ -74,6 +75,14 @@ public class RepositoryManager { plugins.clear(); } + public boolean delRepositories(final CommandSender sender, final String urlstring) { + if (urlstring.isEmpty() || !repos.contains(urlstring)) { + return false; + } + repos.remove(urlstring); + return true; + } + public List getAllPlugin() { final List li = new ArrayList(); for (final Entry plugin : plugins.entrySet()) { @@ -137,6 +146,14 @@ public class RepositoryManager { return plugins.get(groupId + "." + artifactId); } + public HashMap getPlugins() { + return plugins; + } + + public List getRepos() { + return repos; + } + public boolean jsonToCache(final FileConfiguration config) { final String repocache = config.getString("repocache"); final String plugincache = config.getString("plugincache");