From 1c63eca0f7ea4f69e80edbaced846e7e2be9dc10 Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Sun, 31 Dec 2023 14:07:44 +0800 Subject: [PATCH] improve getMinHeight() --- .../listener/LoginLocationFixListener.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java b/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java index 1429772e..9774ec93 100644 --- a/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java +++ b/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java @@ -35,8 +35,7 @@ public class LoginLocationFixListener implements Listener { private static Material materialPortal = Material.matchMaterial("PORTAL"); - private boolean isChecked = false; - private boolean isGetMinHeight = false; + private static int isChecked = 0; // 0: unchecked 1: method available 2: method not available private final boolean isSmartAsyncTeleport = AuthMe.settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT); private final boolean isFixPortalStuck = AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL); private final boolean isFixGroundStuck = AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND); @@ -49,24 +48,19 @@ public class LoginLocationFixListener implements Listener { materialPortal = Material.matchMaterial("NETHER_PORTAL"); } } + try { + Method getMinHeightMethod = World.class.getMethod("getMinHeight"); + isChecked = 1; + } catch (NoSuchMethodException e) { + isChecked = 2; + } } private int getMinHeight(World world) { //This keeps compatibility of 1.16.x and lower - try { - if (!isChecked) { - Method getMinHeightMethod = World.class.getMethod("getMinHeight"); - getMinHeightMethod.setAccessible(true); - isChecked = true; - isGetMinHeight = true; - return world.getMinHeight(); - } else if (isGetMinHeight) { - return world.getMinHeight(); - } else { - return 0; - } - } catch (NoSuchMethodException e) { - isChecked = true; + if (isChecked == 1) { + return world.getMinHeight(); + } else { return 0; } }