getHandler() !== null){ throw new \InvalidArgumentException("Cannot assign multiple handlers to the same task"); } $this->task = $task; $this->delay = $delay; $this->period = $period; $this->taskName = $task->getName(); $this->ownerName = $ownerName ?? "Unknown"; $this->timings = Timings::getScheduledTaskTimings($this, $period); $this->task->setHandler($this); } public function isCancelled() : bool{ return $this->cancelled; } public function getNextRun() : int{ return $this->nextRun; } public function setNextRun(int $ticks) : void{ $this->nextRun = $ticks; } public function getTask() : Task{ return $this->task; } public function getDelay() : int{ return $this->delay; } public function isDelayed() : bool{ return $this->delay > 0; } public function isRepeating() : bool{ return $this->period > 0; } public function getPeriod() : int{ return $this->period; } public function cancel() : void{ try{ if(!$this->isCancelled()){ $this->task->onCancel(); } }finally{ $this->remove(); } } public function remove() : void{ $this->cancelled = true; $this->task->setHandler(null); } public function run() : void{ $this->timings->startTiming(); try{ $this->task->onRun(); }catch(CancelTaskException $e){ $this->cancel(); }finally{ $this->timings->stopTiming(); } } public function getTaskName() : string{ return $this->taskName; } public function getOwnerName() : string{ return $this->ownerName; } }