I know if I want to let task work I do $this->getScheduler()->scheduleRepeatingTask(new NameTask($this), 20); What If I put it in command and I want if the first one write the command the second one can't let the task work while it's work! Hope you help me .
What I did now for fixing this issue I made config [Key => false] if it false task will work and would be Key => true so no one can do task job again but I don't want it in config what I do make sure that I don't know a lot in php I'm learning new stuff by ask and my ideas!! and I'm happy with that!
if you only want the task running once, you can use DelayedTask instead of RepeatingTask Simply changing PHP: $this->getScheduler()->scheduleRepeatingTask(new NameTask($this), 20); Into PHP: #after 20 tick (= 1sec) the task will be excuted then cancelled$this->getScheduler()->scheduleDelayedTask(new NameTask($this), 20); And the Task will cancelled itself after one run
PHP: #after 20 tick (= 1sec) the task will be excuted then cancelled$this->getScheduler()->scheduleDelayedTask(new NameTask($this), 20); This is for not work because it will work once so if I have a timer it would move one number! PHP: class NameTask extends Task{ public function __construct(Main $plugin){ $this->plugin = $plugin; $this->time = 10; } public function onRun($tick){ $this->time--; if($this->time >= 0){ $this->plugin->getLogger()->info($this->time); } if($this->time < 0){ $this->cancel(); } } public function cancel() { $this->getHandler()->cancel(); }} I want from task If it's running! can't be running again while it's running ! I hope you understand me
ok i get you, you didnt want to create another task when already have one, i thought you didnt want to make the task run twice
NO PROBLEM, I learnt something new and I see that good for me. Thx about scheduleDelayedTask it would be helpful for I nice idae