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

Schedular error: Call to a member function cancel() on null

Comments in 'Plugin Development' started by BalAnce, Jul 26, 2015.

  1. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    i trie to cancel task with
    Code:
    $this->getServer()->getScheduler()->cancelTask($taskId);
    on main.php but i get this

    Code:
    Fatal error: Call to a member function cancel() on null in /Users/newuser/Desktop/Pocketmine/plugins/DuelMe/src/duelme/arenatimer.php on line 95
    Full code
    PHP:
    <?php
    namespace duelme;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\Player;
    class 
    arenatimer extends PluginTask{
        private 
    $player;
        private 
    $num;
        public function 
    __construct(Plugin $ownerPlayer $player){
            
    parent::__construct($owner);
            
    $this->player $player;
            
    $this->num $this->getOwner()->num;
        }
        public function 
    onRun($currentTick){
            echo 
    $this->num;
            
    $player $this->player;
            
    $ap $this->getOwner()->dualing[$player->getName()];
            
    $app $this->getOwner()->getServer()->getPlayer($ap);
            if (
    $app instanceof Player){
                switch (
    $this->num){
                    case 
    60:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    30:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    15:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    10:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    5:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    4:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    3:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    2:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    1:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    0:
                        
    $app->sendMessage("[DuelMe] Duel ended due to max time was reached! Teleporting back to spawn");
                        
    $player->sendMessage("[DuelMe] Duel ended due to max time was reached! Teleporting back to spawn");
                        
    $this->getOwner()->endDuel($player$this->getTaskId());
                      
                        
    $this->cancel();
                      
                        return;
                    break;
                }
              
    //                 $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
    //                 $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                
    }
          
            
    $this->num--;
        }
      
        public function 
    cancel() {
            
    $this->getHandler()->cancel();
        }
    }
    Last edited: Jul 28, 2015
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Maybe your task isn't scheduled yet or is already cancelled?
  3. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Um
  4. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    no the task works but when time hits 0 it trys to cancel task but i get the error and the server stops
  5. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Any help?
  6. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  7. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    try what twice
  8. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  9. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    the code made it crash
  10. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    then drop down the code that we can see what uare doing wrong... one line is not enough
  11. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    it was in a spolier but so i removed it
    PHP:
    <?php
    namespace duelme;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\Player;
    class 
    arenatimer extends PluginTask{
        private 
    $player;
        private 
    $num;
        public function 
    __construct(Plugin $ownerPlayer $player){
            
    parent::__construct($owner);
            
    $this->player $player;
            
    $this->num $this->getOwner()->num;
        }
        public function 
    onRun($currentTick){
            echo 
    $this->num;
            
    $player $this->player;
            
    $ap $this->getOwner()->dualing[$player->getName()];
            
    $app $this->getOwner()->getServer()->getPlayer($ap);
            if (
    $app instanceof Player){
                switch (
    $this->num){
                    case 
    60:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    30:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    15:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    10:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    5:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    4:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    3:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    2:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    1:
                        
    $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                        
    $this->num--;
                        return ;
                    break;
                    case 
    0:
                        
    $app->sendMessage("[DuelMe] Duel ended due to max time was reached! Teleporting back to spawn");
                        
    $player->sendMessage("[DuelMe] Duel ended due to max time was reached! Teleporting back to spawn");
                        
    $this->getOwner()->endDuel($player$this->getTaskId());
                     
                        
    $this->cancel();
                     
                        return;
                    break;
                }
             
    //                 $app->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
    //                 $player->sendMessage("[DuelMe] Match has ".$this->num." seconds left");
                
    }
         
            
    $this->num--;
        }
     
        public function 
    cancel() {
            
    $this->getHandler()->cancel();
        }
    }
  12. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    no the code where u do this:

    PHP:
    $this->getServer()->getScheduler()->cancelTask($taskId);
  13. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Thats not the issue its the code above
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That looks like an interesting issue. Can you send me the full plugin so I can do some testing?
    BTW, you don't need to break after return.
  15. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    i sent you PM
  16. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    still dont have this fixed... :/

Share This Page

Advertisement