package cn.citycraft.AuthMe.process.quit;

import org.bukkit.GameMode;
import org.bukkit.entity.Player;

import cn.citycraft.AuthMe.AuthMe;
import cn.citycraft.AuthMe.settings.Settings;

public class ProcessSyncronousPlayerQuit implements Runnable {

	protected boolean isFlying;
	protected boolean isOp;
	protected boolean needToChange;
	protected Player player;
	protected AuthMe plugin;

	public ProcessSyncronousPlayerQuit(AuthMe plugin, Player player, boolean isOp, boolean isFlying, boolean needToChange) {
		this.plugin = plugin;
		this.player = player;
		this.isOp = isOp;
		this.isFlying = isFlying;
		this.needToChange = needToChange;
	}

	@Override
	public void run() {

		if (needToChange) {
			player.setOp(isOp);
			if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
				player.setAllowFlight(isFlying);
				player.setFlying(isFlying);
			}
		}
		try {
			player.getVehicle().eject();
		} catch (Exception e) {
		}
	}
}
