<?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 Setar 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 '.$this->config->get('Cor_Eventos_Arena').'/boxing setar <lobby|pos1|pos2> §fpara setar uma posição.');
			 return false;
		}
		if (empty($this->command->data[$sender->getName()]))
		     $this->command->data[$sender->getName()] = [];
		
		if (!in_array($args[1], ['lobby', 'pos1', 'pos2'])) {
			  $sender->sendMessage('§fUse '.$this->config->get('Cor_Eventos_Arena').'/boxing setar <lobby|pos1|pos2> §fpara setar uma posição.');
			 return false;
		}
		$this->command->data[$sender->getName()][$args[1]] = [$sender->x+0.5, $sender->y, $sender->z+0.5, $sender->level->getFolderName()];
		$sender->sendMessage('§fA Posição '.$this->config->get('Cor_Eventos_Arena').''.$args[1].' §fFoi Setada.');
		return true;
	}
}