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

Unhandled exeception

Discussion in 'Facepalm' started by romainbizet46, Oct 15, 2017.

  1. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Why m'y code doesnt plz can you fix that
    Thx .
    PHP:
    public function onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool {
                if(
    $sender instanceof Player) {
                    if(
    strtolower($command->getName()) == 'atp') {
                        if(
    count($args) == || count($args) == 2) {
                            
    $action strtolower($args[0]);
                            if(
    $action == 'kill' || $action == 'death' || $action == 'break' || $action == 'place') {
                                
    $data = [
                                    
    'type' => $action,
                                    
    'x' => round($sender->getX()),
                                    
    'y' => round($sender->getY()),
                                    
    'z' => round($sender->getZ()),
                                    
    'level' => strtolower($sender->getLevel()->getName())
                                ];
                                
    $this->save($data);
                                
    $this->create($action);
                                return 
    true;
                            }
                            
    $user $this->users->query("SELECT * FROM `users` WHERE `nickname` = '$action'")->fetchArray(SQLITE3_ASSOC);
                            if(
    $user !== false)
                                
    $sender->sendMessage(str_replace('{player}'$action$this->config['titleStat'])."\n§aMatar: §d".$user['kill']."\n§aMuerto: §d".$user['death']."\n§aRoto: §d".$user['break']."\n§aLiberar: §d".$user['place']);
                            else 
    $sender->sendMessage($this->config['userNotExist']);
                        }
                        else 
    $sender->sendMessage('§eUse: /atp <kill/death/break/place> [player]');
                    }
                }
            }
    PHP:
    [10:20:10] [Server thread/CRITICAL]: Unhandled exception executing command 'atp' in atp: Return value of AlexBrin\aTopPlayers::onCommand() must be of the type booleannone returned                                   [10:20:10] [Server thread/CRITICAL]: TypeError"Return value of AlexBrin\aTopPlayers::onCommand() must be of the type boolean, none returned" (EXCEPTIONin "aTopPlayers_v1/src/AlexBrin/aTopPlayers" at line 66    
     
    Last edited: Oct 15, 2017
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
  3. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Sorry i send thé wrong code

    PHP:
    public function onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool {
                if(
    $sender instanceof Player) {
                    if(
    strtolower($command->getName()) == 'atp') {
                        if(
    count($args) == || count($args) == 2) {
                            
    $action strtolower($args[0]);
                            if(
    $action == 'kill' || $action == 'death' || $action == 'break' || $action == 'place') {
                                
    $data = [
                                    
    'type' => $action,
                                    
    'x' => round($sender->getX()),
                                    
    'y' => round($sender->getY()),
                                    
    'z' => round($sender->getZ()),
                                    
    'level' => strtolower($sender->getLevel()->getName())
                                ];
                                
    $this->save($data);
                                
    $this->create($action);
                                return 
    true;
                            }
                            
    $user $this->users->query("SELECT * FROM `users` WHERE `nickname` = '$action'")->fetchArray(SQLITE3_ASSOC);
                            if(
    $user !== false)
                                
    $sender->sendMessage(str_replace('{player}'$action$this->config['titleStat'])."\n§aMatar: §d".$user['kill']."\n§aMuerto: §d".$user['death']."\n§aRoto: §d".$user['break']."\n§aLiberar: §d".$user['place']);
                            else 
    $sender->sendMessage($this->config['userNotExist']);
                        }
                        else 
    $sender->sendMessage('§eUse: /atp <kill/death/break/place> [player]');
                    }
                }
            }
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    then there should be no error in the code
     
    romainbizet46 likes this.
  5. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    No i have thé error at the fist post

    I get this error when i do /ATP
    Not when i starting m'y server
     
  6. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    You need to return true in every scenario.
     
  7. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    No, you need to return a boolean: either true to suppress the default usage message for the command, or false to display it.
     
  8. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Sorry i m noob can you fix syntaxe error
    Unexepted else:

    PHP:
    public function onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool {
                if(
    $sender instanceof Player) {
                    if(
    strtolower($command->getName()) == 'atp') {
                        if(
    count($args) == || count($args) == 2) {
                            
    $action strtolower($args[0]);
                            return 
    true;
                            if(
    $action == 'kill' || $action == 'death' || $action == 'break' || $action == 'place') {
                                
    $data = [
                                    
    'type' => $action,
                                    
    'x' => round($sender->getX()),
                                    
    'y' => round($sender->getY()),
                                    
    'z' => round($sender->getZ()),
                                    
    'level' => strtolower($sender->getLevel()->getName())
                                ];
                                
    $this->save($data);
                                
    $this->create($action);
                                return 
    true;
                                
    $user $this->users->query("SELECT * FROM `users` WHERE `nickname` = '$action'")->fetchArray(SQLITE3_ASSOC);
                                if(
    $user !== false)
                                    
    $sender->sendMessage(str_replace('{player}'$action$this->config['titleStat'])."\n§aMatar: §d".$user['kill']."\n§aMuerto: §d".$user['death']."\n§aRoto: §d".$user['break']."\n§aLiberar: §d".$user['place']);
                                    return 
    true;
                                    } else {
                                        
    $sender->sendMessage($this->config['userNotExist']);
                                        return 
    true;
                                        } else {
                                            
    $sender->sendMessage('§eUse: /atp <kill/death/break/place> [player]');
                                            return 
    true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
     
  9. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    https://phpcodechecker.com
     
  10. romainbizet46

    romainbizet46 Witch

    Messages:
    52
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Perhaps you should try to tell people what you think you are doing when you don't know why you wrote the wrong code?
     
  12. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Yes
     
  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.