package net.simpvp.Misc;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.Location;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerRespawnEvent;

/**
 * Ensures players respawn at the exact spawn location
 */
public class ExactSpawn implements Listener {

	@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=false)
	public void onPlayerLogin(PlayerLoginEvent event) {
		if (event.getResult() != PlayerLoginEvent.Result.ALLOWED)
			return;

		if (event.getPlayer().hasPlayedBefore())
			return;

		Location loc = Misc.instance.getServer().getWorld("world").getSpawnLocation();
		loc.setX(loc.getX() + 0.5);
		loc.setZ(loc.getZ() + 0.5);

		event.getPlayer().teleport(loc);

	}

	@EventHandler(priority = EventPriority.LOW, ignoreCancelled=false)
	public void onPlayerRespawn(PlayerRespawnEvent event) {
		if (event.isBedSpawn())
			return;

		Location loc = Misc.instance.getServer().getWorld("world").getSpawnLocation();
		loc.setX(loc.getX() + 0.5);
		loc.setZ(loc.getZ() + 0.5);

		event.setRespawnLocation(loc);

	}

}


@@ -224,27 +224,26 @@
 layer.Player
-Log
+Jo
 inEvent;%0Aimp
@@ -501,27 +501,26 @@
 Login(Player
-Log
+Jo
 inEvent even
@@ -516,32 +516,33 @@
 nEvent event) %7B%0A
+%0A
 %09%09if (event.getR
@@ -544,70 +544,80 @@
 .get
-Result() != PlayerLoginEvent.Result.ALLOWED)%0A%09%09%09return;%0A%0A%09%09if 
+Player().hasPlayedBefore())%0A%09%09%09return;%0A%0A%09%09Misc.instance.getLogger().info
 (eve
@@ -635,36 +635,68 @@
 r().
-hasPlayedBefor
+getNam
 e()
-)
 %0A%09%09%09
-return
+%09+ %22 joined for first time. Porting to spawn.%22)
 ;%0A%0A%09

Fix bug with new players not properly spawning at exact world spawn