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

Solved How stop repeatingTask

Comments in 'Plugin Development' started by Kvetinac97, Jul 12, 2015.

  1. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    How can I STOP repeatingTask?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $ServerScheduler->cancelTask($Task->getTaskId())
    AndrewBit likes this.
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Where place it? I have:
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new ArenaStartTask($this$arenanumber), 1*20);
    In ArenaStartTask.php:

    PHP:
    <?php
     
    namespace Q7;
     use 
    pocketmine\scheduler\PluginTask;
     class 
    ArenaStartTask extends PluginTask{
    public function 
    _construct(Main $main$arenanumber){
    $this->main $main;
    $this->arenanumber $arenanumber;
    }
    public function 
    onRun($t){
    //something
    }
    }
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Learn PHP. It's not supposed to be put anywhere.
    Falk likes this.
  5. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Thanks :/ Really good reponse.
  6. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Or this?
    PHP:
    $arenanumber 3;
    $this->getServer()->getScheduler()->cancelTask(StartArenaTask($this$arenanumber)->getTaskId());
    So what?????
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Save the task object when you schedule it. Later when you cancel it, get back the task object as $Task.
    And you shouldn't ask where the code should be put. I should be the one asking. It is your own idea to cancel the task, so you should be the one who knows where you want to cancel your task at.
  8. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    OK. So:
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new ArenaStartTask($this$arenanumber$task1*20);
    $id $task->getId();
    $this->getServer()->getScheduler()->cancelTask($id);
    That should be right ;)
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask($task = new ArenaStartTask($this$arenanumber),  1*20);
    $id $task->getId();
    $this->getServer()->getScheduler()->cancelTask($id);
    But what's the meaning of cancelling it immediately after scheduling i5?
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I think in the middle there is another part of code.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Save the ID in a class property.
  12. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    OK. I edited the code to cancel Task from the task.php
    PHP:
    $this->getHandler()->cancelTask($this);
  13. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Hmm. I save it like that:
    $this->getServer()->getScheduler()->scheduleRepeatingTask($task[$player->getName()] = new ArenaStartTask($this, $arenanumber), 1*20);
    How can i get the id? ->getId doesn't exist
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    You just bumped a old thread :D
    BTW, it is getTaskId().
  15. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Okay. I thought so. But still doesn't cancel my task.

Share This Page

Advertisement