From e3223cb1e45441d046ce2e342fc38ed6db7af304 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Mon, 6 Apr 2020 18:22:30 +0800 Subject: [PATCH] Caching getTPS some reflect tools Former-commit-id: 82e3967453d79c991753df96beb33876f77a24d6 --- .../org/maxgamer/quickshop/util/Util.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/util/Util.java b/src/main/java/org/maxgamer/quickshop/util/Util.java index 3613b41e7..57db3cda2 100644 --- a/src/main/java/org/maxgamer/quickshop/util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/util/Util.java @@ -1271,16 +1271,18 @@ public class Util { * @return TPS (e.g 19.92) */ public static Double getTPS() { - try { - serverInstance = getNMSClass("MinecraftServer").getMethod("getServer").invoke(null); - tpsField = serverInstance.getClass().getField("recentTps"); - } catch (NoSuchFieldException - | SecurityException - | IllegalAccessException - | IllegalArgumentException - | InvocationTargetException - | NoSuchMethodException e) { - e.printStackTrace(); + if(serverInstance == null || tpsField == null) { + try { + serverInstance = getNMSClass("MinecraftServer").getMethod("getServer").invoke(null); + tpsField = serverInstance.getClass().getField("recentTps"); + } catch (NoSuchFieldException + | SecurityException + | IllegalAccessException + | IllegalArgumentException + | InvocationTargetException + | NoSuchMethodException e) { + e.printStackTrace(); + } } try { double[] tps = ((double[]) tpsField.get(serverInstance));