package pw.yumc.Residence.commandsub;

import java.util.Map;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.bekvon.bukkit.residence.protection.ResidenceManager;

import cn.citycraft.PluginHelper.commands.BaseCommand;
import pw.yumc.Residence.ResidenceMain;
import pw.yumc.Residence.text.Language;

public class CommandConfirm extends BaseCommand {
    ResidenceMain plugin;

    public CommandConfirm(final ResidenceMain plugin) {
        super("confirm");
        this.plugin = plugin;
    }

    @Override
    public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
        Player player = null;
        final boolean resadmin = (command != null);
        final ResidenceManager rmanager = plugin.getResidenceManager();
        final Map<String, String> deleteConfirm = plugin.getDeleteConfirm();
        final Language language = plugin.getLanguage();
        String name = "Console";
        if (sender instanceof Player) {
            player = (Player) sender;
            name = player.getName();
        }
        final String area = deleteConfirm.get(name);
        if (area == null) {
            sender.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
        } else {
            rmanager.removeResidence(player, area, resadmin);
            deleteConfirm.remove(name);
            if (player == null) {
                sender.sendMessage(ChatColor.GREEN + language.getPhrase("ResidenceRemove", ChatColor.YELLOW + name + ChatColor.GREEN));
            }
        }
    }

}
