package cn.citycraft.AuthMe.task;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import cn.citycraft.AuthMe.AuthMe;
import cn.citycraft.AuthMe.cache.auth.PlayerCache;
import cn.citycraft.AuthMe.settings.Messages;

public class TimeoutTask implements Runnable {

	private Messages m = Messages.getInstance();
	private String name;
	private Player player;
	private AuthMe plugin;

	public TimeoutTask(AuthMe plugin, String name, Player player) {
		this.plugin = plugin;
		this.name = name;
		this.player = player;
	}

	public String getName() {
		return name;
	}

	@Override
	public void run() {
		if (PlayerCache.getInstance().isAuthenticated(name))
			return;

		Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

			@Override
			public void run() {
				if (player.isOnline())
					player.kickPlayer(m.send("timeout")[0]);
			}
		});
	}
}
