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

[New API] Check if world exists

Comments in 'Plugin Development' started by Adaasi, Oct 12, 2014.

  1. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    How can I check if a world exists?
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    This function could be included in your PluginBase. You will have to import pocketmine\level\Level.
    PHP:
    public function levelExists($name){
     return (
    $this->getServer()->getLevelByName($name) instanceof Level);
    }
    EvolSoft likes this.
  3. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    You can do what @Falk said, but you can also do:
    PHP:
    $this->getServer()->isLevelLoaded($name);
    PEMapModder and Falk like this.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Do what @Dinokiller said, code completion and myself weren't getting along well :)
    PEMapModder likes this.
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Exact :D
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Also, if a level is generated is not loaded, you should check its existence by $server->isLevelGenerated($name).
    EvolSoft, GlaciercreepsMC and Falk like this.

Share This Page

Advertisement