Fixed plugin schedulers crashing after disable/reenable

This commit is contained in:
Dylan K. Taylor 2018-05-31 12:34:22 +01:00
parent 05ef13b23a
commit 15270f8329
2 changed files with 8 additions and 3 deletions

View File

@ -575,6 +575,7 @@ class PluginManager{
foreach($plugin->getDescription()->getPermissions() as $perm){
$this->addPermission($perm);
}
$plugin->getScheduler()->setEnabled(true);
$plugin->getPluginLoader()->enablePlugin($plugin);
}catch(\Throwable $e){
$this->server->getLogger()->logException($e);

View File

@ -36,7 +36,7 @@ class TaskScheduler{
private $owner;
/** @var bool */
private $shutdown = false;
private $enabled = true;
/**
* @var ReversePriorityQueue<Task>
@ -146,7 +146,7 @@ class TaskScheduler{
* @throws \InvalidStateException
*/
private function addTask(Task $task, int $delay, int $period){
if($this->shutdown){
if(!$this->enabled){
throw new \InvalidStateException("Tried to schedule task after scheduler shutdown");
}
@ -178,10 +178,14 @@ class TaskScheduler{
}
public function shutdown() : void{
$this->shutdown = true;
$this->enabled = false;
$this->cancelAllTasks();
}
public function setEnabled(bool $enabled) : void{
$this->enabled = $enabled;
}
/**
* @param int $currentTick
*/