<?php

namespace BanSystem\Command;

use BanSystem\Translation\Translation;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;

class UnbanCommand extends Command {
    
    public function __construct() {
        parent::__construct("unban");
        $this->description = "Разбанить игрока по нику";
        $this->usageMessage = "/unban <Player>";
        $this->setPermission("bansystem.command.unban");
    }
    
    public function execute(CommandSender $sender, $commandLabel, array $args) {
    $date = date("d.m.y");
        if ($this->testPermissionSilent($sender)) {
            if (count($args) <= 0) {
                $sender->sendMessage(Translation::translateParams("usage", array($this)));
                return false;
            }
$vk = $sender->getServer()->getPluginManager()->getPlugin("VK");
            $banList = $sender->getServer()->getNameBans();
            if (!$banList->isBanned($args[0])) {
                $sender->sendMessage(Translation::translate("playerNotBanned"));
                return false;
            }
            $banList->remove($args[0]);
             $sender->sendMessage("§a» §fYou are §asuccessfully §funbanned player's nickname: §e".$args[0]."§f!");
$vk->sendMessage(1, "[{$date}] Игрок " . $args[0] . " был разбанен по нику от руки ".$sender->getName()."");
        } else {
            $sender->sendMessage(Translation::translate("noPermission"));
        }
        return true;
    }
}