From b2249f93c0ec3732b7110d727d51cebdf953247b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Jul 2020 11:02:21 +0100 Subject: [PATCH] TaskHandler: bail if given a task that already has a handler This fixes undefined behaviour when scheduling the same task twice. This is usually accidental and almost never desirable. Note that this still allows a task to be scheduled again after it has been cancelled; it only disallows scheduling a task multiple times concurrently. This commit will probably break MyPlot and other plugins that have self-scheduling tasks, but as far as I can tell those use-cases should be replaced with self-cancelling repeating tasks anyway. --- src/pocketmine/scheduler/TaskHandler.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/scheduler/TaskHandler.php b/src/pocketmine/scheduler/TaskHandler.php index ddecf16eb..04b5f1a42 100644 --- a/src/pocketmine/scheduler/TaskHandler.php +++ b/src/pocketmine/scheduler/TaskHandler.php @@ -55,6 +55,9 @@ class TaskHandler{ private $ownerName; public function __construct(Task $task, int $taskId, int $delay = -1, int $period = -1, ?string $ownerName = null){ + if($task->getHandler() !== null){ + throw new \InvalidArgumentException("Cannot assign multiple handlers to the same task"); + } $this->task = $task; $this->taskId = $taskId; $this->delay = $delay;