diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java index c1a6469a..9eba3d15 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/FirstSpawnCommand.java @@ -4,7 +4,6 @@ import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; -import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.util.TeleportUtils; import org.bukkit.entity.Player; @@ -28,11 +27,7 @@ public class FirstSpawnCommand extends PlayerCommand { } else { //String name= player.getName(); bukkitService.runTaskIfFolia(player, () -> { - if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) { - TeleportUtils.teleport(player, spawnLoader.getFirstSpawn()); - } else { - player.teleport(spawnLoader.getFirstSpawn()); - } + TeleportUtils.teleport(player, spawnLoader.getFirstSpawn()); }); //player.teleport(spawnLoader.getFirstSpawn()); } diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java index 19cda730..a506c8f4 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SpawnCommand.java @@ -3,6 +3,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.settings.SpawnLoader; +import fr.xephi.authme.util.TeleportUtils; import org.bukkit.entity.Player; import javax.inject.Inject; @@ -21,7 +22,7 @@ public class SpawnCommand extends PlayerCommand { player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn"); } else { bukkitService.runTaskIfFolia(player, () -> { - player.teleport(spawnLoader.getSpawn()); + TeleportUtils.teleport(player, spawnLoader.getSpawn()); }); } } diff --git a/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java b/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java index 344290ac..1c64b68b 100644 --- a/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java +++ b/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java @@ -75,11 +75,7 @@ public class LoginLocationFixListener implements Listener { boolean solved = false; for (BlockFace face : faces) { if (JoinBlock.getRelative(face).getType().equals(Material.AIR) && JoinBlock.getRelative(face).getRelative(BlockFace.UP).getType().equals(Material.AIR)) { - if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) { - TeleportUtils.teleport(player, JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5)); - } else { - player.teleport(JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5)); - } + TeleportUtils.teleport(player, JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5)); solved = true; break; } @@ -107,20 +103,12 @@ public class LoginLocationFixListener implements Listener { if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) { JoinBlock.getRelative(BlockFace.DOWN).setType(Material.DIRT); } - if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) { - TeleportUtils.teleport(player, JoinBlock.getLocation().add(0.5, 0.1, 0.5)); - } else { - player.teleport(JoinBlock.getLocation().add(0.5, 0.1, 0.5)); - } + TeleportUtils.teleport(player, JoinBlock.getLocation().add(0.5, 0.1, 0.5)); messages.send(player, MessageKey.LOCATION_FIX_UNDERGROUND); break; } if (i == MaxHeight) { - if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) { - TeleportUtils.teleport(player, JoinBlock.getLocation().add(0.5, 1.1, 0.5)); - } else { - player.teleport(JoinBlock.getLocation().add(0.5, 1.1, 0.5)); - } + TeleportUtils.teleport(player, JoinBlock.getLocation().add(0.5, 1.1, 0.5)); messages.send(player, MessageKey.LOCATION_FIX_UNDERGROUND_CANT_FIX); } } diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 41277d79..d79620b3 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -19,7 +19,6 @@ import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.util.TeleportUtils; import fr.xephi.authme.util.message.MiniMessageUtils; import org.bukkit.ChatColor; @@ -376,17 +375,9 @@ public class PlayerListener implements Listener{ Location spawn = spawnLoader.getSpawnLocation(player); if (spawn != null && spawn.getWorld() != null) { if (!player.getWorld().equals(spawn.getWorld())) { - if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) { - TeleportUtils.teleport(player,spawn); - } else { - player.teleport(spawn); - } + TeleportUtils.teleport(player,spawn); } else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) { - if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) { - TeleportUtils.teleport(player,spawn); - } else { - player.teleport(spawn); - } + TeleportUtils.teleport(player,spawn); } } } diff --git a/src/main/java/fr/xephi/authme/service/TeleportationService.java b/src/main/java/fr/xephi/authme/service/TeleportationService.java index bbc204cd..c50b0129 100644 --- a/src/main/java/fr/xephi/authme/service/TeleportationService.java +++ b/src/main/java/fr/xephi/authme/service/TeleportationService.java @@ -14,7 +14,6 @@ import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.RestrictionSettings; -import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.util.TeleportUtils; import org.bukkit.Location; import org.bukkit.World; @@ -189,10 +188,8 @@ public class TeleportationService implements Reloadable { private void performTeleportation(final Player player, final AbstractTeleportEvent event) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> { bukkitService.callEvent(event); - if (player.isOnline() && isEventValid(event) && settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) { + if (player.isOnline() && isEventValid(event)) { TeleportUtils.teleport(player, event.getTo()); - } else if (player.isOnline() && isEventValid(event)) { - player.teleport(event.getTo()); } }); } diff --git a/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java b/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java index ed938518..c8469e86 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java @@ -48,11 +48,6 @@ public final class SecuritySettings implements SettingsHolder { public static final Property ADVANCED_SHULKER_FIX = newProperty("3rdPartyFeature.fixes.advancedShulkerFix", false); - @Comment({"Choose the best teleport method by server brand?", - "(Enable this if you are using Paper/Folia)"}) - public static final Property SMART_ASYNC_TELEPORT = - newProperty("3rdPartyFeature.optimizes.smartAsyncTeleport", true); - @Comment("Send a GUI captcha to unregistered players?(Requires ProtocolLib)") public static final Property GUI_CAPTCHA = newProperty("3rdPartyFeature.features.captcha.guiCaptcha", false); diff --git a/src/main/java/fr/xephi/authme/util/TeleportUtils.java b/src/main/java/fr/xephi/authme/util/TeleportUtils.java index a6594447..4a043b17 100644 --- a/src/main/java/fr/xephi/authme/util/TeleportUtils.java +++ b/src/main/java/fr/xephi/authme/util/TeleportUtils.java @@ -3,24 +3,24 @@ package fr.xephi.authme.util; import org.bukkit.Location; import org.bukkit.entity.Player; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.concurrent.CompletableFuture; /** * This class is a utility class for handling async teleportation of players in game. */ public class TeleportUtils { - private static Method teleportAsyncMethod; + private static MethodHandle teleportAsyncMethodHandle; static { - try {//Detect Paper class - Class paperClass = Class.forName("com.destroystokyo.paper.PaperConfig"); - teleportAsyncMethod = Player.class.getMethod("teleportAsync", Location.class); - teleportAsyncMethod.setAccessible(true); - // if detected,use teleportAsync() - } catch (ClassNotFoundException | NoSuchMethodException e) { - teleportAsyncMethod = null; - //if not, set method to null + try { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + teleportAsyncMethodHandle = lookup.findVirtual(Player.class, "teleportAsync", MethodType.methodType(CompletableFuture.class, Location.class)); + } catch (NoSuchMethodException | IllegalAccessException e) { + teleportAsyncMethodHandle = null; + // if not, set method handle to null } } @@ -31,10 +31,10 @@ public class TeleportUtils { * @param location Where should the player be teleported */ public static void teleport(Player player, Location location) { - if (teleportAsyncMethod != null) { + if (teleportAsyncMethodHandle != null) { try { - teleportAsyncMethod.invoke(player, location); - } catch (IllegalAccessException | InvocationTargetException e) { + teleportAsyncMethodHandle.invoke(player, location); + } catch (Throwable throwable) { player.teleport(location); } } else {