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

How to load all level

Comments in 'Plugin Development' started by MikkiMCPE, Aug 25, 2016.

  1. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    i want load all level when my ones plugin is enabled (the plugin is about teleport player from one world to other world).

    should this code working? i never try it before, and give me some clue or helps! thanks.
    PHP:

    foreach((array) $this->getServer()->getProperty("Worlds", []) as $myworlds){
    $this->getServer()->loadLevel($myworlds);
    }

  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    No, Server::loadLevel() requires first parameter to be string, level name in this case. But the levels under "Worlds" key in pocketmine.yml is in array format.
    ImagicalGamer likes this.
  3. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    PHP:
     foreach(glob($this->getServer()->getDataPath() . "worlds/*") as $world) {
        
    $world str_replace($this->getServer()->getDataPath() . "worlds/"""$world);
        if(
    $this->getServer()->isLevelLoaded($world)){
          continue;
        }
        
    $this->getServer()->loadLevel($world);
      }
    There is most likely a better way to do this but this works too. ;)
    Last edited: Aug 27, 2016
    MikkiMCPE likes this.
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    It should be break or continue (Forgot which one) not return.
  5. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    Break and I corrected my mistake. Continue continues...
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    It has to be 'continue' because other worlds won't be loaded. 'break' jumps out of loop but 'continue' jumps to next index.
    MikkiMCPE, SOFe and ImagicalGamer like this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Thanks for saying what was in my head @Primus :)
    Primus likes this.
  8. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    :p

Share This Page

Advertisement