版本更新至 4.05
修复:更新检测失效 修复:TLocale 载入语言文件的语法错误导致资源浪费的问题 新增:拥有 "taboolib.update.notify" 权限的玩家进服将会收到更新提醒
This commit is contained in:
parent
fb38ef8977
commit
8a20fb7edb
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.skymc</groupId>
|
||||
<artifactId>TabooLib</artifactId>
|
||||
<version>4.03</version>
|
||||
<version>4.05</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,8 @@ ANVIL-CONTAINER:
|
||||
- '&7随后点击右侧输出物品'
|
||||
|
||||
UPDATETASK:
|
||||
VERSION-LATEST: '插件已是最新版, 无需更新!'
|
||||
VERSION-FAIL: '&4更新记录获取失败, 请检查网络连接!'
|
||||
VERSION-LATEST: '&7插件已是最新版, 无需更新!'
|
||||
VERSION-OUTDATED:
|
||||
- '&8####################################################'
|
||||
- '&7 检测到有新的版本更新!'
|
||||
|
Loading…
Reference in New Issue
Block a user