For $event->setQuiMessage(); it work And count() not work why ? Not Executed i not have message error of my log. PHP: public function PlayerQuit(PlayerQuitEvent $event){ $player = $event->getPlayer(); $lvl = $player->getLevel()->getName(); if($lvl === "test"){ if(isset($this->players[$player->getName()])){ unset($this->players[$player->getName()]); $event->setQuitMessage("[GAME] ".$player->getName()." Disconnected !"); $this->refreshSign(); if(count($this->players)< 1){ foreach($this->players as $p){ $p->sendMessage("you are won !"); $p->teleport($this->getServer()->getLevelByName("world")->getSafeSpawn()); $p->setNameTag($p->getName()); $p->getInventory()->clearAll(); $this->min = 4; } }
First, the player isnt fully unregistered on quit event, means that the level count is outdated, and how can you send to 0 players a messsge, do < 3 not < 1 (I use < 3 in my plugin too)
Because you are checking if there are zero players. Just change 'if(count ($players) < 1)' to 'if(count ( $players ) <= 1)'
Indefined : $players ...... What is the différent with if(count($this->players) < 1){ or if(count($this->players) > 1){ ?
To debug which point of the code is run and which point is not run, try adding lines of echo at different places in your code.
The difference is called "common sense". Or "eye test". Or "do-you-live-in-20th-to-21st-century test".
OMG ! Lol example if(count($this->player) > 1){ = 1 And if(count($this->players) < 1){ = 0 ... Okay .... I have other problem with code the problem is as a player quit and other players teleport in the Spawn with Message executed "You are won" all players help....
PHP: public function PlayerQuit(PlayerQuitEvent $event){ $player = $event->getPlayer(); $lvl = $player->getLevel()->getName(); if($lvl === "test"){ if(isset($this->players[$player->getName()])){ unset($this->players[$player->getName()]); $event->setQuitMessage("[GAME] ".$player->getName()." Disconnected !"); $this->refreshSign(); if(count($this->players) == 1){ foreach($this->players as $pl){$p = $this->getServer()->getPlayer($pl); $p->sendMessage("you are won !"); $p->teleport($this->getServer()->getLevelByName("world")->getSafeSpawn()); $p->setNameTag($p->getName()); $p->getInventory()->clearAll(); $this->min = 4; } }
Use == 2 as I said the player isnt fully unregistered on PlayerQuitEvent, so the player count is not correctly
He Say PHP: foreach($this->players as $p){$p->sendMessage("..");etc.. I Just Fix IT PHP: foreach($this->players as $pl){$p = $this->getServer()->getPlayer($pl);$p->sendMessage("you are won !");etc..
Guess why. Because we do not know what your array looks like. It's not our fault if we expect the array to be another one than you really have.