From 8f8e3b3465fd2e791cdf4c76c066e47065b8bab6 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 1 Sep 2015 15:42:53 +0800 Subject: [PATCH] add update force version... Signed-off-by: 502647092 --- .../cn/citycraft/Yum/commands/CommandUpdate.java | 16 ++++++++++++---- .../cn/citycraft/Yum/repository/PluginInfo.java | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java b/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java index bef7f26..68bafb0 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java @@ -26,7 +26,7 @@ public class CommandUpdate extends BaseCommand { } @Override - public void execute(final CommandSender sender, String label, String[] args) throws CommandException { + public void execute(final CommandSender sender, String label, final String[] args) throws CommandException { final String pluginname = args[0]; final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); sender.sendMessage("§a开始更新插件: " + pluginname); @@ -35,12 +35,20 @@ public class CommandUpdate extends BaseCommand { @Override public void run() { PluginInfo pi = main.repo.getPlugin(pluginname); - if (pi != null) - if (main.download.run(sender, pi.getMavenUrl(), main.plugman.getPluginFile(plugin))) { + if (pi != null) { + String fileurl; + if (args.length < 2) { + fileurl = pi.getMavenUrl(); + } else { + fileurl = pi.getMavenUrl(args[1]); + } + if (main.download.run(sender, fileurl, main.plugman.getPluginFile(plugin))) { if (main.plugman.unload(sender, plugin)) { main.plugman.load(sender, pluginname); } } + } + } }); } else { @@ -55,7 +63,7 @@ public class CommandUpdate extends BaseCommand { @Override public String getPossibleArguments() { - return "<插件名称>"; + return "<插件名称> <插件版本>"; } @Override diff --git a/src/main/java/cn/citycraft/Yum/repository/PluginInfo.java b/src/main/java/cn/citycraft/Yum/repository/PluginInfo.java index 6c30281..976b65f 100644 --- a/src/main/java/cn/citycraft/Yum/repository/PluginInfo.java +++ b/src/main/java/cn/citycraft/Yum/repository/PluginInfo.java @@ -16,6 +16,11 @@ public class PluginInfo { plugin.artifactId, plugin.version); } + 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); + } + public String getFileName() { return String.format("%1$s-%2$s.jar", plugin.artifactId, plugin.version); }