Fix: Teleports to spawn at every join

This commit is contained in:
Cyanoure
2026-03-29 21:25:31 +02:00
parent fa02392ca1
commit 711aad60b7

View File

@@ -6,50 +6,48 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.*;
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 java.util.UUID; import java.util.UUID;
public class Events implements Listener { public class Events implements Listener {
@EventHandler (priority = EventPriority.HIGH) @EventHandler (priority = EventPriority.HIGH)
public void onSpawn(PlayerSpawnLocationEvent e) { public void onJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
Location loc = GoSpawn.instance.getSpawnLocation(); Location loc = GoSpawn.instance.getSpawnLocation();
if (loc == null) { if (loc == null) {
return; return;
} }
if (!e.getPlayer().hasPlayedBefore()) { UUID lastWorld = GoSpawn.instance.getPlayerLastWorld(player);
GoSpawn.instance.debug("Player '" + e.getPlayer().getName() + "' has not played here before.");
e.setSpawnLocation(loc); if (!player.hasPlayedBefore() && lastWorld == null) {
GoSpawn.instance.debug("Player '" + player.getName() + "' has not played here before.");
player.teleport(loc);
return; return;
} else { } 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())) { if (GoSpawn.instance.shouldForceRespawnIfInWorld(currentLoc.getWorld())) {
e.setSpawnLocation(loc); GoSpawn.instance.debug("Config says that " + player.getName() + " should be teleported to the spawn, because their world is not whitelisted.");
GoSpawn.instance.debug("Config says that " + e.getPlayer().getName() + " should be teleported to the spawn, because their world is not whitelisted."); player.teleport(loc);
return; return;
} }
UUID lastWorld = GoSpawn.instance.getPlayerLastWorld(e.getPlayer());
if (lastWorld == null) { 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 { } 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) { if (lastWorld != null && Bukkit.getWorld(lastWorld) == null) {
e.setSpawnLocation(loc); player.teleport(loc);
} }
} }