I'm trying to cancel this task but for some reason it isn't working.... Main.php PHP: public function startMatch(Player $player, Player $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)!
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.
PHP: public function startMatch(Player $player, Player $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).
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
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.