code PHP: foreach($this->getServer()->getOnlinePlayers() as $players){ $playersName = $players->getName(); $sender->sendMessage("There are " . count($this->getServer()->getOnlinePlayers()) . "/".$this->getServer()->getMaxPlayers(). " players online.\n" . implode(", ", $playersName)); } error Code: [19:08:33] [Server thread/CRITICAL]: Unhandled exception executing command 'list' in list: implode(): Invalid arguments passed [19:08:33] [Server thread/CRITICAL]: ErrorException: "implode(): Invalid arguments passed" (EXCEPTION) in "plugins/test/src/test/Main" at line 109
First thing, remove the sendMessage function from the foreach loop, as that would've sent the player tons of messages(if there wasn't an error with implode) Second, you used the implode function wrong. The implode functions calls for an array, and you kept setting a string and then provided a string as an input. PHP: $playersNames = "";foreach($this->getServer()->getOnlinePlayers() as $player) { $playersNames .= $player->getName() . ", "; //This attaches the $player->getName() and comma to the end of the $playersNames string.} $sender->sendMessage("There are " . count($this->getServer()->getOnlinePlayers()) . "/". $this->getServer()->getMaxPlayers() . " players online.\n" . $playersNames); If you're really keen on using the implode function: PHP: $playersNames = [];foreach($this->getServer()->getOnlinePlayers() as $player) { $playersNames[] = $player->getName(); //Adds the player's name to an array} $sender->sendMessage("There are " . count($this->getServer()->getOnlinePlayers()) . "/". $this->getServer()->getMaxPlayers() . " players online.\n" . implode(", ", $playersNames));