From 14b58dcdc72f265dab54257c65414f5a2cf04967 Mon Sep 17 00:00:00 2001 From: Maaattqc Date: Sat, 10 May 2025 12:03:10 -0400 Subject: [PATCH] Update PaperLibreLogin.java Fix when player registers for the first time, he will get tp to the spawnLocation of the default world in the server.properties, every other login, he gets tp to the normal lastLocation he was before, small problem is that the first login tp he is always looking east because i cant get the yaw from the worlds it's always returning 0 --- .../librelogin/paper/PaperLibreLogin.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Plugin/src/main/java/xyz/kyngs/librelogin/paper/PaperLibreLogin.java b/Plugin/src/main/java/xyz/kyngs/librelogin/paper/PaperLibreLogin.java index aa48d21c..3963edc8 100644 --- a/Plugin/src/main/java/xyz/kyngs/librelogin/paper/PaperLibreLogin.java +++ b/Plugin/src/main/java/xyz/kyngs/librelogin/paper/PaperLibreLogin.java @@ -17,8 +17,12 @@ import org.bstats.charts.CustomChart; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; import xyz.kyngs.librelogin.api.Logger; import xyz.kyngs.librelogin.api.database.User; import xyz.kyngs.librelogin.api.event.exception.EventCancelledException; @@ -32,6 +36,7 @@ import java.io.InputStream; import java.util.UUID; +import static org.bukkit.Bukkit.getWorld; import static xyz.kyngs.librelogin.common.config.ConfigurationKeys.DEBUG; public class PaperLibreLogin extends AuthenticLibreLogin { @@ -183,11 +188,44 @@ public void authorize(Player player, User user, Audience audience) { } var finalLocation = location; + + if(isFirstJoin(player, Bukkit.getWorlds().get(0))){ + Location preciseSpawn = new Location( + getWorld(Bukkit.getWorlds().get(0).getName()), + Bukkit.getWorlds().get(0).getSpawnLocation().getX() + 0.5, + Bukkit.getWorlds().get(0).getSpawnLocation().getY(), + Bukkit.getWorlds().get(0).getSpawnLocation().getZ() + 0.5, + (float) -90, // player looking direction is east + // Bukkit.getWorlds().get(0).getSpawnLocation().getYaw() always returns 0 bruh.. + Bukkit.getWorlds().get(0).getSpawnLocation().getPitch() + ); + + PaperUtil.runSyncAndWait(() -> player.teleportAsync(preciseSpawn), this); + return; + } + PaperUtil.runSyncAndWait(() -> player.teleportAsync(finalLocation), this); } catch (EventCancelledException ignored) {} } + public boolean isFirstJoin(Player player, World world) { + // Get the persistent data container for the world + PersistentDataContainer worldContainer = world.getPersistentDataContainer(); + + // Create a unique NamespacedKey for this player in this world + NamespacedKey playerKey = new NamespacedKey("librelogin", "player_visited_" + player.getUniqueId().toString()); + + // Check if the world has data for this player + if (worldContainer.has(playerKey, PersistentDataType.BYTE)) { + return false; // Player has joined this world before + } else { + // Store data indicating the player has now visited this world + worldContainer.set(playerKey, PersistentDataType.BYTE, (byte)1); + return true; // First time joining this world + } + } + @Override public CancellableTask delay(Runnable runnable, long delayInMillis) { var task = Bukkit.getScheduler().runTaskLaterAsynchronously(bootstrap, runnable, delayInMillis / 50);