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

Task Cancelling

Comments in 'Plugin Development' started by CrazedMiner, Jul 17, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I'm trying to cancel this task but for some reason it isn't working....

    Main.php
    PHP:
    public function startMatch(Player $playerPlayer $opponent) {
            
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Tasks\StartMatch($this$player$opponent$arena), 20);
        }
    StartMatch.php
    PHP:
    public function __construct(Main $plugin$player$opponent$arena) {
            
    parent::__construct($plugin);
            
    $this->plugin $plugin;
            
    $this->player $player;
            
    $this->opponent $opponent;
            
    $this->arena $arena;
        }

    public function 
    endMatch() {
            
    $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId());
        }
    All the variables are defined and the console doesn't show any errors, the task just continues....

    Thanks for your help (in advance)!
    hoyinm14mc likes this.
  2. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    I don't think the task id is being initialized at all.. (At least not from reading the source). What is the value you get from $this->getTaskId()?

    What I do myself is when schedule, I get the id from the task handler.
    CrazedMiner likes this.
  3. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I got it to broadcast the task ID to the server and it was -1
  4. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Anyone else have any ideas?
  5. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    PHP:
    public function startMatch(Player $playerPlayer $opponent) {
       
    $h $this->getServer()->getScheduler()->scheduleRepeatingTask($t = new Tasks\StartMatch($this$player$opponent$arena), 20);
       
    $t->setTaskId($h->getTaskId());
     }
    Or something like that (I did not test this).
    CrazedMiner likes this.
  6. Pman1220
    Offline

    Pman1220 Active Member Plugin Developer

    Joined:
    Nov 21, 2013
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Pman1220
    Did you figure it out? Im having the same problem.
    CrazedMiner likes this.
  7. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    +1
  8. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Undefined method setTaskId()
  9. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    I solved it like this

    PHP:
    public function onRun($t){
    if (
    $this->stopped === null){
    //I make something here, e.g. counting how many times was task executed
    $this->stopped true;
    }
    }
    Yes, this won't cancel the task, but it won't be executed
    hoyinm14mc likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It will be laggy.
    Creeperface likes this.
  11. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I need the task to cancel, the entire point of creating a task was so I can just delete the information after the task is finished and I can create a new one at any time.
    hoyinm14mc likes this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The best way is to make one repeated task and accept new tasks to run.

Share This Page

Advertisement