+ 静默更新

This commit is contained in:
坏黑 2019-01-20 16:45:02 +08:00
parent 70efab657a
commit 7dbc9966c5
8 changed files with 57 additions and 56 deletions

View File

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

View File

@ -12,6 +12,7 @@ import com.ilummc.tlib.resources.TLocale;
import com.ilummc.tlib.resources.TLocaleLoader; import com.ilummc.tlib.resources.TLocaleLoader;
import com.ilummc.tlib.util.IO; import com.ilummc.tlib.util.IO;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.plugin.PluginUtils; import me.skymc.taboolib.plugin.PluginUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -96,8 +97,8 @@ public class TLib {
field.set(Bukkit.getServer(), new TPluginManager()); field.set(Bukkit.getServer(), new TPluginManager());
TLocale.Logger.info("TLIB.INJECTION-SUCCESS"); TLocale.Logger.info("TLIB.INJECTION-SUCCESS");
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException ignored) { } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException ignored) {
TLocale.Logger.fatal("TLIB.INJECTION-FAILED"); TLocale.Logger.error("TLIB.INJECTION-FAILED");
Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> plugin != Main.getInst()).forEach(plugin -> TDependencyInjector.inject(plugin, plugin)); Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> !TabooLib.isTabooLib(plugin)).forEach(plugin -> TDependencyInjector.inject(plugin, plugin));
} }
} }

View File

