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;