diff --git a/pom.xml b/pom.xml index e45a643..4d52892 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.skymc TabooLib - 4.69 + 4.7 UTF-8 diff --git a/src/main/java/com/ilummc/tlib/TLib.java b/src/main/java/com/ilummc/tlib/TLib.java index 83559c3..831c274 100644 --- a/src/main/java/com/ilummc/tlib/TLib.java +++ b/src/main/java/com/ilummc/tlib/TLib.java @@ -12,6 +12,7 @@ import com.ilummc.tlib.resources.TLocale; import com.ilummc.tlib.resources.TLocaleLoader; import com.ilummc.tlib.util.IO; import me.skymc.taboolib.Main; +import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.plugin.PluginUtils; import org.bukkit.Bukkit; @@ -96,8 +97,8 @@ public class TLib { field.set(Bukkit.getServer(), new TPluginManager()); TLocale.Logger.info("TLIB.INJECTION-SUCCESS"); } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException ignored) { - TLocale.Logger.fatal("TLIB.INJECTION-FAILED"); - Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> plugin != Main.getInst()).forEach(plugin -> TDependencyInjector.inject(plugin, plugin)); + TLocale.Logger.error("TLIB.INJECTION-FAILED"); + Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> !TabooLib.isTabooLib(plugin)).forEach(plugin -> TDependencyInjector.inject(plugin, plugin)); } } diff --git a/src/main/java/me/skymc/taboolib/Main.java b/src/main/java/me/skymc/taboolib/Main.java index c364a0a..c036d92 100644 --- a/src/main/java/me/skymc/taboolib/Main.java +++ b/src/main/java/me/skymc/taboolib/Main.java @@ -119,13 +119,15 @@ public class Main extends JavaPlugin { @Override public void run() { // 面子工程 - InputStream inputStream = FileUtils.getResource("motd.txt"); - try { - String text = new String(IO.readFully(inputStream), Charset.forName("utf-8")); - if (text != null) { - Arrays.stream(text.split("\n")).forEach(line -> Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(line, getDescription().getVersion()))); + if (!TabooLib.isSilent()) { + InputStream inputStream = FileUtils.getResource("motd.txt"); + try { + String text = new String(IO.readFully(inputStream), Charset.forName("utf-8")); + if (text != null) { + Arrays.stream(text.split("\n")).forEach(line -> Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(line, getDescription().getVersion()))); + } + } catch (IOException ignored) { } - } catch (IOException ignored) { } // 本地通讯网络终端 if (getConfig().getBoolean("SERVER")) { @@ -135,12 +137,14 @@ public class Main extends JavaPlugin { TabooLibClient.init(); } }.runTask(this); - // 更新检测 - new UpdateTask(); // 启动 started = true; // 载入语言文件 exampleLanguage2 = new Language2("Language2", this); + // 更新检测 + if (!TabooLib.isSilent()) { + new UpdateTask(); + } } @Override diff --git a/src/main/java/me/skymc/taboolib/TabooLib.java b/src/main/java/me/skymc/taboolib/TabooLib.java index 93097e9..bc61503 100644 --- a/src/main/java/me/skymc/taboolib/TabooLib.java +++ b/src/main/java/me/skymc/taboolib/TabooLib.java @@ -1,6 +1,6 @@ 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.playerdata.DataUtils; import net.md_5.bungee.api.ChatColor; @@ -16,6 +16,7 @@ import java.util.UUID; public class TabooLib { private static boolean spigot = false; + private static boolean silent = false; static { try { @@ -28,8 +29,6 @@ public class TabooLib { /** * 获取主类对象,因 Main 名称容易造成混淆所以转移至此 - * - * @return {@link Main} */ public static Main instance() { return (Main) Main.getInst(); @@ -37,9 +36,6 @@ public class TabooLib { /** * 插件是否为 TabooLib(沙雕方法) - * - * @param plugin 插件 - * @return boolean */ public static boolean isTabooLib(Plugin plugin) { return plugin.equals(instance()) || plugin.getName().equals("TabooLib"); @@ -47,9 +43,6 @@ public class TabooLib { /** * 插件是否依赖于 TabooLib(依赖或软兼容) - * - * @param plugin 插件 - * @return boolean */ public static boolean isDependTabooLib(Plugin plugin) { return plugin.getDescription().getDepend().contains("TabooLib") || plugin.getDescription().getSoftDepend().contains("TabooLib"); @@ -57,17 +50,27 @@ public class TabooLib { /** * 是否为 Spigot 核心,因 TabooLib 可在 BungeeCord 上运行所以添加此方法 - * - * @return boolean */ public static boolean isSpigot() { return spigot; } + /** + * 是否为静默模式 + */ + public static boolean isSilent() { + return silent; + } + + /** + * 设置静默模式,启用后将关闭部分提示 + */ + public static void setSilent(boolean silent) { + TabooLib.silent = silent; + } + /** * 获取 TabooLib 插件版本 - * - * @return double */ public static double getPluginVersion() { return NumberUtils.getDouble(Main.getInst().getDescription().getVersion()); @@ -75,8 +78,6 @@ public class TabooLib { /** * 获取服务端版本 - * - * @return String */ public static String getVersion() { return Bukkit.getServer().getClass().getName().split("\\.")[3]; @@ -84,8 +85,6 @@ public class TabooLib { /** * 获取服务端版本数字 - * - * @return int */ public static int getVersionNumber() { return getVerint(); @@ -100,8 +99,6 @@ public class TabooLib { /** * 是否为调试模式 - * - * @return boolean */ public static boolean isDebug() { return DataUtils.getPluginData("TabooLibrary", instance()).getBoolean("debug"); @@ -109,8 +106,6 @@ public class TabooLib { /** * 切换调试模式 - * - * @param debug 值 */ public static void setDebug(boolean debug) { DataUtils.getPluginData("TabooLibrary", instance()).set("debug", debug); @@ -118,8 +113,6 @@ public class TabooLib { /** * 发送调试信息 - * - * @param args 内容 */ public static void debug(String... args) { debug(instance(), args); @@ -127,9 +120,6 @@ public class TabooLib { /** * 发送调试信息 - * - * @param plugin 插件名 - * @param args 内容 */ public static void debug(Plugin plugin, String... args) { if (TabooLib.isDebug()) { @@ -139,8 +129,6 @@ public class TabooLib { /** * 获取服务器序列号 - * - * @return String */ public static String getServerUID() { if (!DataUtils.getPluginData("TabooLibrary", null).contains("serverUID")) { @@ -151,17 +139,9 @@ public class TabooLib { /** * 获取服务器 TPS - * - * @return double[3] */ public static double[] getTPS() { - try { - 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}; - } + return NMSHandler.getHandler().getTPS(); } @Deprecated diff --git a/src/main/java/me/skymc/taboolib/cloud/TCloudLoader.java b/src/main/java/me/skymc/taboolib/cloud/TCloudLoader.java index 53d22e3..4be5c95 100644 --- a/src/main/java/me/skymc/taboolib/cloud/TCloudLoader.java +++ b/src/main/java/me/skymc/taboolib/cloud/TCloudLoader.java @@ -14,9 +14,7 @@ import me.skymc.taboolib.plugin.PluginUtils; import org.bukkit.Bukkit; import java.io.File; -import java.util.HashMap; import java.util.Map; -import java.util.Set; /** * @Author sky @@ -48,13 +46,17 @@ public class TCloudLoader { long time = System.currentTimeMillis(); latestJsonOrigin = FileUtils.getStringFromURL(url, 1024); if (latestJsonOrigin == null) { - TLocale.Logger.error("TCLOUD.LIST-CONNECT-FAILED"); + if (!TabooLib.isSilent()) { + TLocale.Logger.error("TCLOUD.LIST-CONNECT-FAILED"); + } return; } try { latestJsonObject = new JsonParser().parse(latestJsonOrigin).getAsJsonObject(); } catch (Exception e) { - TLocale.Logger.info("TCLOUD.LIST-PARSE-FAILED", e.getMessage()); + if (!TabooLib.isSilent()) { + TLocale.Logger.info("TCLOUD.LIST-PARSE-FAILED", e.getMessage()); + } return; } if (latestJsonObject.has("plugins")) { @@ -62,7 +64,9 @@ public class TCloudLoader { try { expansionPlugins.put(pluginEntry.getKey(), Expansion.unSerialize(ExpansionType.PLUGIN, pluginEntry.getKey(), pluginEntry.getValue().getAsJsonObject())); } catch (Exception e) { - TLocale.Logger.info("TCLOUD.LIST-LOAD-FAILED", pluginEntry.getKey(), e.getMessage()); + if (!TabooLib.isSilent()) { + TLocale.Logger.info("TCLOUD.LIST-LOAD-FAILED", pluginEntry.getKey(), e.getMessage()); + } } } } @@ -71,11 +75,15 @@ public class TCloudLoader { try { expansionInternal.put(pluginEntry.getKey(), Expansion.unSerialize(ExpansionType.INTERNAL, pluginEntry.getKey(), pluginEntry.getValue().getAsJsonObject())); } catch (Exception e) { - TLocale.Logger.info("TCLOUD.LIST-LOAD-FAILED", pluginEntry.getKey(), e.getMessage()); + if (!TabooLib.isSilent()) { + TLocale.Logger.info("TCLOUD.LIST-LOAD-FAILED", pluginEntry.getKey(), e.getMessage()); + } } } } - TLocale.Logger.info("TCLOUD.LIST-LOAD-SUCCESS", String.valueOf(System.currentTimeMillis() - time)); + if (!TabooLib.isSilent()) { + TLocale.Logger.info("TCLOUD.LIST-LOAD-SUCCESS", String.valueOf(System.currentTimeMillis() - time)); + } }); } diff --git a/src/main/java/me/skymc/taboolib/common/nms/NMSHandler.java b/src/main/java/me/skymc/taboolib/common/nms/NMSHandler.java index 0a2ddab..51749e6 100644 --- a/src/main/java/me/skymc/taboolib/common/nms/NMSHandler.java +++ b/src/main/java/me/skymc/taboolib/common/nms/NMSHandler.java @@ -32,6 +32,8 @@ public abstract class NMSHandler { abstract public void sendActionBar(Player player, String text); + abstract public double[] getTPS(); + public static NMSHandler getHandler() { return handler; } diff --git a/src/main/java/me/skymc/taboolib/common/nms/NMSHandlerImpl.java b/src/main/java/me/skymc/taboolib/common/nms/NMSHandlerImpl.java index d365346..15de1a0 100644 --- a/src/main/java/me/skymc/taboolib/common/nms/NMSHandlerImpl.java +++ b/src/main/java/me/skymc/taboolib/common/nms/NMSHandlerImpl.java @@ -3,6 +3,7 @@ package me.skymc.taboolib.common.nms; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.common.packet.TPacketHandler; 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.PacketPlayOutChat; 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)); } } + + @Override + public double[] getTPS() { + return MinecraftServer.getServer().recentTps; + } } diff --git a/src/main/java/me/skymc/taboolib/socket/TabooLibClient.java b/src/main/java/me/skymc/taboolib/socket/TabooLibClient.java index 2706db7..9309e5d 100644 --- a/src/main/java/me/skymc/taboolib/socket/TabooLibClient.java +++ b/src/main/java/me/skymc/taboolib/socket/TabooLibClient.java @@ -68,7 +68,7 @@ public class TabooLibClient { /* 防止未启用终端服务器导致重复提示连接失败信息 */ - if (!notify) { + if (!notify && !TabooLib.isSilent()) { notify = true; TLocale.sendToConsole("COMMUNICATION.FAILED-CONNECT-SERVER"); }