HELLO, i have a problem with my code, this code is for ban player but i don't know how to ban a given player because as in the console he puts in /check ban <player name> and the reason it banns me all the time player with nickname player please help me. Thanks in advance PHP: if(isset($args[0])){ if($args[0] == "ban"){ if (!($sender instanceof Player)) return true; $sender->getServer()->dispatchCommand(new ConsoleCommandSender(), "ban $sender Cheats!"); $sender->sendMessage("§c§lWas benned for cheats!");
if(isset($args[0])){ if($args[0] == "ban"){ if (!($sender instanceof Player)) return true; if(($player = $sender->getServer()->getPlayer($args[1])) != null){ $sender->getServer()->dispatchCommand(new ConsoleCommandSender(), "ban $player Cheats!"); } } }
PHP: if(isset($args[0])){ if($args[0] == "ban"){ if($sender instanceof Player) { $player = $this->getServer()->getPlayer($args[1]); if($player->isOnline()){ $sender->getServer()->dispatchCommand(new ConsoleCommandSender(), "ban " . $player->getName() . " Cheats!"); } else { $sender->sendMessage("The player is not online!"); } } }}
i'm try it but i've got this error when i say "/check ban nickname" PHP: [11:20:25] [Server thread/CRITICAL]: Error: "Call to a member function isOnline() on null" (EXCEPTION) in "plugins/EasyKomendy/src/EasyKomendy/Main" at line 89
it work only in console but when i say /check ban nickname the server was crashed PHP: [15:26:29] [Server thread/CRITICAL]: Error: "Call to a member function isOnline() on null" (EXCEPTION) in "plugins/EasyKomendy/src/EasyKomendy/Main" at line 89