I need to send a message to a different player than sent the command. Lets see the command is /w <player> . How can I send a message to the <player> that was specified?
This is really easy... Just check that the first argument isn't null then run Server::getPlayer on it, which returns a Player object(if it doesnt fail).
Code for what @applqpak said PHP: $player = $this->getServer()->getPlayer($args);if($player->isConnected()){$player->sendMessage("Hello!");}else{$sender->sendMessage("Player isn't online!");// "$sender" is the command sender}
As far as I know Server::getPlayer() returns null if no player was found, which also means $player->isConnected() won't work in that case. That's how I would solve it: PHP: if($player instanceof Player){} or PHP: if($player !== null){} Besides that +1