I made a minigame plugin with some countdown when you run the command, but when the player quits the game while the countdown still playing, the server is crashes. How to cancel the task when the player quits the server?? Heres my attempt : PHP: public function onQuit(PlayerQuitEvent $event) { $player = $event->getPlayer(); $task = new GameTask($this, $player); $this->getServer()->getScheduler()->scheduleRepeatingTask($task, 20); }
Using the awesome search button that's embed on the top right of this website. I've found this thread that may help you! https://forums.pmmp.io/threads/activate-and-cancel-task-help.7152/
thank you but that is not what im asking for, i need a code to cancel task WHEN the player quits the game
save the task's id: PHP: $task = new GameTask($this, $player);$taskId = $task->getTaskId();$this->getServer()->getScheduler()->scheduleRepeatingTask($task, 20); then cancel it when player quits: PHP: $this->getScheduler()->cancelTask($taskId);
That's exactly what you are looking for. It has the code you need, but just with a different concept.