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

Command not working and not showing any errors

Discussion in 'Development' started by rektpixel, Jan 9, 2018.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    I have this code:
    PHP:
        public function onCommand(CommandSender $playerCommand $command$label, array $args) : bool{
            switch (
    $command->getName()) {
                case 
    "sg":
                    if(
    $player->isOp())
                    {
                        if(!empty(
    $args[0]))
                                        
                        {
                            if(
    $args[0]=="make")
                            {
                                if(!empty(
    $args[1]))
                                {
                                    if(
    file_exists($this->getServer()->getDataPath() . "/worlds/" $args[1]))
                                    {
                                        
    $this->getServer()->loadLevel($args[1]);
                                        
    $this->getServer()->getLevelByName($args[1])->loadChunk($this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorX(), $this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorZ());
                                        
    array_push($this->arenas,$args[1]);
                                        
    $this->currentLevel $args[1];
                                        
    $this->mode 1;
                                        
    $player->sendMessage("§eYou are now in §6SETUP MODE§r§e. Tap a block to set the first spawn point.");
                                        
    $player->setGamemode(1);
                                        
    $player->teleport($this->getServer()->getLevelByName($args[1])->getSafeSpawn(),0,0);
                                    }
                                    else
                                    {
                                        
    $player->sendMessage("§c[ERROR] §7Couldn't find a world with this name");
                                    }
                                }
                                else
                                {
                                    
    $player->sendMessage(TextFormat::YELLOW "/sg make <world> §7make an sg arena");
                                }
                            }
                        }
                        else
                        {
                            
    $player->sendMessage(TextFormat::YELLOW "/sg make <world> §7make an sg arena");
                            
    $player->sendMessage(TextFormat::YELLOW "/sg join <world> §7join an sg game");
                        }
                    }
                break;             
                case 
    "join":
                if(
    $player->isOp())
                {
                    if(!empty(
    $args[0]))
                    {
                        if(!empty(
    $args[1]))
                        {
                            if(
    file_exists($this->getServer()->getDataPath() . "/worlds/" $args[1]))
                            {
                                
    $this->getServer()->loadLevel($args[1]);
                                
    $this->getServer()->getLevelByName($args[1])->loadChunk($this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorX(), $this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorZ());
                                
    array_push($this->arenas,$args[1]);
                                
    $this->currentLevel $args[1];
                                
    $this->mode 1;
                              
                                
    $level $this->getServer()->getLevelByName($this->currentLevel);
                                
    $levelArena $level;
                                
    $playersArena $levelArena->getPlayers();
                                
    $gamecount count($this->getServer()->getLevelByName($this->currentLevel)->getPlayers());
                                
    $this->currentLevel $level;
                                      
                                
    $player->setFood(20);
                                
    $player->setHealth(20);
                                
    $player->setGamemode(0);
                                
    $level $this->currentLevel;
                                
    $x = -963;
                                
    $y 33;
                                
    $z 837;
                                
    $pos = new Vector3($x,$y,$z);
                                
    $player->teleport($level->getSafeSpawn($pos));
                                
    $levelArena $level;
                                
    $playersArena $levelArena->getPlayers();
                                
    $gamecount count($this->getServer()->getLevelByName($args[1])->getPlayers());
                                foreach(
    $playersArena as $pl)
                                
    $pl->sendMessage(TextFormat::YELLOW $player->getNameTag() . TextFormat::YELLOW " joined the game. (" TextFormat::AQUA $gamecount TextFormat::RESET TextFormat::AQUA "/24" TextFormat::YELLOW ")");
                            }
                        }
                    }
                    else
                    {
                        
    $player->sendMessage(TextFormat::YELLOW "/sg join <world> §7Join and sg game");
                    }
                }
            }
            return 
    true;
        }
        
    The first command works perfectly fine (/sg make) but the second command (/sg join) does not work. why is this.
    btw the second command is not finished, there are still more things I must add but as it is now it's not working and not showing any errors when the command in ran
     
  2. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    What is the error?
     
  3. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    you somehow attempted to create /make and not /sg make
    here's it fixed:
    PHP:
    <?php
    public function onCommand(CommandSender $playerCommand $command$label, array $args): bool{
       switch(
    $command->getName()){
          case 
    "sg":
             if(!empty(
    $args[0])){
                switch(
    $args[0]){
                   case 
    "make":
                      if(
    $player->isOp()){
                         if(!empty(
    $args[1])){
                            if(
    file_exists($this->getServer()->getDataPath() . "/worlds/" $args[1])){
                               
    $this->getServer()->loadLevel($args[1]);
                               
    $this->getServer()->getLevelByName($args[1])->loadChunk($this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorX(), $this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorZ());
                               
    array_push($this->arenas$args[1]);
                               
    $this->currentLevel $args[1];
                               
    $this->mode 1;
                               
    $player->sendMessage("§eYou are now in §6SETUP MODE§r§e. Tap a block to set the first spawn point.");
                               
    $player->setGamemode(1);
                               
    $player->teleport($this->getServer()->getLevelByName($args[1])->getSafeSpawn(), 00);
                            }else{
                               
    $player->sendMessage("§c[ERROR] §7Couldn't find a world with this name");
                            }
                         }else{
                            
    $player->sendMessage(TextFormat::YELLOW "/sg make <world> §7make an sg arena");
                         }
                      }
                   break;
                   case 
    "join":
                      if(
    $player->isOp()){
                         if(!empty(
    $args[0])){
                            if(!empty(
    $args[1])){
                               if(
    file_exists($this->getServer()->getDataPath() . "/worlds/" $args[1])){
                                  
    $this->getServer()->loadLevel($args[1]);
                                  
    $this->getServer()->getLevelByName($args[1])->loadChunk($this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorX(), $this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorZ());
                                  
    array_push($this->arenas,$args[1]);
                                  
    $this->currentLevel $args[1];
                                  
    $this->mode 1;
                                  
                                  
    $level $this->getServer()->getLevelByName($this->currentLevel);
                                  
    $levelArena $level;
                                  
    $playersArena $levelArena->getPlayers();
                                  
    $gamecount count($this->getServer()->getLevelByName($this->currentLevel)->getPlayers());
                                  
    $this->currentLevel $level;
                                  
                                  
    $player->setFood(20);
                                  
    $player->setHealth(20);
                                  
    $player->setGamemode(0);
                                  
    $level $this->currentLevel;
                                  
    $x = -963;
                                  
    $y 33;
                                  
    $z 837;
                                  
    $pos = new Vector3($x,$y,$z);
                                  
    $player->teleport($level->getSafeSpawn($pos));
                                  
    $levelArena $level;
                                  
    $playersArena $levelArena->getPlayers();
                                  
    $gamecount count($this->getServer()->getLevelByName($args[1])->getPlayers());
                                  foreach(
    $playersArena as $pl)
                                     
    $pl->sendMessage(TextFormat::YELLOW $player->getNameTag() . TextFormat::YELLOW " joined the game. (" TextFormat::AQUA $gamecount TextFormat::RESET TextFormat::AQUA "/24" TextFormat::YELLOW ")");
                               }
                            }
                         }else{
                            
    $player->sendMessage(TextFormat::YELLOW "/sg join <world> §7Join and sg game");
                         }
                      }
                }
             }else{
                
    $player->sendMessage(TextFormat::YELLOW "/sg make <world> §7make an sg arena");
                
    $player->sendMessage(TextFormat::YELLOW "/sg join <world> §7join an sg game");
             }
          break;
       }
       return 
    true;
    }
     
    rektpixel likes this.
  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.