If your command is something like this `/fly Erik1206` You can get the player Instance like this `$this->getServer()->getPlayer($args[1])` Selectors aren't supported in PMMP. You can add `@a` like I did in VoteParty like this: PHP: if($args[1] == "@a"){ foreach($this->getServer()->getOnlinePlayers() as &$OnPlayer){ // Do something with player, this will repeat for all the players }}
Sorry to answer late PHP: public function execute(CommandSender $sender, string $commandLabel, array $args){ if($sender instanceof Player) { if (isset($args[0])) { if ($args[0] === "@a") { foreach (Server::getInstance()->getOnlinePlayers() as $player) { //todo } } elseif ($args[0] === "@e") { foreach (Server::getInstance()->getLevels() as $level) { foreach ($level->getEntities() as $entity) { // todo } } } elseif($args[0] === "@r"){ $player = array_rand(Server::getInstance()->getOnlinePlayers(), 1); $player->sendMessage("lol"); } else { $searchplayer = Server::getInstance()->getPlayer(strtolower($args[0])); if($searchplayer instanceof Player){ $searchplayer->sendMessage('xD'); } else { return false; } } } } }
Can't you just array_rand all the player online? I'm sorry if I sounded rude, but I was just wondering if there is any difference between your method and my method