版本更新至 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

@ -6,7 +6,7 @@
<groupId>me.skymc</groupId> <groupId>me.skymc</groupId>
<artifactId>TabooLib</artifactId> <artifactId>TabooLib</artifactId>
<version>4.03</version> <version>4.05</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -141,7 +141,7 @@ public class TLocaleLoader {
} }
private static YamlConfiguration getLocaleAtStream(Plugin plugin, File localeFile) { private static YamlConfiguration getLocaleAtStream(Plugin plugin, File localeFile) {
InputStream localeInputSteam = FileUtils.getResource("lang/" + localeFile.getName()); InputStream localeInputSteam = FileUtils.getResource(plugin, "lang/" + localeFile.getName());
try { try {
String yamlText = new String(IO.readFully(localeInputSteam), Charset.forName("utf-8")); String yamlText = new String(IO.readFully(localeInputSteam), Charset.forName("utf-8"));
YamlConfiguration yaml = new YamlConfiguration(); YamlConfiguration yaml = new YamlConfiguration();

View File

@ -7,7 +7,6 @@ import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.anvil.AnvilContainerAPI; import me.skymc.taboolib.anvil.AnvilContainerAPI;
import me.skymc.taboolib.bstats.Metrics; import me.skymc.taboolib.bstats.Metrics;
import me.skymc.taboolib.commands.TabooLibMainCommand; import me.skymc.taboolib.commands.TabooLibMainCommand;
import me.skymc.taboolib.commands.internal.BaseMainCommand;
import me.skymc.taboolib.commands.internal.TBaseCommand; import me.skymc.taboolib.commands.internal.TBaseCommand;
import me.skymc.taboolib.commands.language.Language2Command; import me.skymc.taboolib.commands.language.Language2Command;
import me.skymc.taboolib.commands.locale.TabooLibLocaleCommand; import me.skymc.taboolib.commands.locale.TabooLibLocaleCommand;
@ -334,7 +333,7 @@ public class Main extends JavaPlugin implements Listener {
getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(this, this);
getServer().getPluginManager().registerEvents(new ListenerPlayerCommand(), this); getServer().getPluginManager().registerEvents(new ListenerPlayerCommand(), this);
getServer().getPluginManager().registerEvents(new ListenerPlayerJump(), this); getServer().getPluginManager().registerEvents(new ListenerPlayerJump(), this);
getServer().getPluginManager().registerEvents(new ListenerPlayerQuit(), this); getServer().getPluginManager().registerEvents(new ListenerPlayerJoinAndQuit(), this);
getServer().getPluginManager().registerEvents(new ChatCatcher(), this); getServer().getPluginManager().registerEvents(new ChatCatcher(), this);
getServer().getPluginManager().registerEvents(new DataUtils(), this); getServer().getPluginManager().registerEvents(new DataUtils(), this);
getServer().getPluginManager().registerEvents(new AnvilContainerAPI(), this); getServer().getPluginManager().registerEvents(new AnvilContainerAPI(), this);

View File

@ -2,8 +2,10 @@ package me.skymc.taboolib.fileutils;
import ch.njol.util.Closeable; import ch.njol.util.Closeable;
import com.ilummc.tlib.util.IO; import com.ilummc.tlib.util.IO;
import javafx.print.PageLayout;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.bukkit.plugin.Plugin;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -48,8 +50,12 @@ public class FileUtils {
} }
public static InputStream getResource(String filename) { public static InputStream getResource(String filename) {
return getResource(Main.getInst(), filename);
}
public static InputStream getResource(Plugin plugin, String filename) {
try { try {
URL url = Main.class.getClassLoader().getResource(filename); URL url = plugin.getClass().getClassLoader().getResource(filename);
if (url == null) { if (url == null) {
return null; return null;
} else { } else {

View File

@ -0,0 +1,26 @@
package me.skymc.taboolib.listener;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.playerdata.DataUtils;
import me.skymc.taboolib.update.UpdateTask;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class ListenerPlayerJoinAndQuit implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent e) {
if (UpdateTask.isHaveUpdate() && e.getPlayer().hasPermission("taboolib.update.notify")) {
TLocale.Logger.sendTo(e.getPlayer(), "UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(UpdateTask.getNewVersion()));
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(PlayerQuitEvent e) {
DataUtils.saveOnline(e.getPlayer().getName());
}
}

View File

@ -1,15 +0,0 @@
package me.skymc.taboolib.listener;
import me.skymc.taboolib.playerdata.DataUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
public class ListenerPlayerQuit implements Listener{
@EventHandler (priority = EventPriority.MONITOR)
public void quit(PlayerQuitEvent e) {
DataUtils.saveOnline(e.getPlayer().getName());
}
}

View File

@ -1,5 +1,6 @@
package me.skymc.taboolib.update; package me.skymc.taboolib.update;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.ilummc.tlib.resources.TLocale; import com.ilummc.tlib.resources.TLocale;
@ -14,10 +15,19 @@ import org.bukkit.scheduler.BukkitRunnable;
*/ */
public class UpdateTask { 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() { public UpdateTask() {
new BukkitRunnable() { new BukkitRunnable() {
@ -27,13 +37,21 @@ public class UpdateTask {
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) { if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) {
return; return;
} }
String value = FileUtils.getStringFromURL(API, "{}");
JsonObject json = new JsonParser().parse(value).getAsJsonObject(); String value = FileUtils.getStringFromURL("https://api.github.com/repos/Bkm016/TabooLib/tags", null);
if (json.entrySet().size() > 0) { if (value == null) {
double newVersion = Double.parseDouble(json.get("tag_name").getAsString()); 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) { if (TabooLib.getPluginVersion() >= newVersion) {
TLocale.Logger.info("UPDATETASK.VERSION-LATEST"); TLocale.Logger.info("UPDATETASK.VERSION-LATEST");
} else { } else {
haveUpdate = true;
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion)); TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
} }
} }

View File

@ -112,7 +112,8 @@ ANVIL-CONTAINER:
- '&7随后点击右侧输出物品' - '&7随后点击右侧输出物品'
UPDATETASK: UPDATETASK:
VERSION-LATEST: '插件已是最新版, 无需更新!' VERSION-FAIL: '&4更新记录获取失败, 请检查网络连接!'
VERSION-LATEST: '&7插件已是最新版, 无需更新!'
VERSION-OUTDATED: VERSION-OUTDATED:
- '&8####################################################' - '&8####################################################'
- '&7 检测到有新的版本更新!' - '&7 检测到有新的版本更新!'