版本更新至 4.05

修复:更新检测失效
修复:TLocale 载入语言文件的语法错误导致资源浪费的问题
新增:拥有 "taboolib.update.notify" 权限的玩家进服将会收到更新提醒
This commit is contained in:
坏黑
2018-05-23 22:12:59 +08:00
parent fb38ef8977
commit 8a20fb7edb
8 changed files with 62 additions and 27 deletions

View File

@@ -1,5 +1,6 @@
package me.skymc.taboolib.update;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.ilummc.tlib.resources.TLocale;
@@ -14,10 +15,19 @@ import org.bukkit.scheduler.BukkitRunnable;
*/
public class UpdateTask {
private static final String API = "https://internal.github.com/repos/Bkm016/TabooLib/releases/latest";
private static boolean haveUpdate = false;
private static double newVersion = 0;
public static boolean isHaveUpdate() {
return haveUpdate;
}
public static double getNewVersion() {
return newVersion;
}
/**
* 检测更新
* 旧地址https://internal.github.com/repos/Bkm016/TabooLib/releases/latest
*/
public UpdateTask() {
new BukkitRunnable() {
@@ -27,13 +37,21 @@ public class UpdateTask {
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) {
return;
}
String value = FileUtils.getStringFromURL(API, "{}");
JsonObject json = new JsonParser().parse(value).getAsJsonObject();
if (json.entrySet().size() > 0) {
double newVersion = Double.parseDouble(json.get("tag_name").getAsString());
String value = FileUtils.getStringFromURL("https://api.github.com/repos/Bkm016/TabooLib/tags", null);
if (value == null) {
TLocale.Logger.error("UPDATETASK.VERSION-FAIL");
return;
}
JsonElement json = new JsonParser().parse(value);
if (json.isJsonArray()) {
JsonObject latestObject = json.getAsJsonArray().get(0).getAsJsonObject();
newVersion = latestObject.get("name").getAsDouble();
if (TabooLib.getPluginVersion() >= newVersion) {
TLocale.Logger.info("UPDATETASK.VERSION-LATEST");
} else {
haveUpdate = true;
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
}
}