package org.black_ixx.bossshop.command;

import java.util.ArrayList;

import org.black_ixx.bossshop.core.BSShopHolder;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;

import cc.util.bossshop.FBukkit;


public class CommandClose extends ACommandBase{

    public CommandClose(CommandExc exector){
        super(exector);
    }

    @Override
    public boolean execute(CommandSender pSender,String[] pArgs){
        //bs close <player>
        if(!pSender.hasPermission(this.mPluginName+".close.other")) return noPermit(pSender);
        if(pArgs.length!=1) return help(pSender);
        Player tPlayer=Bukkit.getPlayer(pArgs[0]);
        if(tPlayer==null)
            return send(pSender,C("Main.NoPlayerFound"));
        if(!tPlayer.isOnline())
            return send(pSender,C("Main.PlayerOffline"));
        Inventory inv=tPlayer.getOpenInventory().getTopInventory();
        if(!(inv.getHolder() instanceof BSShopHolder))
            return send(pSender,C("Main.PlayerNotOpenBSShop"));
        tPlayer.closeInventory();
        return send(pSender,C("Main.AlreadyClosePlayerShop"));
    }

    @Override
    public ArrayList<String> getHelp(CommandSender pSender,boolean pAll){
        ArrayList<String> list=new ArrayList<>();
        if(pSender.hasPermission(this.mPluginName+".close.other")){
            list.add(this.mMainCmdLabel+" close <"+C("Word.PlayerName")+">");
            list.add(C("Help.ClosePlayerShop"));
        }
        return list;
    }
    
    @Override
    public ArrayList<String> getSubCommand(CommandSender pSender,String[] pArgs){
        return FBukkit.getOnlinePlayersName();
    }

    @Override
    public int getMaxArgumentLength(){
        return 1;
    }

}
