<?php

namespace duel\command\subcommand;

use pocketmine\command\CommandSender;

use duel\command\BoxingCommand;
use duel\command\SubCommand;
use pocketmine\utils\Config;
use duel\Loader;

class Deletar extends SubCommand
{
	
	/** @var DuelCommand */
	private $command;
	
	private $config;
	
	/**
	  * CreateSubCommand constructor.
	  * @param DuelCommand $command
	  */
	public function __construct(BoxingCommand $command)
	{
		$this->command = $command;
        $this->config = new Config(Loader::getInstance()->getDataFolder() . 'config.yml', Config::YAML);
	}
	
	/**
	  * @param CommandSender $sender
	  * @param array $args
	  */
	public function execute(CommandSender $sender, array $args)
	{
		if (count($args) < 2) {
			 $sender->sendMessage('§fUse §r'.$this->config->get('Cor_Eventos_Arena').'/boxing deletar <nome> §fpara deletar um boxing.');
			 return false;
		}
		$manager = $this->command->loader->arenaManager;
		
		if (!$manager->existsArena($args[1])) {
			 $sender->sendMessage(' §cO§f '.$args[1].' §cnão existe!');
			 return false;
		}
		$manager->removeArena($args[1]);
		$sender->sendMessage('§fO Boxing'.$this->config->get('Cor_Eventos_Arena').' '.$args[1].' §fFoi Deletado.');
		return true;
	}
}