<?php

namespace BanSystem\Command;

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

class KickCommand extends Command {
    
    public function __construct() {
        parent::__construct("kick");
        $this->description = "Кикнуть игрока с сервера";
        $this->usageMessage = "/kick <Player> <Reason>";
        $this->setPermission("bansystem.command.kick");
    }
    
    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;
            }
            $player = $sender->getServer()->getPlayer($args[0]);
$vk = $sender->getServer()->getPluginManager()->getPlugin("VK");

            if (count($args) == 1) {
                if ($player != null) {
                    $player->kick("§fYou §ewere§f kicked\n\n§fBy: §b" . $sender->getName() . "\n§fReason: §bnot stated", false);
                     $sender->sendMessage("§a» §fYou are §asuccessfully §fkicked player: §e".$player->getName()."§f!");
$vk->sendMessage(1, "[{$date}] Игрок " . $player->getName() . " был кикнут от руки " . $sender->getName() . "! Причина: не имеется");

                } else {
                    $sender->sendMessage(Translation::translate("playerNotFound"));
                }
             } else if (count($args) >= 2) {
                if ($player != null) {
                     $reason = "";
                    for ($i = 1; $i < count($args); $i++) {
                        $reason .= $args[$i];
                        $reason .= " ";
                    }
                    $reason = substr($reason, 0, strlen($reason) - 1);
                    $player->kick("§fYou §ewere§f kicked\n\nBy: §b" . $sender->getName() . "\n§fReason: §b" . $reason . "", false);
                     $sender->sendMessage("§a» §fYou are §asuccessfully §fkicked player: §e".$player->getName()."§f!");
$vk->sendMessage(1, "[{$date}] Игрок " . $player->getName() . " был кикнут " . $sender->getName() . "! Причина: ". $reason . "!");

                } else {
                    $sender->sendMessage(Translation::translate("playerNotFound"));
                }
            }
        } else {
            $sender->sendMessage(Translation::translate("noPermission"));
        }
        return true;
    }
}