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

how to get getLevel() from PlayerMoveEvent

Comments in 'Plugin Development' started by Valeron, Nov 27, 2015.

  1. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    how to get getLevel() (levelname) from PlayerMoveEvent
  2. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    $event->getPlayer()->getLevel()
    Does not works
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    OMG READ THE DOCS. $player->getLevel() returns a LEVEL OBJECT. Then in the Level class it says getName().
    So: $player->getLevel()->getName();. Using var_dump() can also simply show you the problem. var_dump($event->getPlayer()->getLevel()); will return a Level object -_- *sweaty-facepalm*
  4. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    This method doesn't require a parameter, as it already returns a Level instance(of the player that joined). But if you want to get another Level instance, you would need to use Server->getLevelByName(), which will return a Level instance on success and null on failure.
    You should actually explain to him how it works, he doesn't understand right now.
    Legoboy0215 likes this.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    From $event->getPlayer()->getLevel() you'll get Level object that player is currently in.

    In docs its said that Level object contains method called getName(). So you can use it like this.
    PHP:
    $levelName $event->getPlayer()->getLevel()->getName();

    var_dump($levelName);
    Code:
    string(5) => 'world'
    
    To see what else you can get out of Level object see here: http://jenkins.pocketmine.net/job/P...3/d4b/classpocketmine_1_1level_1_1_level.html
    although it's from API 1.12.0 but it's almost/completly the same with API 1.13.0
    Khaled098 and LDX like this.

Share This Page

Advertisement