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

Get Player in Level in certain Gamemode

Comments in 'Plugin Development' started by MineBuilderFR, Dec 16, 2015.

  1. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
    Hi!
    I need code For get all player in level in survival gamemode.

    Exemple:
    =-=
    $plw= $this->getServer()->getLevelByName($level)->getPlayers()->isSurvival(); //For exemple survival
    =-=

    I have test with config (set player in config and check if is on survival) and it work but exist more simple code?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $level $this->getServer()->getLevelByName("name");
    foreach(
    $level->getPlayers as $pl){
      if(
    $pl->getGamemode === 0){
        
    //Do something
      
    }
    }
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $survivalPlayers array_filter(function(Player $player){
      return 
    $player->isSurvival();
    }, 
    $level->getPlayers());
    Note that it is not advisable to get a level object every time by searching it by name. It is better to cache the level ID and get the level object directly using $server->getLevel().
    PocketKiller and CraftYourBukkit like this.
  4. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    The most easy thinks become difficult when you write it... lol
    Last edited: Dec 19, 2015
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder

Share This Page

Advertisement