/*
 * Copyright 2015 CrystalCraftMC
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.crystalcraftmc.iceball;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffect;

public class DelayedTeleport implements Listener {
	private IceBall plugin;
	private boolean hasMoved;
	private int accumulator;
	public DelayedTeleport(IceBall ib, Player p) {
		final Player pp = p; //final variable needed to use in run method
		accumulator = 0;
		plugin = ib;
		plugin.getServer().getPluginManager().registerEvents(this, plugin);
		hasMoved = false;
		p.sendMessage(ChatColor.GOLD + "Teleportation will commence in " + ChatColor.RED + "5 seconds" +
				ChatColor.GOLD + ". don't move.");
		p.sendMessage(ChatColor.AQUA + "Any potion effects will be removed upon arrival.");
		plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
			public void run() {
				if(!hasMoved) {
					for(PotionEffect effects : pp.getActivePotionEffects())
						pp.removePotionEffect(effects.getType());
					Location locS = new Location(pp.getWorld(), (double)plugin.X,
							(double)(plugin.Y+1), (double)plugin.Z);
					locS.setYaw(plugin.FIGHTYAW);
					locS.setPitch(plugin.FIGHTPITCH);
					pp.teleport(locS);
					pp.sendMessage(ChatColor.GOLD + "Welcome to the" + ChatColor.AQUA +
							" CCMC " + ChatColor.GOLD + "SnowBall Arena!");
					pp.sendMessage(ChatColor.RED + "Note that commands have been disabled here.");
					pp.sendMessage(ChatColor.RED + "Type " + ChatColor.BOLD + "/snowleave" +
							ChatColor.RED + "  to leave the arena.");
				}
			}
		}, (long)100);
	}
	@EventHandler
	public void moveEvent(PlayerMoveEvent e) {
		hasMoved = true;
		accumulator++;
		if(accumulator == 1)
			e.getPlayer().sendMessage(ChatColor.RED + "Teleport cancelled due to your movement.");
		if(accumulator > 100)
			accumulator = 10;
	}
}

@@ -1035,16 +1035,49 @@
 ulator;%0A
+%09private final Player thePlayer;%0A
 %09public 
@@ -1122,24 +1122,18 @@
 %7B%0A%09%09
-final 
+the
 Player 
-pp 
 = p;
@@ -1161,17 +1161,11 @@
 ded 
-to use in
+for
  run
@@ -1680,18 +1680,25 @@
 fects : 
-pp
+thePlayer
 .getActi
@@ -1722,18 +1722,25 @@
 )%0A%09%09%09%09%09%09
-pp
+thePlayer
 .removeP
@@ -1805,18 +1805,25 @@
 ocation(
-pp
+thePlayer
 .getWorl
@@ -1972,18 +1972,25 @@
 );%0A%09%09%09%09%09
-pp
+thePlayer
 .telepor
@@ -1995,34 +1995,41 @@
 ort(locS);%0A%09%09%09%09%09
-pp
+thePlayer
 .sendMessage(Cha
@@ -2130,34 +2130,41 @@
  Arena!%22);%0A%09%09%09%09%09
-pp
+thePlayer
 .sendMessage(Cha
@@ -2229,18 +2229,25 @@
 );%0A%09%09%09%09%09
-pp
+thePlayer
 .sendMes
@@ -2448,16 +2448,77 @@
 nt e) %7B%0A
+%09%09if(e.getPlayer().getName().equals(thePlayer.getName())) %7B%0A%09
 %09%09hasMov
@@ -2530,16 +2530,17 @@
 true;%0A%09%09
+%09
 accumula
@@ -2546,16 +2546,17 @@
 ator++;%0A
+%09
 %09%09if(acc
@@ -2570,16 +2570,17 @@
 r == 1)%0A
+%09
 %09%09%09e.get
@@ -2663,16 +2663,17 @@
 t.%22);%0A%09%09
+%09
 if(accum
@@ -2685,24 +2685,25 @@
 r %3E 100)%0A%09%09%09
+%09
 accumulator 
@@ -2708,13 +2708,17 @@
 r = 10;%0A
+%09%09%7D%0A
 %09%7D%0A%7D%0A

Update DelayedTeleport.java to fix TP bug