1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Which method i do use: a player in a specific world

Discussion in 'Development' started by romainbizet46, Oct 20, 2017.

  1. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    PHP:
    if($player->getLevel()->getName() === "worldName") {/*i do change lvdat with this that*/

    /*Or*/

    if($player->getLevel()->getLevelByName() === "worldName") {
     
    Last edited: Oct 20, 2017
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Neither because both will give you errors :facepalm:
    PHP:
    if($player->getLevel()->getName() === "worldName") {
        
    //do stuff
    }
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Better use Level->getFolderName().
     
    romainbizet46 likes this.
  4. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Why that's better?
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Level->getName() returns the name in level.dat.
    Level->getFolderName() returns the name of the folder containing the level.

    Two loaded levels can have the same Level->getName(), but they can't have the same Level->getFolderName(). So Level->getFolderName() is the unique identifier, while Level->getName() is just the display name.
    If you use /status, if the folder name is different from the level.dat name, it will display format:
    Code:
    World "folder name" (level.dat name):
    
    When you use Server->getLevelByName($name), the function actually compares the $name against the folder name of each loaded level. So, there is no good reason to use Level->getName() except for displaying to the user.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.