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..1841835d13 100644 --- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java +++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java @@ -128,6 +128,52 @@ 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); + if (essentialsUserdataFile.exists()) { + + YamlConfiguration config = YamlConfiguration.loadConfiguration(essentialsUserdataFile); + if (config.contains("logoutlocation")) { + String worldName = config.getString("logoutlocation.world-name"); + World world = Bukkit.getWorld(worldName); + if (world == null) { + 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); + return location; + } else { + logger.debug("logoutlocation not found in userdata file: " + essentialsUserdataFile.getAbsolutePath()); + return null; + } + } else { + logger.debug("Essentials userdata file not found: '" + essentialsUserdataFile.getAbsolutePath() + "'"); + return null; + } + } + + /** * Unset the spawn point defined in EssentialsSpawn. */