Async teleport is now default >v<
This commit is contained in:
parent
ae76066db6
commit
42e907580c
@ -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());
|
||||
}
|
||||
});
|
||||
//player.teleport(spawnLoader.getFirstSpawn());
|
||||
}
|
||||
|
||||
@ -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());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
messages.send(player, MessageKey.LOCATION_FIX_UNDERGROUND_CANT_FIX);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -48,11 +48,6 @@ public final class SecuritySettings implements SettingsHolder {
|
||||
public static final Property<Boolean> 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<Boolean> SMART_ASYNC_TELEPORT =
|
||||
newProperty("3rdPartyFeature.optimizes.smartAsyncTeleport", true);
|
||||
|
||||
@Comment("Send a GUI captcha to unregistered players?(Requires ProtocolLib)")
|
||||
public static final Property<Boolean> GUI_CAPTCHA =
|
||||
newProperty("3rdPartyFeature.features.captcha.guiCaptcha", false);
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user