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.service.BukkitService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
|
||||||
import fr.xephi.authme.util.TeleportUtils;
|
import fr.xephi.authme.util.TeleportUtils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -28,11 +27,7 @@ public class FirstSpawnCommand extends PlayerCommand {
|
|||||||
} else {
|
} else {
|
||||||
//String name= player.getName();
|
//String name= player.getName();
|
||||||
bukkitService.runTaskIfFolia(player, () -> {
|
bukkitService.runTaskIfFolia(player, () -> {
|
||||||
if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) {
|
TeleportUtils.teleport(player, spawnLoader.getFirstSpawn());
|
||||||
TeleportUtils.teleport(player, spawnLoader.getFirstSpawn());
|
|
||||||
} else {
|
|
||||||
player.teleport(spawnLoader.getFirstSpawn());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
//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.command.PlayerCommand;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
|
import fr.xephi.authme.util.TeleportUtils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
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");
|
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
|
||||||
} else {
|
} else {
|
||||||
bukkitService.runTaskIfFolia(player, () -> {
|
bukkitService.runTaskIfFolia(player, () -> {
|
||||||
player.teleport(spawnLoader.getSpawn());
|
TeleportUtils.teleport(player, spawnLoader.getSpawn());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,11 +75,7 @@ public class LoginLocationFixListener implements Listener {
|
|||||||
boolean solved = false;
|
boolean solved = false;
|
||||||
for (BlockFace face : faces) {
|
for (BlockFace face : faces) {
|
||||||
if (JoinBlock.getRelative(face).getType().equals(Material.AIR) && JoinBlock.getRelative(face).getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
|
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));
|
||||||
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;
|
solved = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -107,20 +103,12 @@ public class LoginLocationFixListener implements Listener {
|
|||||||
if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) {
|
if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) {
|
||||||
JoinBlock.getRelative(BlockFace.DOWN).setType(Material.DIRT);
|
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));
|
||||||
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);
|
messages.send(player, MessageKey.LOCATION_FIX_UNDERGROUND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i == MaxHeight) {
|
if (i == MaxHeight) {
|
||||||
if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) {
|
TeleportUtils.teleport(player, JoinBlock.getLocation().add(0.5, 1.1, 0.5));
|
||||||
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);
|
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.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
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.TeleportUtils;
|
||||||
import fr.xephi.authme.util.message.MiniMessageUtils;
|
import fr.xephi.authme.util.message.MiniMessageUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -376,17 +375,9 @@ public class PlayerListener implements Listener{
|
|||||||
Location spawn = spawnLoader.getSpawnLocation(player);
|
Location spawn = spawnLoader.getSpawnLocation(player);
|
||||||
if (spawn != null && spawn.getWorld() != null) {
|
if (spawn != null && spawn.getWorld() != null) {
|
||||||
if (!player.getWorld().equals(spawn.getWorld())) {
|
if (!player.getWorld().equals(spawn.getWorld())) {
|
||||||
if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) {
|
TeleportUtils.teleport(player,spawn);
|
||||||
TeleportUtils.teleport(player,spawn);
|
|
||||||
} else {
|
|
||||||
player.teleport(spawn);
|
|
||||||
}
|
|
||||||
} else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) {
|
} else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) {
|
||||||
if (settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) {
|
TeleportUtils.teleport(player,spawn);
|
||||||
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.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
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.TeleportUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -189,10 +188,8 @@ public class TeleportationService implements Reloadable {
|
|||||||
private void performTeleportation(final Player player, final AbstractTeleportEvent event) {
|
private void performTeleportation(final Player player, final AbstractTeleportEvent event) {
|
||||||
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
|
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
|
||||||
bukkitService.callEvent(event);
|
bukkitService.callEvent(event);
|
||||||
if (player.isOnline() && isEventValid(event) && settings.getProperty(SecuritySettings.SMART_ASYNC_TELEPORT)) {
|
if (player.isOnline() && isEventValid(event)) {
|
||||||
TeleportUtils.teleport(player, event.getTo());
|
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 =
|
public static final Property<Boolean> ADVANCED_SHULKER_FIX =
|
||||||
newProperty("3rdPartyFeature.fixes.advancedShulkerFix", false);
|
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)")
|
@Comment("Send a GUI captcha to unregistered players?(Requires ProtocolLib)")
|
||||||
public static final Property<Boolean> GUI_CAPTCHA =
|
public static final Property<Boolean> GUI_CAPTCHA =
|
||||||
newProperty("3rdPartyFeature.features.captcha.guiCaptcha", false);
|
newProperty("3rdPartyFeature.features.captcha.guiCaptcha", false);
|
||||||
|
|||||||
@ -3,24 +3,24 @@ package fr.xephi.authme.util;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.reflect.Method;
|
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.
|
* This class is a utility class for handling async teleportation of players in game.
|
||||||
*/
|
*/
|
||||||
public class TeleportUtils {
|
public class TeleportUtils {
|
||||||
private static Method teleportAsyncMethod;
|
private static MethodHandle teleportAsyncMethodHandle;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {//Detect Paper class
|
try {
|
||||||
Class<?> paperClass = Class.forName("com.destroystokyo.paper.PaperConfig");
|
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||||
teleportAsyncMethod = Player.class.getMethod("teleportAsync", Location.class);
|
teleportAsyncMethodHandle = lookup.findVirtual(Player.class, "teleportAsync", MethodType.methodType(CompletableFuture.class, Location.class));
|
||||||
teleportAsyncMethod.setAccessible(true);
|
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||||
// if detected,use teleportAsync()
|
teleportAsyncMethodHandle = null;
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
// if not, set method handle to null
|
||||||
teleportAsyncMethod = null;
|
|
||||||
//if not, set method to null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,10 +31,10 @@ public class TeleportUtils {
|
|||||||
* @param location Where should the player be teleported
|
* @param location Where should the player be teleported
|
||||||
*/
|
*/
|
||||||
public static void teleport(Player player, Location location) {
|
public static void teleport(Player player, Location location) {
|
||||||
if (teleportAsyncMethod != null) {
|
if (teleportAsyncMethodHandle != null) {
|
||||||
try {
|
try {
|
||||||
teleportAsyncMethod.invoke(player, location);
|
teleportAsyncMethodHandle.invoke(player, location);
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (Throwable throwable) {
|
||||||
player.teleport(location);
|
player.teleport(location);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user