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

Error getTile()

Discussion in 'Development' started by Harviy11, Dec 27, 2016.

  1. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Help console giving error
    PHP:
    public function refreshSigns()
    {
        
    $pl count($this->getServer()->getLevelByName("Hub")->getPlayers());
        
    $lobby $this->getServer()->getLevelByName("GDshop");
        
    $t $lobby->getTile(new Vector3(1254485));
        
    $text $t->getText();
        if (
    $t instanceof Sign) {
            if (
    $text[0] == $this->prefix) {
                
    $t->setText($this->prefix"§7" $pl "/14 §9]"$text[2], $text[3]);
            }
        }
    }
    ERROR

    Code:
    [11:39:29] [Server thread/CRITICAL]: Could not execute task GetDown\SignRefresher: Call to a member function getTile() on null
    [11:39:29] [Server thread/CRITICAL]: Error: "Call to a member function getTile() on null" (EXCEPTION) in "myzip:///GetDown.zip#GetDown/src/GetDown/Main" at line 484
    
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    It looks like the level with the name "GDshop" does not exist.
     
  3. Aviv

    Aviv Baby Zombie

    Messages:
    156
    Is the level loaded? it must be loaded so it will be an instance of Level and not null
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    Get the level on plugin enabling then if it's not loaded, throw an error or disable the plugin.
    PHP:
    if(!$level) {
       throw new \
    Exception("necessary level 'GDshop' was not loaded");
    }
    That's what Plugin::onEnable() is meant for, prepare your plugin!
     
  5. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Level is correctly loaded :p
     
  6. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Put this on onEnable() pls
    PHP:
    /**
    * Enable the plugin
    */
    public function onEnable() {
        if(!
    $this->getServer()->isLevelLoaded("GDshop")) {
            
    $this->getServer()->loadLevel("GDshop");
        }
    }
    and code should work
     
    Primus likes this.
  7. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    You should explain what this code does.
    No, obviously not.
     
  8. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    It loads the fucking level don't you see the function name
     
  9. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Of course I do. But you should still explain your code rather than just sending a random piece of code to someone who might not understand what it does and copy pastes it. Also your code is not ideal, and the isLevelLoaded check is not needed.
    PHP:
    /* I am assuming you are in a class that extends PluginBase */
    public function onEnable(){ //This function will be called by the server when your plugin is enabled.
        
    $levelName "GDshop"//The name of the level you want to use
        
    if($this->getServer()->loadLevel($levelName) === false){ //loadLevel returns false if level could not be loaded, and it ignore the request if the level is already loaded.
            
    $this->getLogger()->critical("I can't find my required level ".$levelName.". I will now disable myself"); //Output warning message using the pluginLogger
            
    $this->getServer()->getPluginManager()->disablePlugin($this); //Safely disables and unloads the plugin
        
    }
    }
    This disables the plugin if the level could not be found.
     
    Muqsit likes this.
  10. imYannic

    imYannic Baby Zombie

    Messages:
    113
    ..... var_dump($lobby);
    var_dump(get_class($lobby));
     
  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.