@ -119,6 +119,7 @@ public class Main extends JavaPlugin {
@Override @Override
public void run() { public void run() {
// 面子工程 // 面子工程
if (!TabooLib.isSilent()) {
InputStream inputStream = FileUtils.getResource("motd.txt"); InputStream inputStream = FileUtils.getResource("motd.txt");
try { try {
String text = new String(IO.readFully(inputStream), Charset.forName("utf-8")); String text = new String(IO.readFully(inputStream), Charset.forName("utf-8"));
@ -127,6 +128,7 @@ public class Main extends JavaPlugin {
} }
} catch (IOException ignored) { } catch (IOException ignored) {
} }
}
// 本地通讯网络终端 // 本地通讯网络终端
if (getConfig().getBoolean("SERVER")) { if (getConfig().getBoolean("SERVER")) {
TabooLibServer.main(new String[0]); TabooLibServer.main(new String[0]);
@ -135,12 +137,14 @@ public class Main extends JavaPlugin {
TabooLibClient.init(); TabooLibClient.init();
} }
}.runTask(this); }.runTask(this);
// 更新检测
new UpdateTask();
// 启动 // 启动
started = true; started = true;
// 载入语言文件 // 载入语言文件
exampleLanguage2 = new Language2("Language2", this); exampleLanguage2 = new Language2("Language2", this);
// 更新检测
if (!TabooLib.isSilent()) {
new UpdateTask();
}
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package me.skymc.taboolib; package me.skymc.taboolib;
import me.skymc.taboolib.nms.NMSUtils; import me.skymc.taboolib.common.nms.NMSHandler;
import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.playerdata.DataUtils; import me.skymc.taboolib.playerdata.DataUtils;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
@ -16,6 +16,7 @@ import java.util.UUID;
public class TabooLib { public class TabooLib {
private static boolean spigot = false; private static boolean spigot = false;
private static boolean silent = false;
static { static {
try { try {
@ -28,8 +29,6 @@ public class TabooLib {
/** /**
* 获取主类对象 Main 名称容易造成混淆所以转移至此 * 获取主类对象 Main 名称容易造成混淆所以转移至此
*
* @return {@link Main}
*/ */
public static Main instance() { public static Main instance() {
return (Main) Main.getInst(); return (Main) Main.getInst();
@ -37,9 +36,6 @@ public class TabooLib {
/** /**
* 插件是否为 TabooLib沙雕方法 * 插件是否为 TabooLib沙雕方法
*
* @param plugin 插件
* @return boolean
*/ */
public static boolean isTabooLib(Plugin plugin) { public static boolean isTabooLib(Plugin plugin) {
return plugin.equals(instance()) || plugin.getName().equals("TabooLib"); return plugin.equals(instance()) || plugin.getName().equals("TabooLib");
@ -47,9 +43,6 @@ public class TabooLib {
/** /**
* 插件是否依赖于 TabooLib依赖或软兼容 * 插件是否依赖于 TabooLib依赖或软兼容
*
* @param plugin 插件
* @return boolean
*/ */
public static boolean isDependTabooLib(Plugin plugin) { public static boolean isDependTabooLib(Plugin plugin) {
return plugin.getDescription().getDepend().contains("TabooLib") || plugin.getDescription().getSoftDepend().contains("TabooLib"); return plugin.getDescription().getDepend().contains("TabooLib") || plugin.getDescription().getSoftDepend().contains("TabooLib");
@ -57,17 +50,27 @@ public class TabooLib {
/** /**
* 是否为 Spigot 核心 TabooLib 可在 BungeeCord 上运行所以添加此方法 * 是否为 Spigot 核心 TabooLib 可在 BungeeCord 上运行所以添加此方法
*
* @return boolean
*/ */
public static boolean isSpigot() { public static boolean isSpigot() {
return spigot; return spigot;
} }
/**
* 是否为静默模式
*/
public static boolean isSilent() {
return silent;
}
/**
* 设置静默模式启用后将关闭部分提示
*/
public static void setSilent(boolean silent) {
TabooLib.silent = silent;
}
/** /**
* 获取 TabooLib 插件版本 * 获取 TabooLib 插件版本
*
* @return double
*/ */
public static double getPluginVersion() { public static double getPluginVersion() {
return NumberUtils.getDouble(Main.getInst().getDescription().getVersion()); return NumberUtils.getDouble(Main.getInst().getDescription().getVersion());
@ -75,8 +78,6 @@ public class TabooLib {
/** /**
* 获取服务端版本 * 获取服务端版本
*
* @return String
*/ */
public static String getVersion() { public static String getVersion() {
return Bukkit.getServer().getClass().getName().split("\\.")[3]; return Bukkit.getServer().getClass().getName().split("\\.")[3];
@ -84,8 +85,6 @@ public class TabooLib {
/** /**
* 获取服务端版本数字 * 获取服务端版本数字
*
* @return int
*/ */
public static int getVersionNumber() { public static int getVersionNumber() {
return getVerint(); return getVerint();
@ -100,8 +99,6 @@ public class TabooLib {
/** /**
* 是否为调试模式 * 是否为调试模式
*
* @return boolean
*/ */
public static boolean isDebug() { public static boolean isDebug() {
return DataUtils.getPluginData("TabooLibrary", instance()).getBoolean("debug"); return DataUtils.getPluginData("TabooLibrary", instance()).getBoolean("debug");
@ -109,8 +106,6 @@ public class TabooLib {
/** /**
* 切换调试模式 * 切换调试模式
*
* @param debug
*/ */
public static void setDebug(boolean debug) { public static void setDebug(boolean debug) {
DataUtils.getPluginData("TabooLibrary", instance()).set("debug", debug); DataUtils.getPluginData("TabooLibrary", instance()).set("debug", debug);
@ -118,8 +113,6 @@ public class TabooLib {
/** /**
* 发送调试信息 * 发送调试信息
*
* @param args 内容
*/ */
public static void debug(String... args) { public static void debug(String... args) {
debug(instance(), args); debug(instance(), args);
@ -127,9 +120,6 @@ public class TabooLib {
/** /**
* 发送调试信息 * 发送调试信息
*
* @param plugin 插件名
* @param args 内容
*/ */
public static void debug(Plugin plugin, String... args) { public static void debug(Plugin plugin, String... args) {
if (TabooLib.isDebug()) { if (TabooLib.isDebug()) {
@ -139,8 +129,6 @@ public class TabooLib {
/** /**
* 获取服务器序列号 * 获取服务器序列号
*
* @return String
*/ */
public static String getServerUID() { public static String getServerUID() {
if (!DataUtils.getPluginData("TabooLibrary", null).contains("serverUID")) { if (!DataUtils.getPluginData("TabooLibrary", null).contains("serverUID")) {
@ -151,17 +139,9 @@ public class TabooLib {
/** /**
* 获取服务器 TPS * 获取服务器 TPS
*
* @return double[3]
*/ */
public static double[] getTPS() { public static double[] getTPS() {
try { return NMSHandler.getHandler().getTPS();
Class<?> minecraftServer = NMSUtils.getNMSClass("MinecraftServer");
Object server = minecraftServer.getMethod("getServer").invoke(null);
return (double[]) server.getClass().getField("recentTps").get(server);
} catch (Exception e) {
return new double[] {0, 0, 0};
}
} }
@Deprecated @Deprecated

View File

@ -14,9 +14,7 @@ import me.skymc.taboolib.plugin.PluginUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* @Author sky * @Author sky
@ -48,13 +46,17 @@ public class TCloudLoader {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
latestJsonOrigin = FileUtils.getStringFromURL(url, 1024); latestJsonOrigin = FileUtils.getStringFromURL(url, 1024);
if (latestJsonOrigin == null) { if (latestJsonOrigin == null) {
if (!TabooLib.isSilent()) {
TLocale.Logger.error("TCLOUD.LIST-CONNECT-FAILED"); TLocale.Logger.error("TCLOUD.LIST-CONNECT-FAILED");
}
return; return;
} }
try { try {
latestJsonObject = new JsonParser().parse(latestJsonOrigin).getAsJsonObject(); latestJsonObject = new JsonParser().parse(latestJsonOrigin).getAsJsonObject();
} catch (Exception e) { } catch (Exception e) {
if (!TabooLib.isSilent()) {
TLocale.Logger.info("TCLOUD.LIST-PARSE-FAILED", e.getMessage()); TLocale.Logger.info("TCLOUD.LIST-PARSE-FAILED", e.getMessage());
}
return; return;
} }
if (latestJsonObject.has("plugins")) { if (latestJsonObject.has("plugins")) {
@ -62,20 +64,26 @@ public class TCloudLoader {
try { try {
expansionPlugins.put(pluginEntry.getKey(), Expansion.unSerialize(ExpansionType.PLUGIN, pluginEntry.getKey(), pluginEntry.getValue().getAsJsonObject())); expansionPlugins.put(pluginEntry.getKey(), Expansion.unSerialize(ExpansionType.PLUGIN, pluginEntry.getKey(), pluginEntry.getValue().getAsJsonObject()));
} catch (Exception e) { } catch (Exception e) {
if (!TabooLib.isSilent()) {
TLocale.Logger.info("TCLOUD.LIST-LOAD-FAILED", pluginEntry.getKey(), e.getMessage()); TLocale.Logger.info("TCLOUD.LIST-LOAD-FAILED", pluginEntry.getKey(), e.getMessage());
} }
} }
} }
}
if (latestJsonObject.has("internal")) { if (latestJsonObject.has("internal")) {
for (Map.Entry<String, JsonElement> pluginEntry : latestJsonObject.getAsJsonObject("internal").entrySet()) { for (Map.Entry<String, JsonElement> pluginEntry : latestJsonObject.getAsJsonObject("internal").entrySet()) {
try { try {
expansionInternal.put(pluginEntry.getKey(), Expansion.unSerialize(ExpansionType.INTERNAL, pluginEntry.getKey(), pluginEntry.getValue().getAsJsonObject())); expansionInternal.put(pluginEntry.getKey(), Expansion.unSerialize(ExpansionType.INTERNAL, pluginEntry.getKey(), pluginEntry.getValue().getAsJsonObject()));
} catch (Exception e) { } catch (Exception e) {
if (!TabooLib.isSilent()) {
TLocale.Logger.info("TCLOUD.LIST-LOAD-FAILED", pluginEntry.getKey(), e.getMessage()); TLocale.Logger.info("TCLOUD.LIST-LOAD-FAILED", pluginEntry.getKey(), e.getMessage());
} }
} }
} }
}
if (!TabooLib.isSilent()) {
TLocale.Logger.info("TCLOUD.LIST-LOAD-SUCCESS", String.valueOf(System.currentTimeMillis() - time)); TLocale.Logger.info("TCLOUD.LIST-LOAD-SUCCESS", String.valueOf(System.currentTimeMillis() - time));
}
}); });
} }

View File

@ -32,6 +32,8 @@ public abstract class NMSHandler {
abstract public void sendActionBar(Player player, String text); abstract public void sendActionBar(Player player, String text);
abstract public double[] getTPS();
public static NMSHandler getHandler() { public static NMSHandler getHandler() {
return handler; return handler;
} }

View File

@ -3,6 +3,7 @@ package me.skymc.taboolib.common.nms;
import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.common.packet.TPacketHandler; import me.skymc.taboolib.common.packet.TPacketHandler;
import net.minecraft.server.v1_12_R1.ChatMessageType; import net.minecraft.server.v1_12_R1.ChatMessageType;
import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_8_R3.ChatComponentText; import net.minecraft.server.v1_8_R3.ChatComponentText;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat; import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import net.minecraft.server.v1_8_R3.PacketPlayOutTitle; import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
@ -28,4 +29,9 @@ public class NMSHandlerImpl extends NMSHandler {
TPacketHandler.sendPacket(player, new PacketPlayOutChat(new ChatComponentText(String.valueOf(text)), (byte) 2)); TPacketHandler.sendPacket(player, new PacketPlayOutChat(new ChatComponentText(String.valueOf(text)), (byte) 2));
} }
} }
@Override
public double[] getTPS() {
return MinecraftServer.getServer().recentTps;
}
} }

View File

@ -68,7 +68,7 @@ public class TabooLibClient {
/* /*
防止未启用终端服务器导致重复提示连接失败信息 防止未启用终端服务器导致重复提示连接失败信息
*/ */
if (!notify) { if (!notify && !TabooLib.isSilent()) {
notify = true; notify = true;
TLocale.sendToConsole("COMMUNICATION.FAILED-CONNECT-SERVER"); TLocale.sendToConsole("COMMUNICATION.FAILED-CONNECT-SERVER");
} }