diff --git a/src/thread/CommonThreadPartsTrait.php b/src/thread/CommonThreadPartsTrait.php index de2ecbde8..f01a979b0 100644 --- a/src/thread/CommonThreadPartsTrait.php +++ b/src/thread/CommonThreadPartsTrait.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\thread; +use pmmp\thread\Thread as NativeThread; use pmmp\thread\ThreadSafeArray; use pocketmine\errorhandler\ErrorToExceptionHandler; use pocketmine\Server; @@ -96,6 +97,15 @@ trait CommonThreadPartsTrait{ public function getCrashInfo() : ?ThreadCrashInfo{ return $this->crashInfo; } + public function start(int $options = NativeThread::INHERIT_NONE) : bool{ + ThreadManager::getInstance()->add($this); + + if($this->getClassLoaders() === null){ + $this->setClassLoaders(); + } + return parent::start($options); + } + final public function run() : void{ error_reporting(-1); $this->registerClassLoaders(); diff --git a/src/thread/Thread.php b/src/thread/Thread.php index 706f96429..2f0204022 100644 --- a/src/thread/Thread.php +++ b/src/thread/Thread.php @@ -38,16 +38,6 @@ use pocketmine\scheduler\AsyncTask; abstract class Thread extends NativeThread{ use CommonThreadPartsTrait; - public function start(int $options = NativeThread::INHERIT_NONE) : bool{ - //this is intentionally not traitified - ThreadManager::getInstance()->add($this); - - if($this->getClassLoaders() === null){ - $this->setClassLoaders(); - } - return parent::start($options); - } - /** * Stops the thread using the best way possible. Try to stop it yourself before calling this. */ diff --git a/src/thread/Worker.php b/src/thread/Worker.php index 3bc5cda97..7d9ca72c3 100644 --- a/src/thread/Worker.php +++ b/src/thread/Worker.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace pocketmine\thread; -use pmmp\thread\Thread as NativeThread; use pmmp\thread\Worker as NativeWorker; use pocketmine\scheduler\AsyncTask; @@ -40,16 +39,6 @@ use pocketmine\scheduler\AsyncTask; abstract class Worker extends NativeWorker{ use CommonThreadPartsTrait; - public function start(int $options = NativeThread::INHERIT_NONE) : bool{ - //this is intentionally not traitified - ThreadManager::getInstance()->add($this); - - if($this->getClassLoaders() === null){ - $this->setClassLoaders(); - } - return parent::start($options); - } - /** * Stops the thread using the best way possible. Try to stop it yourself before calling this. */