package cn.citycraft.AuthMe.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import cn.citycraft.AuthMe.AuthMe;
import cn.citycraft.AuthMe.settings.Messages;

public class LoginCommand implements CommandExecutor {

	private Messages m = Messages.getInstance();
	private AuthMe plugin;

	public LoginCommand(AuthMe plugin) {
		this.plugin = plugin;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmnd, String label, final String[] args) {
		if (!(sender instanceof Player)) {
			return true;
		}

		final Player player = (Player) sender;

		if (args.length == 0) {
			m.send(player, "usage_log");
			return true;
		}

		if (!plugin.authmePermissible(player, "authme." + label.toLowerCase())) {
			m.send(player, "no_perm");
			return true;
		}
		plugin.management.performLogin(player, args[0], false);
		return true;
	}
}
