Fix: Teleports to spawn at every join
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user