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.ResidenceManager;

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

public class CommandInfo extends BaseCommand {
    ResidenceMain plugin;

    public CommandInfo(final ResidenceMain plugin) {
        super("i");
        this.plugin = plugin;
        setOnlyPlayerExecutable();
    }

    @Override
    public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
        final Player player = (Player) sender;

        final ResidenceManager rmanager = plugin.getResidenceManager();
        final Language language = plugin.getLanguage();

        if (args.length == 0) {
            final String area = rmanager.getNameByLoc(player.getLocation());
            if (area != null) {
                rmanager.printAreaInfo(area, player);
            } else {
                player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
            }
        } else {
            if (args.length == 1) {
                rmanager.printAreaInfo(args[0], player);
            }
        }
    }

}
