From 711aad60b76eff1be2cb7d2d65becbcb4322092e Mon Sep 17 00:00:00 2001 From: Cyanoure Date: Sun, 29 Mar 2026 21:25:31 +0200 Subject: [PATCH] Fix: Teleports to spawn at every join --- .../minecraft/gospawn/Events.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/hu/kozelkaricsi/minecraft/gospawn/Events.java b/src/main/java/hu/kozelkaricsi/minecraft/gospawn/Events.java index f38af86..09fdd46 100644 --- a/src/main/java/hu/kozelkaricsi/minecraft/gospawn/Events.java +++ b/src/main/java/hu/kozelkaricsi/minecraft/gospawn/Events.java @@ -6,50 +6,48 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.spigotmc.event.player.PlayerSpawnLocationEvent; +import org.bukkit.event.player.*; import java.util.UUID; public class Events implements Listener { @EventHandler (priority = EventPriority.HIGH) - public void onSpawn(PlayerSpawnLocationEvent e) { + public void onJoin(PlayerJoinEvent e) { + Player player = e.getPlayer(); + Location loc = GoSpawn.instance.getSpawnLocation(); if (loc == null) { return; } - if (!e.getPlayer().hasPlayedBefore()) { - GoSpawn.instance.debug("Player '" + e.getPlayer().getName() + "' has not played here before."); - e.setSpawnLocation(loc); + UUID lastWorld = GoSpawn.instance.getPlayerLastWorld(player); + + if (!player.hasPlayedBefore() && lastWorld == null) { + GoSpawn.instance.debug("Player '" + player.getName() + "' has not played here before."); + player.teleport(loc); return; } else { - GoSpawn.instance.debug("Player '" + e.getPlayer().getName() + "' has already played here before."); + GoSpawn.instance.debug("Player '" + player.getName() + "' has already played here before."); } - Location currentLoc = e.getSpawnLocation(); + Location currentLoc = player.getLocation(); - GoSpawn.instance.debug("Current world of player '" + e.getPlayer().getName() + "' is " + currentLoc.getWorld().getName() + "(" + currentLoc.getWorld().getUID() + ")"); + GoSpawn.instance.debug("Current world of player '" + player.getName() + "' is " + currentLoc.getWorld().getName() + "(" + currentLoc.getWorld().getUID() + ")"); if (GoSpawn.instance.shouldForceRespawnIfInWorld(currentLoc.getWorld())) { - e.setSpawnLocation(loc); - GoSpawn.instance.debug("Config says that " + e.getPlayer().getName() + " should be teleported to the spawn, because their world is not whitelisted."); + GoSpawn.instance.debug("Config says that " + player.getName() + " should be teleported to the spawn, because their world is not whitelisted."); + player.teleport(loc); return; } - UUID lastWorld = GoSpawn.instance.getPlayerLastWorld(e.getPlayer()); - if (lastWorld == null) { - GoSpawn.instance.debug("No last world stored for player " + e.getPlayer().getName() + "."); + GoSpawn.instance.debug("No last world stored for player " + player.getName() + "."); } else { - GoSpawn.instance.debug("The UID of the last world of player " + e.getPlayer().getName() + " is " + lastWorld + "."); + GoSpawn.instance.debug("The UID of the last world of player " + player.getName() + " is " + lastWorld + "."); } if (lastWorld != null && Bukkit.getWorld(lastWorld) == null) { - e.setSpawnLocation(loc); + player.teleport(loc); } }