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

Error with getAll function

Discussion in 'Development' started by DanielYTK, Mar 1, 2017.

  1. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Look the error
    Code:
    [15:42:19] [Server thread/CRITICAL]: Unhandled exception executing command 'status' in status: Call to a member function getAll() on null
    [15:42:19] [Server thread/CRITICAL]: Error: "Call to a member function getAll() on null" (EXCEPTION) in "/MCMMO/src/DanielYTK/MCMMO/Main" at line 59
     
    Look the function onCommand:
    PHP:
        public function onCommand(CommandSender $senderCommand $command$label, array $args) {
            switch(
    strtolower($command->getName())){
                case 
    "status":
                    
    $nick $sender->getName();
                    
    $cfga $aco->getAll(); //line 59
                    
    $cfgs $sword->getAll();
                    
    $cfgm $this->mineracao->getAll();
                        
    $sender->sendMessage("§e-------§a STATUS§e -------");
                        
    $sender->sendMessage("§aAcrobacia:");
                        
    $sender->sendMessage("  §eXP: §c".$cfga[$nick]["xp"]);
                        
    $sender->sendMessage("  §eLevel: §c".$cfga[$nick]["level"]);
                        
    $sender->sendMessage("§aSword:");
                        
    $sender->sendMessage("  §eXP: §c".$cfgs[$nick]["xp"]);
                        
    $sender->sendMessage("  §eLevel: §c".$cfgs[$nick]["level"]);
                        
    $sender->sendMessage("§aMineração:");
                        
    $sender->sendMessage("  §eXP: §c".$cfgm[$nick]["xp"]);
                        
    $sender->sendMessage("  §eLevel: §c".$cfgm[$nick]["level"]);
                    break;
            }
        }
     
    Look PlayerJoinEvent:
    PHP:
        public function aoEntrar(PlayerJoinEvent $ev){
            
    $player $ev->getPlayer();
            
    $nick $player->getName();
                
    $aco = new Config($this->getDataFolder()."players/acrobacia/".$nick.".yml"Config::YAML, array(
                
    $nick => [
                
    "xp" => 0,
                
    "level" => 0,
                ]));
                
    $aco->save();
                
    $sword = new Config($this->getDataFolder()."players/sword/".$nick.".yml"Config::YAML, array(
                
    $nick => [
                
    "xp" => 0,
                
    "level" => 0,
                ]));
                
    $sword->save();
        }
     
     
  2. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    You need to define the config in your onCommand function.
     
  3. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Undefined '$aco'
     
  4. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Add this.
    PHP:
    //To Line 58
     
    $aco = new Config($this->getDataFolder()."players/acrobacia/".$nick.".yml"Config::YAML);
     
    LilCrispy2o9 likes this.
  5. DanielYTK

    DanielYTK Zombie

    Messages:
    227
  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.