package com.ForgeEssentials.util;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.management.ServerConfigurationManager;

import com.ForgeEssentials.core.PlayerInfo;
import com.ForgeEssentials.util.AreaSelector.WarpPoint;
import com.ForgeEssentials.util.AreaSelector.WorldPoint;

import cpw.mods.fml.common.FMLCommonHandler;

/**
 * Uses by TeleportCenter.
 * 
 * @author Dries007
 * 
 */

public class TPdata
{
	private WarpPoint		point;
	private EntityPlayer	player;
	private WorldPoint		lastPos;
	private WorldPoint		currentPos;
	int						waittime;

	public TPdata(WarpPoint point, EntityPlayer player)
	{
		this.point = point;
		this.player = player;
		waittime = TeleportCenter.tpWarmup;
		lastPos = new WarpPoint(player);
	}

	public void count()
	{
		currentPos = new WarpPoint(player);
		if (!lastPos.equals(currentPos))
		{
			TeleportCenter.abort(this);
		}

		waittime--;
		if (waittime == 0)
		{
			doTP();
		}
	}

	public void doTP()
	{
		PlayerInfo.getPlayerInfo(player).back = new WarpPoint(player);
		ServerConfigurationManager server = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager();
		if (player.dimension != point.dim)
		{
			server.transferPlayerToDimension((EntityPlayerMP) player, point.dim);
		}
		((EntityPlayerMP) player).playerNetServerHandler.setPlayerLocation(point.x, point.y, point.z, point.yaw, point.pitch);
		PlayerInfo.getPlayerInfo(player).TPcooldown = TeleportCenter.tpCooldown;
		TeleportCenter.TPdone(this);
	}

	public EntityPlayer getPlayer()
	{
		return player;
	}
}

@@ -1024,16 +1024,27 @@
 TP()%0A%09%7B%0A
+%09%09try%0A%09%09%7B%0A%09
 %09%09Player
@@ -1100,16 +1100,17 @@
 layer);%0A
+%09
 %09%09Server
@@ -1221,24 +1221,25 @@
 anager();%0A%09%09
+%09
 if (player.d
@@ -1263,18 +1263,20 @@
 .dim)%0A%09%09
+%09
 %7B%0A
+%09
 %09%09%09serve
@@ -1342,18 +1342,20 @@
 dim);%0A%09%09
+%09
 %7D%0A
+%09
 %09%09((Enti
@@ -1469,16 +1469,17 @@
 tch);%0A%09%09
+%09
 PlayerIn
@@ -1545,16 +1545,17 @@
 down;%0A%09%09
+%09
 Teleport
@@ -1575,16 +1575,151 @@
 (this);%0A
+%09%09%7D%0A%09%09catch (Exception e)%0A%09%09%7B%0A%09%09%09OutputHandler.warning(%22Someone tried to crash the server when warping!%22);%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A
 %09%7D%0A%0A%09pub

Fix NPE with TP system