improve getMinHeight()

This commit is contained in:
HaHaWTH 2023-12-31 14:07:44 +08:00
parent 69989fb99e
commit 1c63eca0f7

View File

@ -35,8 +35,7 @@ public class LoginLocationFixListener implements Listener {
private static Material materialPortal = Material.matchMaterial("PORTAL"); private static Material materialPortal = Material.matchMaterial("PORTAL");
private boolean isChecked = false; private static int isChecked = 0; // 0: unchecked 1: method available 2: method not available
private boolean isGetMinHeight = false;
private final boolean isSmartAsyncTeleport = AuthMe.settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT); 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 isFixPortalStuck = AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL);
private final boolean isFixGroundStuck = AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND); 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"); materialPortal = Material.matchMaterial("NETHER_PORTAL");
} }
} }
try {
Method getMinHeightMethod = World.class.getMethod("getMinHeight");
isChecked = 1;
} catch (NoSuchMethodException e) {
isChecked = 2;
}
} }
private int getMinHeight(World world) { private int getMinHeight(World world) {
//This keeps compatibility of 1.16.x and lower //This keeps compatibility of 1.16.x and lower
try { if (isChecked == 1) {
if (!isChecked) { return world.getMinHeight();
Method getMinHeightMethod = World.class.getMethod("getMinHeight"); } else {
getMinHeightMethod.setAccessible(true);
isChecked = true;
isGetMinHeight = true;
return world.getMinHeight();
} else if (isGetMinHeight) {
return world.getMinHeight();
} else {
return 0;
}
} catch (NoSuchMethodException e) {
isChecked = true;
return 0; return 0;
} }
} }