diff --git a/src/main/java/cn/citycraft/Yum/api/YumApi.java b/src/main/java/cn/citycraft/Yum/api/YumApi.java index ac0bbda..4dfdf46 100644 --- a/src/main/java/cn/citycraft/Yum/api/YumApi.java +++ b/src/main/java/cn/citycraft/Yum/api/YumApi.java @@ -3,6 +3,13 @@ */ package cn.citycraft.Yum.api; +import java.net.URL; + +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; + +import cn.citycraft.Yum.manager.YumManager; + /** * Yum仓库插件API * @@ -10,5 +17,7 @@ package cn.citycraft.Yum.api; * @since 2015年8月22日下午4:43:41 */ public class YumApi { - + public static boolean update(final CommandSender sender, final Plugin plugin, final URL url, final String version) { + return YumManager.update(sender, plugin, url, version); + } } diff --git a/src/main/java/cn/citycraft/Yum/manager/DownloadManager.java b/src/main/java/cn/citycraft/Yum/manager/DownloadManager.java index a54f6d9..116f6ab 100644 --- a/src/main/java/cn/citycraft/Yum/manager/DownloadManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/DownloadManager.java @@ -128,7 +128,7 @@ public class DownloadManager { fout.write(data, 0, count); final int percent = (int) (downloaded * 100L / fileLength); if (percent % 10 == 0) { - if (fileLength < 102400 || System.currentTimeMillis() - time > 1000) { + if (System.currentTimeMillis() - time > 500) { sender.sendMessage(String.format("§6已下载: §a" + getPer(percent / 10) + " %s%%", percent)); time = System.currentTimeMillis(); } diff --git a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java index 53a97d4..6aed95d 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java @@ -141,11 +141,11 @@ public class RepositoryManager { final String repocache = config.getString("repocache"); final String plugincache = config.getString("plugincache"); try { - if (!repocache.isEmpty()) { + if (repocache != null && !repocache.isEmpty()) { repos = gson.fromJson(repocache, new TypeToken>() { }.getType()); } - if (!plugincache.isEmpty()) { + if (plugincache != null && !plugincache.isEmpty()) { plugins = gson.fromJson(plugincache, new TypeToken>() { }.getType()); } diff --git a/src/main/java/cn/citycraft/Yum/manager/YumManager.java b/src/main/java/cn/citycraft/Yum/manager/YumManager.java index daf290a..a545d2c 100644 --- a/src/main/java/cn/citycraft/Yum/manager/YumManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/YumManager.java @@ -1,6 +1,7 @@ package cn.citycraft.Yum.manager; import java.io.File; +import java.net.URL; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -56,4 +57,12 @@ public class YumManager { } return false; } + + public static boolean update(final CommandSender sender, final Plugin plugin, final URL url, final String version) { + if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { + sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!"); + return true; + } + return false; + } }