From e648107f1be89e16366b52a390050e46150f1524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Wed, 12 Sep 2018 01:01:42 +0800 Subject: [PATCH] =?UTF-8?q?+=20=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=B0=8F=E7=A2=A7=E6=B2=B9=E9=B8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/me/skymc/taboolib/TabooLib.java | 16 ++++++++++++++++ .../me/skymc/taboolib/socket/TabooLibServer.java | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/skymc/taboolib/TabooLib.java b/src/main/java/me/skymc/taboolib/TabooLib.java index 44a5683..46bcf89 100644 --- a/src/main/java/me/skymc/taboolib/TabooLib.java +++ b/src/main/java/me/skymc/taboolib/TabooLib.java @@ -1,5 +1,6 @@ package me.skymc.taboolib; +import me.skymc.taboolib.nms.NMSUtils; import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.playerdata.DataUtils; import net.md_5.bungee.api.ChatColor; @@ -129,6 +130,21 @@ public class TabooLib { return DataUtils.getPluginData("TabooLibrary", null).getString("serverUID"); } + /** + * 获取服务器 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}; + } + } + @Deprecated public static int getVerint() { String version = getVersion(); diff --git a/src/main/java/me/skymc/taboolib/socket/TabooLibServer.java b/src/main/java/me/skymc/taboolib/socket/TabooLibServer.java index 24f7fa7..ed2e92a 100644 --- a/src/main/java/me/skymc/taboolib/socket/TabooLibServer.java +++ b/src/main/java/me/skymc/taboolib/socket/TabooLibServer.java @@ -1,13 +1,12 @@ package me.skymc.taboolib.socket; -·import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.socket.packet.Packet; import me.skymc.taboolib.socket.packet.PacketSerializer; import me.skymc.taboolib.socket.packet.impl.PacketHeartbeat; import me.skymc.taboolib.socket.packet.impl.PacketQuit; import me.skymc.taboolib.socket.server.ClientConnection; -import org.bukkit.Bukkit; import java.io.IOException; import java.net.ServerSocket;