I've been using PHP: $task = new kickTask($this, $player);$this->getServer()->getScheduler()->cancelTask($task->getTaskId()); Which doesn't work.
Well if you don't want to post it then fine. It just means we won't be able to see what you're doing wrong. This is the annoying part about "private" plugins. Post all your code or don't ask for help at all.
PHP: public function punishHackerCancel($player) { $task = new punishTask($this, $player); $this->getServer()->getScheduler()->cancelTask($task->getTaskId()); } if($this->isHacking($player)) { $this->punishHacker($player); } else { $this->punishHackerCancel($player); } '$this->punishHacker()' Is a delayed task, which works. The only thing that's not working is cancelling the task which is '$this->punishHackerCancel()'
See, you cancel the task immediately after the task is created. How can you cancel a task that isn't scheduled? Please learn PHP. new punishTask returns a new different instance of it every time. Hence, it has a different task ID. Moreover, you did it in an if else. If player is not hacking, if is not run, so you have nothing to cancel at all.[/PHP][/QUOTE]
The task is scheduled and defined within the isHacking() function, as I said before. The task already works, all I need to know is how to cancel it.
So if new punishTask returns a new instance should $task = the task I already scheduled? Example: PHP: $task = new dummyTask($this, $player);$this->getServer()->getScheduler()->scheduleDelayedTask($task), 20);// And to cancel it$task = $this->getServer()->getScheduler()->scheduleDelayedTask(new dummyTask($this, $player), 20);$this->getServer()->getScheduler()->cancelTask($task->getTaskId()); ?
You don't need to schedule it again... And as I have already said, `new dummyTask` returns a new task every time. You need to use class properties .
As I said, you have to use class properties to save the task. Actually you shouldn't schedule it at all. Schedule task if is hacking. Don't schedule task if not hacking.
I'm not 100% sure what you mean. Could you give an example? I assume you mean something like this PHP: $this->task = new punishTask($this, $player); Idk, I could be wrong.
Still doesn't work. This is what my cancel() function Looks like in the task PHP: public function cancel() { $this->getHandler()->cancel(); }
PHP: $this->task = new punishTask($this, $player);if($this->isHacking($player)) { $this->punishHacker($player); } else { $this->punishHackerCancel($player); } Public function punishHackCancel($player) { $this->getServer()->getScheduler()->cancelTask($this->task->getTaskId());} punishHacker($player) calls the delayed task.