add YumApi...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-10-07 13:19:38 +08:00
parent f1b5551cf2
commit 88cec09019
4 changed files with 22 additions and 4 deletions

View File

@ -3,6 +3,13 @@
*/ */
package cn.citycraft.Yum.api; 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 * Yum仓库插件API
* *
@ -10,5 +17,7 @@ package cn.citycraft.Yum.api;
* @since 2015年8月22日下午4:43:41 * @since 2015年8月22日下午4:43:41
*/ */
public class YumApi { 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);
}
} }

View File

@ -128,7 +128,7 @@ public class DownloadManager {
fout.write(data, 0, count); fout.write(data, 0, count);
final int percent = (int) (downloaded * 100L / fileLength); final int percent = (int) (downloaded * 100L / fileLength);
if (percent % 10 == 0) { 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)); sender.sendMessage(String.format("§6已下载: §a" + getPer(percent / 10) + " %s%%", percent));
time = System.currentTimeMillis(); time = System.currentTimeMillis();
} }

View File

@ -141,11 +141,11 @@ public class RepositoryManager {
final String repocache = config.getString("repocache"); final String repocache = config.getString("repocache");
final String plugincache = config.getString("plugincache"); final String plugincache = config.getString("plugincache");
try { try {
if (!repocache.isEmpty()) { if (repocache != null && !repocache.isEmpty()) {
repos = gson.fromJson(repocache, new TypeToken<List<String>>() { repos = gson.fromJson(repocache, new TypeToken<List<String>>() {
}.getType()); }.getType());
} }
if (!plugincache.isEmpty()) { if (plugincache != null && !plugincache.isEmpty()) {
plugins = gson.fromJson(plugincache, new TypeToken<HashMap<String, PluginInfo>>() { plugins = gson.fromJson(plugincache, new TypeToken<HashMap<String, PluginInfo>>() {
}.getType()); }.getType());
} }

View File

@ -1,6 +1,7 @@
package cn.citycraft.Yum.manager; package cn.citycraft.Yum.manager;
import java.io.File; import java.io.File;
import java.net.URL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -56,4 +57,12 @@ public class YumManager {
} }
return false; 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;
}
} }