From 2fa30098f8c4f42861c50fb9bad61d839b5a16b3 Mon Sep 17 00:00:00 2001 From: Subu19 Date: Mon, 20 May 2024 17:04:26 +0545 Subject: [PATCH 1/2] Fix: Teleporting Players to Spawn on Login with teleportUnAuthedToSpawn=true Issue: When changing the config option teleportUnAuthedToSpawn=true during gameplay, players were teleported to spawn on their next login. It only happens for the first time after the update. Patch: AuthMe now checks the player's last logout location from Essentials if it is not found in the AuthMe database. This ensures players are teleported to their last known location instead of the spawn point when the configuration is changed mid-game. --- .../authme/service/TeleportationService.java | 7 ++- .../fr/xephi/authme/settings/SpawnLoader.java | 50 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/service/TeleportationService.java b/src/main/java/fr/xephi/authme/service/TeleportationService.java index f0eb7f851a..4da077322e 100644 --- a/src/main/java/fr/xephi/authme/service/TeleportationService.java +++ b/src/main/java/fr/xephi/authme/service/TeleportationService.java @@ -146,7 +146,12 @@ public void teleportOnLogin(final Player player, PlayerAuth auth, LimboPlayer li teleportBackFromSpawn(player, location); } else if (limbo != null && limbo.getLocation() != null) { logger.debug("Teleporting `{0}` after login, based on the limbo player", player.getName()); - teleportBackFromSpawn(player, limbo.getLocation()); + //check for essential's quit location exists + Location location = spawnLoader.getEssentialsQuitLocation(player); + if(location != null) + teleportBackFromSpawn(player, location); + else + teleportBackFromSpawn(player, limbo.getLocation()); } } } diff --git a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java index 47e9711de2..7122422f49 100644 --- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java +++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java @@ -128,6 +128,56 @@ public void loadEssentialsSpawn() { } } + /** + * Retrieves the last logout location of a player from their Essentials data file. + * + * This function fetches the player's data file from the Essentials data folder, + * reads the 'logoutlocation' section, and constructs a Location object from it. + * If the file or the location data is not found, it returns null. + * + * @param player The player whose logout location is to be retrieved. + * @return The last known logout location of the player, or null if not found. + */ + public Location getEssentialsQuitLocation(Player player) { + File essentialsFolder = pluginHookService.getEssentialsDataFolder(); + if (essentialsFolder == null) { + return null; + } + + String path = "userdata/" + player.getUniqueId() + ".yml"; + File essentialsUserdataFile = new File(essentialsFolder, path); + logger.info(essentialsUserdataFile.getAbsolutePath()); + if (essentialsUserdataFile.exists()) { + logger.info("Found location!"); + + YamlConfiguration config = YamlConfiguration.loadConfiguration(essentialsUserdataFile); + if (config.contains("logoutlocation")) { + String worldName = config.getString("logoutlocation.world-name"); + World world = Bukkit.getWorld(worldName); + if (world == null) { + logger.warning("World not found: " + worldName); + return null; + } + double x = config.getDouble("logoutlocation.x"); + double y = config.getDouble("logoutlocation.y"); + double z = config.getDouble("logoutlocation.z"); + float yaw = (float) config.getDouble("logoutlocation.yaw"); + float pitch = (float) config.getDouble("logoutlocation.pitch"); + + Location location = new Location(world, x, y, z, yaw, pitch); + logger.info(location.toString()); + return location; + } else { + logger.info("logoutlocation not found in file: " + essentialsUserdataFile.getAbsolutePath()); + return null; + } + } else { + logger.info("Essentials userdata file not found: '" + essentialsUserdataFile.getAbsolutePath() + "'"); + return null; + } + } + + /** * Unset the spawn point defined in EssentialsSpawn. */ From 172f97e9c7c2357d3abefba69edc2cb207aac064 Mon Sep 17 00:00:00 2001 From: Subu19 Date: Mon, 20 May 2024 17:22:57 +0545 Subject: [PATCH 2/2] Remove unnecessary logs --- src/main/java/fr/xephi/authme/settings/SpawnLoader.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java index 7122422f49..1841835d13 100644 --- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java +++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java @@ -146,16 +146,13 @@ public Location getEssentialsQuitLocation(Player player) { String path = "userdata/" + player.getUniqueId() + ".yml"; File essentialsUserdataFile = new File(essentialsFolder, path); - logger.info(essentialsUserdataFile.getAbsolutePath()); if (essentialsUserdataFile.exists()) { - logger.info("Found location!"); YamlConfiguration config = YamlConfiguration.loadConfiguration(essentialsUserdataFile); if (config.contains("logoutlocation")) { String worldName = config.getString("logoutlocation.world-name"); World world = Bukkit.getWorld(worldName); if (world == null) { - logger.warning("World not found: " + worldName); return null; } double x = config.getDouble("logoutlocation.x"); @@ -165,14 +162,13 @@ public Location getEssentialsQuitLocation(Player player) { float pitch = (float) config.getDouble("logoutlocation.pitch"); Location location = new Location(world, x, y, z, yaw, pitch); - logger.info(location.toString()); return location; } else { - logger.info("logoutlocation not found in file: " + essentialsUserdataFile.getAbsolutePath()); + logger.debug("logoutlocation not found in userdata file: " + essentialsUserdataFile.getAbsolutePath()); return null; } } else { - logger.info("Essentials userdata file not found: '" + essentialsUserdataFile.getAbsolutePath() + "'"); + logger.debug("Essentials userdata file not found: '" + essentialsUserdataFile.getAbsolutePath() + "'"); return null; } }