diff --git a/pom.xml b/pom.xml
index 07bb135..4aaeaa4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.skymc
TabooLib
- 4.03
+ 4.05
UTF-8
diff --git a/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java b/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java
index c9f6bcb..2aef0c0 100644
--- a/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java
+++ b/src/main/java/com/ilummc/tlib/resources/TLocaleLoader.java
@@ -141,7 +141,7 @@ public class TLocaleLoader {
}
private static YamlConfiguration getLocaleAtStream(Plugin plugin, File localeFile) {
- InputStream localeInputSteam = FileUtils.getResource("lang/" + localeFile.getName());
+ InputStream localeInputSteam = FileUtils.getResource(plugin, "lang/" + localeFile.getName());
try {
String yamlText = new String(IO.readFully(localeInputSteam), Charset.forName("utf-8"));
YamlConfiguration yaml = new YamlConfiguration();
diff --git a/src/main/java/me/skymc/taboolib/Main.java b/src/main/java/me/skymc/taboolib/Main.java
index a181285..731b886 100644
--- a/src/main/java/me/skymc/taboolib/Main.java
+++ b/src/main/java/me/skymc/taboolib/Main.java
@@ -7,7 +7,6 @@ import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.anvil.AnvilContainerAPI;
import me.skymc.taboolib.bstats.Metrics;
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.language.Language2Command;
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(new ListenerPlayerCommand(), 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 DataUtils(), this);
getServer().getPluginManager().registerEvents(new AnvilContainerAPI(), this);
diff --git a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
index a3040e4..a0afd4d 100644
--- a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
+++ b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
@@ -2,8 +2,10 @@ package me.skymc.taboolib.fileutils;
import ch.njol.util.Closeable;
import com.ilummc.tlib.util.IO;
+import javafx.print.PageLayout;
import me.skymc.taboolib.Main;
import org.apache.commons.io.IOUtils;
+import org.bukkit.plugin.Plugin;
import java.io.*;
import java.net.HttpURLConnection;
@@ -48,8 +50,12 @@ public class FileUtils {
}
public static InputStream getResource(String filename) {
+ return getResource(Main.getInst(), filename);
+ }
+
+ public static InputStream getResource(Plugin plugin, String filename) {
try {
- URL url = Main.class.getClassLoader().getResource(filename);
+ URL url = plugin.getClass().getClassLoader().getResource(filename);
if (url == null) {
return null;
} else {
diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJoinAndQuit.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJoinAndQuit.java
new file mode 100644
index 0000000..3f262df
--- /dev/null
+++ b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerJoinAndQuit.java
@@ -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());
+ }
+}
diff --git a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java b/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java
deleted file mode 100644
index 066e77c..0000000
--- a/src/main/java/me/skymc/taboolib/listener/ListenerPlayerQuit.java
+++ /dev/null
@@ -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());
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/update/UpdateTask.java b/src/main/java/me/skymc/taboolib/update/UpdateTask.java
index 7deb383..ee4f992 100644
--- a/src/main/java/me/skymc/taboolib/update/UpdateTask.java
+++ b/src/main/java/me/skymc/taboolib/update/UpdateTask.java
@@ -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));
}
}
diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml
index 6555707..3e8ddbf 100644
--- a/src/main/resources/lang/zh_CN.yml
+++ b/src/main/resources/lang/zh_CN.yml
@@ -112,7 +112,8 @@ ANVIL-CONTAINER:
- '&7随后点击右侧输出物品'
UPDATETASK:
- VERSION-LATEST: '插件已是最新版, 无需更新!'
+ VERSION-FAIL: '&4更新记录获取失败, 请检查网络连接!'
+ VERSION-LATEST: '&7插件已是最新版, 无需更新!'
VERSION-OUTDATED:
- '&8####################################################'
- '&7 检测到有新的版本更新!'