Caching getTPS some reflect tools

Former-commit-id: 82e3967453d79c991753df96beb33876f77a24d6
This commit is contained in:
Ghost_chu committed 2020-04-06 18:22:30 +08:00
1 parent 25ca1f13b5
commit e3223cb1e4
1 file changed
+12 -10
@@ -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));