Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Teleporting Players to Spawn on Login with teleportUnAuthedToSpawn=true #2823

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/fr/xephi/authme/settings/SpawnLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down