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

How to fix this error?

Comments in 'Plugin Development' started by korado531m7, Mar 26, 2016.

  1. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    I made a plugin.
    But, crashed. i try to fix this, but it's not my plugin error.
    How to fix this?
    Thank you for answering.

    (I used code)
    loadLevel , unloadLevel

    Error
    Error: Call to a member function getName() on null
    File: /src/pocketmine/level/Level
    Line: 2896
    Type: E_ERROR
    Last edited: Mar 26, 2016
  2. CookieSteve
    Offline

    CookieSteve Active Member

    Joined:
    Apr 22, 2014
    Posts:
    132
    Minecraft User:
    iStrqfeChris
    theres no code but im guessing the level is'nt loaded
    applqpak likes this.
  3. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    How to load all?
  4. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Please show the line in the code where the error is happening.
    Vaivez66 likes this.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You're trying to call getName() on a Level that either does not exist or isn't loaded. To load it, use
    PHP:
    $this->getServer()->loadLevel($name);
    applqpak likes this.
  6. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    i'm using a restoring function.
    to unload, using
    PHP:
    $this->getServer()->getLevelByName("world")->setAutoSave(false);
    $this->getServer()->unloadLevel($this->getServer()->getLevelByName("world"));
    to load,
    PHP:
     $this->getServer()->loadLevel("world");
  7. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Hmm, i created a function
    PHP:
    public function loadWorld(){
    $this->getServer()->loadLevel("FireBuilds-1vs1Arenas");
    }
    and run this. solved this problem. but i don't know why happened and fixed...
  8. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    PHP:
    Foreach($server->getLevels() as $k):
    $server->loadLevel($k->getName());
    endforeach;
    korado531m7 and applqpak like this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $server->getLevels() will only return loaded levels... $k is a Level instance. A Level instance won't exist unless the level is already loaded (or loaded and then unloaded). If you want to find all worlds in the worlds directory, use scandir().

Share This Page

Advertisement