mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
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.
This commit is contained in:
parent
303344783a
commit
b2249f93c0
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user