package pw.yumc.Residence.commandsub;

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.ClaimedResidence;
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 CommandClearFlags extends BaseCommand {
    ResidenceMain plugin;

    public CommandClearFlags(final ResidenceMain plugin) {
        super("cf");
        this.plugin = plugin;
        setMinimumArguments(1);
        setOnlyPlayerExecutable();
        setPossibleArguments("<领地名称>");
    }

    @Override
    public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
        final Player player = (Player) sender;
        final boolean resadmin = (command != null);
        final ResidenceManager rmanager = plugin.getResidenceManager();
        final Language language = plugin.getLanguage();

        if (!resadmin) {
            player.sendMessage(ChatColor.RED + language.getPhrase("NoPermission"));
            return;
        }
        final ClaimedResidence area = rmanager.getByName(args[1]);
        if (area != null) {
            area.getPermissions().clearFlags();
            player.sendMessage(ChatColor.GREEN + language.getPhrase("FlagsCleared"));
        } else {
            player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
        }
    }

}
