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 the level object knowing only the name of the world?

Comments in 'Plugin Development' started by Svile, Jun 25, 2015.

  1. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    Hi , i' m new on the forum and that is my first thread :) if something is not written correctly is because i' m not english ;)

    I need an help with that :
    PHP:
    public function isGameFull($levelName){                    
               if(
    $this->config->get("MaxPlayersPerGame") == count($this->getServer()->getLevelByName($levelName)->getPlayers())){
                   return 
    true;     
               }else{
                   return 
    false;
               }        
        }
    when that function is called the server crash, reason: call to a member function getPlayers() on NULL
    why ? I would appreciate if someone reply ,thanks to all
  2. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You can also just use
    PHP:
    return $maxPlayers === $otherMax;
    // You have to replace/define them
    instead of if/else.
    Svile and PEMapModder like this.
  4. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    you' re right but the error is the same...
    PHP:
           public function isGameFull($levelName){                   
               return 
    $this->config->get("MaxPlayersPerGame") === count($this->getServer()->getLevelByName($levelName)->getPlayers());  
        }
    ...Call to a member function getPlayers() on null
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wt, do you know what you're saying?

    @Svile check $levelName's value.
    Svile and iksaku like this.
  6. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    I tried to enter the level name string :
    PHP:
    public function isGameFull($levelName){                  
               return 
    $this->config->get("MaxPlayersPerGame") === count($this->getServer()->getLevelByName("lobby")->getPlayers()); 
        }
    nothing change ... the level folder is in her place and is called "lobby"... i really don' t know why this error appears :(
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1. Make sure $levelName is "lobby".
    2. Make sure the world is loaded.
    3. Make sure the world name not just the world folder name is lobby.
  8. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    solved by loading the level in memory ... Thanks :)
    Falk likes this.

Share This Page

Advertisement