package net.simpvp.Jail;

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.AsyncPlayerPreLoginEvent;
import org.bukkit.scheduler.BukkitRunnable;

public class PlayerLogin implements Listener {

	@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true)
	public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
		if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED)
			return;

		final JailedPlayer jailedplayer = SQLite.get_player_info(event.getUniqueId());
		if (jailedplayer == null)
			return;

		if (jailedplayer.to_be_released) {
			/* as the player will not have an entity associated with them at this
			 * stage, we have to try for a bit to see when they're done logging in
			 * and then teleport them then */
			final long start = System.currentTimeMillis();

			new BukkitRunnable() {
				@Override
				public void run() {
					if (System.currentTimeMillis() > start + 10 * 1000) {
						this.cancel();
						Jail.instance.getLogger().info("Unable to unjail " + jailedplayer.playername);
					}

					Player player = Jail.instance.getServer().getPlayer(jailedplayer.uuid);
					if (player != null) {
						player.teleport(jailedplayer.location);
						SQLite.delete_player_info(player.getUniqueId());
						Jail.instance.getLogger().info("Releasing " + jailedplayer.playername + " from jail.");
						this.cancel();
					}
				}
			}.runTaskTimer(Jail.instance, 20, 20);

			return;
		}

		Jail.instance.getLogger().info("Jailed player " + event.getName() + " has connected.");
		jailedplayer.add();
	}

}


@@ -194,33 +194,24 @@
 .player.
-Async
 Player
-PreLog
+Jo
 inEvent;
@@ -348,14 +348,15 @@
 ity.
-NORMAL
+MONITOR
 , ig
@@ -402,33 +402,24 @@
 erLogin(
-Async
 Player
-PreLog
+Jo
 inEvent 
@@ -431,93 +431,8 @@
 ) %7B%0A
-%09%09if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED)%0A%09%09%09return;%0A%0A
 %09%09fi
@@ -492,16 +492,28 @@
 o(event.
+getPlayer().
 getUniqu
@@ -1519,16 +1519,28 @@
 + event.
+getPlayer().
 getName(

Use PlayerJoinEvent instead of PlayerPreLoginEvent It seems to be more stable