<?php

namespace BlockCommand;

use pocketmine\event\Listener;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\event\player\PlayerCommandPreprocessEvent;

  class Main extends PluginBase implements Listener{

protected
$players = [],
$blocked = [];

public function onEnable()
{
@mkdir($this->getDataFolder());
$this->saveDefaultConfig();
$this->blocked = explode(",", $this->getConfig()->get("commands"));
$this->players = explode(",", $this->getConfig()->get("players"));
$this->getServer()->getPluginManager()->registerEvents($this, $this);
/* $this->getLogger()->info("############################"); $this->getLogger()->info("#    [Создатель плагина]   #"); $this->getLogger()->info("#       __   __            #");
$this->getLogger()->info("#\  /  |  | |  |   __|   \/#"); $this->getLogger()->info("# \/   |__| |__|  |__|   / #"); $this->getLogger()->info("############################"); */
}

public function Command($cmd){
  if(isset($this->blocked)){
 $cmd = strtolower($cmd);
  foreach($this->blocked as $bcmd){
 $bcmd = strtolower($bcmd);
  if($cmd === $bcmd){
  return true;
  }
  }
  }
return false;
}

public function Player(Player $p){
  if(isset($this->players)){
 $p = $p->getName();
 $p = strtolower($p);
  foreach($this->players as $wlp){
 $wlp = strtolower($wlp);
  if($p === $wlp){
  return true;
  }
  }
  }
return false;
}

public function onPlayerCommand(PlayerCommandPreprocessEvent $ev){$msg = $ev->getMessage();
$ccmd = explode(" ", $msg);
$cmd = strtolower(substr(array_shift($ccmd), 1));
if($msg[0] !== "/"){
return;
}
if($this->Command($cmd)){
if($this->Player($ev->getPlayer())){
$this->getLogger()->info("§f".$ev->getPlayer()->getName()." §f: §e/".$cmd."§f!");
}else{
$this->getLogger()->info("§f".$ev->getPlayer()->getName()." §fпытался использовать: §e/".$cmd."§f!");
$cmded = "/".$cmd."";
$message = $this->getConfig()->get("msg");
    $message = str_replace("{cmd}",$cmded, $message);
$ev->getPlayer()->sendMessage("{$message}");
$ev->setCancelled(true);
}
}
}
}