From d53a27fb4087591bc2010367547a4810ba5acbd9 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Sat, 22 Aug 2015 16:40:38 +0800 Subject: [PATCH] async install plugin and fix install command... --- .../Yum/commands/CommandInstall.java | 17 ++++++++++------ .../citycraft/Yum/commands/CommandUpdate.java | 20 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java b/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java index 73ab672..20b5118 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandInstall.java @@ -33,13 +33,18 @@ public class CommandInstall extends BaseCommand { }; @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - String pluginname = args[0]; + public void execute(final CommandSender sender, String label, String[] args) throws CommandException { + final String pluginname = args[0]; Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); - if (plugin != null) { - if (yum.download.run(sender, pluginname)) { - sender.sendMessage(PluginsManager.load(pluginname)); - } + if (plugin == null) { + Bukkit.getScheduler().runTaskAsynchronously(yum, new Runnable() { + @Override + public void run() { + if (yum.download.run(sender, pluginname)) { + sender.sendMessage(PluginsManager.load(pluginname)); + } + } + }); } else { sender.sendMessage("§c插件已安装在服务器 需要更新请使用yum update " + pluginname + "!"); } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java b/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java index 70e9fe3..56cea74 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUpdate.java @@ -31,15 +31,21 @@ public class CommandUpdate extends BaseCommand { }; @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - String pluginname = args[0]; - Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); + public void execute(final CommandSender sender, String label, String[] args) throws CommandException { + final String pluginname = args[0]; + final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); sender.sendMessage("§a开始更新插件: " + pluginname); if (plugin != null) { - sender.sendMessage(PluginsManager.unload(plugin)); - if (yum.download.run(sender, pluginname)) { - sender.sendMessage(PluginsManager.load(pluginname)); - } + Bukkit.getScheduler().runTaskAsynchronously(yum, new Runnable() { + @Override + public void run() { + sender.sendMessage(PluginsManager.unload(plugin)); + PluginsManager.getPluginFile(plugin).delete(); + if (yum.download.run(sender, pluginname)) { + sender.sendMessage(PluginsManager.load(pluginname)); + } + } + }); } else { sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!"); }