Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Did $event->getLevel() exist ?

Comments in 'Plugin Development' started by PlayCubePE, Mar 22, 2015.

  1. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    I'll reformulate it here !

    So, i want a snippets of code please :

    so here's my code :

    PHP:
         public function PlayerQuit(PlayerQuitEvent$event) {
         
    $this->playerCount $this->playerCount 1;
         
    $this->getServer()->broadcastMessage("[Game name] ".$event->getPlayer()->getName()." left the game.");
         }
    But me i want than the servers execute it only in the world Hunger Games for a exmple.

    Thanks you for helping me ! (If you do)
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $event->getPlayer()->getLevel()

    Also, you don't need to count the players yourself. To count players in a Level $level, use count($level->getPlayers()). To count players in the whole server, use count($server->getOnlinePlayers()).
  3. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    You don't understand what i want to do !
    What i want is :
    That's not some real code don't cry ;-)

    If getlevel = examplemap
    execute this code

    PHP:
    public function PlayerQuit(PlayerQuitEvent$event) {
         
    $this->playerCount $this->playerCount 1;
         
    $this->getServer()->broadcastMessage("[Game name] ".$event->getPlayer()->getName()." left the game.");
         }
    but i want to get the level of the player who quit
  4. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Just Do:

    public function PlayerQuit(PlayerQuitEvent $ev) {
    if ($ev->getPlayer()->getLevel()->getName() = "WorldName"){
    $this->playerCount = $this->playerCount - 1;
    $this->getServer()->broadcastMessage("[Game name] ".$event->getPlayer()->getName()." left the game.");
    }
    }
    also can someone tell me how to do the code area thing :)
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Try this code:
    PHP:
    foreach($event->getPlayer()->getLevel()->getPlayers() as $lvl_players){
       
    $lvl_players->sendMessage("[Game Name] " $event->getPlayer()->getName() . "left the game.");
    }
    Please like if I helped you :)
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please make sure, do you want to know when the player quits the server when he is in that level, or simply teleport over worlds?
    EvolSoft and iksaku like this.
  7. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Yes, don't forget to put the code in PlayerDeathEvent

Share This Page

Advertisement