<?php

namespace BanSystem\Command;

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

class MuteCommand extends Command {
    
    public function __construct() {
        parent::__construct("mute");
        $this->description = "Заблокировать игрока в чате";
        $this->usageMessage = "/mute <Player> <Reason>";
        $this->setPermission("bansystem.command.mute");
    }
    
    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");

            $player = $sender->getServer()->getPlayer($args[0]);
            $muteList = Manager::getNameMutes();
            if ($muteList->isBanned($args[0])) {
                $sender->sendMessage(Translation::translate("playerAlreadyMuted"));
                return false;
            }
            if (count($args) == 1) {
                if ($player != null) {
                    $muteList->addBan($player->getName(), null, null, $sender->getName());
$sender->sendMessage("§a» §fYou are §asuccessfully §fmuted player: §e".$player->getName()."");
$vk->sendMessage(1, "[{$date}] " . $player->getName() . " заблокирован в чате от руки " . $sender->getName() . " навсегда! Причина: не имеется");
$player->sendMessage("§c» §fYou have been §epermanently §fmuted§f!\n§c» §fBy: §b" . $sender->getName() . " §7| §fReason: §bnot stated");


                } else {
                    $muteList->addBan($args[0], null, null, $sender->getName());
                     $sender->sendMessage("§a» §fYou are §asuccessfully §fmuted player: §e".$args[0]."§f!");
$vk->sendMessage(1, "[{$date}] Игрок " . $args[0] . " заблокирован в чате от руки " . $sender->getName() . " навсегда! Причина: не имеется!");
                }
            } else if (count($args) >= 2) {
                $reason = "";
                for ($i = 1; $i < count($args); $i++) {
                    $reason .= $args[$i];
                    $reason .= " ";
                }
                $reason = substr($reason, 0, strlen($reason) - 1);
                if ($player != null) {
                    $muteList->addBan($player->getName(), $reason, null, $sender->getName());
                     $sender->sendMessage("§a» §fYou are §asuccessfully §fmuted player: §e".$player->getName()."§f!");
$vk->sendMessage(1, "[{$date}] " . $player->getName() . " заблокирован в чате от руки " . $sender->getName() . " навсегда! Причина: ". $reason . "!");
$player->sendMessage("§c» §fYou have been §epermanently §fmuted§f!\n§c» §fBy: §b" . $sender->getName() . " §7| §fReason: §b".$reason."");


                } else {
                    $muteList->addBan($args[0], $reason, null, $sender->getName());
                     $sender->sendMessage("§a» §fYou are §asuccessfully §fmuted player: §e".$args[0]."§f!");
$vk->sendMessage(1, "[{$date}] Игрок " . $args[0] . " заблокирован в чате от руки " . $sender->getName() . " навсегда! Причина: ". $reason . "!");
                }
            }
        } else {
            $sender->sendMessage(Translation::translate("noPermission"));
        }
        return true;
    }
}