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

Why not try getLevelByName() calls loadLevel()?

Discussion in 'General discussion' started by yuko fuyutsuki, Apr 20, 2018.

  1. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    If this is implemented, think that it is not necessary for the plugin to determine whether or not the level is loaded one by one.
    That is, at the time the world's folder exists, it will be determined that the level class is acquired, or null is returned (internal loadLevel() error).
    Therefore, I think that the following implementation is good, but how is it?

    Summary: When getting a Level class with getLevel() etc, how about trying loadLevel() internally?

    PHP:
    // On Server Class
    // I omit some parameters so this is example...

    /**
     * @return Level[]
     */
    public function getLevels(): array {
      
    // No code changes, but returns are all getable Levels.
    }

    /**
     * @return Level|null
     */
    public function getDefaultLevel(): ?Level {
      
    // In first, trying to load Level
      // If you get an error with loadLevel(), throw an exception or close the server.
      
    $loaded $this->loadLevel();
      
    // Determine $loaded
      
    if ($loaded) {
        return 
    $this->getLevel();// returns default level
      
    }else {
        return 
    null;
      }
    }
     
    Last edited: Apr 20, 2018
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    RCF?
    i think of also adding a $tryload if someone for whatever reasons dont want to load it
     
    yuko fuyutsuki likes this.
  3. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    I understand that "RCF" is an abbreviation for something, but Idk its meaning...
     
  4. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    A misspelling of "RFC".
     
    HimbeersaftLP and yuko fuyutsuki like this.
  5. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    I thought that but suspected the possibility of other abbreviations. :confused:
    Is this thread correct for posting in the RFC category?
     
  6. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    If you mean if it's ok to post it there, then since the category is called "PocketMine-MP Contributing & RFCs" I think it would be okay to post it there, because the category's subject is broad enough. As for the thread's itself correctness, I don't think there are any strict rules for that.
     
    yuko fuyutsuki likes this.
  7. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    I don't like this. The "Level->getChunk()" clusterfuck is enough implicit loading messes for me. It might seem convenient but it's a great way to cause unexpected behaviour.

    If you want to load something, whether it's a level, chunk, dimension or whatever, you should be explicit about it, especially in the case where whatever you're loading could be happening asynchronously.
     
    Tee7even and yuko fuyutsuki like this.
  8. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    Ok, I understood.
    Now, is there a way to check whether a level exists without loading unnecessary levels, or is there a corresponding function?
    I want to do that.
     
  9. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    if(is_dir(*world path*)){
     
  10. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    Ok, thx
     
  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.