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

Error: Call to a member function getSpawnLocation() on null

Comments in 'Plugin Development' started by Survingo, Apr 24, 2016.

  1. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Hello all,
    I try to make a Nether plugin.
    But I get an Error while using getSpawnLocation() or getSafeSpawn()
    PHP:
    $nether "Nether";
                
    $location $this->plugin->getServer()->getLevelByName($nether)->getSpawnLocation();
                
    $pos = new Position($location->getX(), $location->getY(), $location->getZ(), $this->plugin->getServer()->getLevelByName($nether));
                
    $block $player->getLevel()->getBlock(new Vector3($player->x$player->0.5$player->z));
                if(
    $block->getId(49)){
    if(
    $this->getServer()->loadLevel($nether) != false){
                      
    $player->teleport($pos);
    While in this PluginTask, $player is getOnlinePlayers() foreached.
    Code:
    Error: Call to a member function getSpawnLocation() on null
    Maybe because that function is for default 'null' but I don't know how to edit that
    I searched a lot but doesn't helped at all
    Last edited: Apr 24, 2016
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Means, getLevelByName() or a previous method, had already returned null.
    Check if that level exists and is loaded.
  3. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Already did.
    PHP:
    if($this->getServer()->loadLevel($nether) != false){
                      
    $player->teleport($pos);
                      
    $player->sendMessage("§cTeleporting to the Nether...");
                      }else{
                      
    $this->NetherGenerator->generateNetherWorld();
    Else it generates a nether world if the level doesn't exists
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why != false? Also, you're loading the lwvel after getting its safespawn

Share This Page

Advertisement