From 0dd488bd159672c7194e165de571047e79f697c9 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Sat, 22 Aug 2015 16:55:46 +0800 Subject: [PATCH] add YumApi... --- .../java/cn/citycraft/Yum/api/YumApi.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/main/java/cn/citycraft/Yum/api/YumApi.java diff --git a/src/main/java/cn/citycraft/Yum/api/YumApi.java b/src/main/java/cn/citycraft/Yum/api/YumApi.java new file mode 100644 index 0000000..b923861 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/api/YumApi.java @@ -0,0 +1,65 @@ +/** + * + */ +package cn.citycraft.Yum.api; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; + +import cn.citycraft.Yum.utils.DownloadManager; +import cn.citycraft.Yum.utils.PluginsManager; + +/** + * Yum仓库插件API + * + * @author 蒋天蓓 + * 2015年8月22日下午4:43:41 + */ +public class YumApi { + + public static void install(Plugin yum, final String pluginname) { + install(yum, Bukkit.getConsoleSender(), pluginname); + } + + public static void install(Plugin yum, final CommandSender sender, final String pluginname) { + Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); + final DownloadManager download = new DownloadManager(yum); + if (plugin == null) { + Bukkit.getScheduler().runTaskAsynchronously(yum, new Runnable() { + @Override + public void run() { + if (download.run(sender, pluginname)) { + sender.sendMessage(PluginsManager.load(pluginname)); + } + } + }); + } else { + sender.sendMessage("§c插件已安装在服务器 需要更新请使用yum update " + pluginname + "!"); + } + } + + public static void update(Plugin yum, final String pluginname) { + update(yum, Bukkit.getConsoleSender(), pluginname); + } + + public static void update(Plugin yum, final CommandSender sender, final String pluginname) { + final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); + final DownloadManager download = new DownloadManager(yum); + sender.sendMessage("§a开始更新插件: " + pluginname); + if (plugin != null) { + Bukkit.getScheduler().runTaskAsynchronously(yum, new Runnable() { + @Override + public void run() { + sender.sendMessage(PluginsManager.unload(plugin)); + PluginsManager.getPluginFile(plugin).delete(); + if (download.run(sender, pluginname)) { + sender.sendMessage(PluginsManager.load(pluginname)); + } + } + }); + } else { + sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!"); + } + } +}