I have tried this : PHP: $player = $this->getServer()->getPlayer($args[0]);if($player instanceof Player) {//blahh} However, it gives me error : unknow error when platform the command... Anyone help?
Your title and post tell different things. We need more code than this, and the error that showed up in console when executing this command, if you want us to help you.
PHP: public function onCommand(CommandSender $sender, Command $command, $label, array $args) { if($sender instanceof Player) { if(strtolower($command->getName() === "hi")) { if($sender->hasPermission("agagawgg.rstsh")) { switch ($args[0]) { case "player": if(count($args) === 2){ $name = strtolower($args[1]); $this->target = $name; $target = $this->getServer()->getPlayer($args[1]); //if(target instanceof Player) ? if(!$target->hasPermission("agagawgg.rstsh")) { $sender->sendMessage(C::LIGHT_PURPLE . "You targeted" . C::AQUA . $this->target); $target->sendMessage(C::RED . "You are targeted!"); } } break; and the error is the same as I said Code: [23:14:11] [Server thread/INFO]: An unknown error occurred while attempting to perform this command [23:14:11] [Server thread/CRITICAL]: Unhandled exception executing command 'mute player akwfaw4' in mute: Call to a member function getPlayer() on array [23:14:11] [Server thread/CRITICAL]: Error: "Call to a member function getPlayer() on array" (EXCEPTION) in "/Mute/src/Mute/mute" at line 135
PHP: public function onCommand(CommandSender $sender, Command $command, $label, array $args) { if($sender instanceof Player) { if(strtolower($command->getName() === "hi")) { if($sender->hasPermission("agagawgg.rstsh")) { switch ($args[0]) { case "player": if(count($args) === 2){ $name = strtolower($args[1]); $this->target = $name; $target = $sender->getServer()->getPlayer($args[1]); // If $this->getServer() is being overwritten use $sender->getServer() if($target instanceof Player and !$target->hasPermission("agagawgg.rstsh")) { $sender->sendMessage(C::LIGHT_PURPLE . "You targeted" . C::AQUA . $this->target); $target->sendMessage(C::RED . "You are targeted!"); } } break;