classLoader; } public function setClassLoader(\ClassLoader $loader = null){ if($loader === null){ $loader = Server::getInstance()->getLoader(); } $this->classLoader = $loader; } /** * Registers the class loader for this thread. * * WARNING: This method MUST be called from any descendent threads' run() method to make autoloading usable. * If you do not do this, you will not be able to use new classes that were not loaded when the thread was started * (unless you are using a custom autoloader). */ public function registerClassLoader(){ require(\pocketmine\PATH . "vendor/autoload.php"); if(!interface_exists("ClassLoader", false)){ require(\pocketmine\PATH . "src/spl/ClassLoader.php"); require(\pocketmine\PATH . "src/spl/BaseClassLoader.php"); } if($this->classLoader !== null){ $this->classLoader->register(false); } } public function start(?int $options = \PTHREADS_INHERIT_ALL){ ThreadManager::getInstance()->add($this); if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){ if($this->getClassLoader() === null){ $this->setClassLoader(); } return parent::start($options); } return false; } /** * Stops the thread using the best way possible. Try to stop it yourself before calling this. */ public function quit(){ $this->isKilled = true; $this->notify(); if(!$this->isJoined()){ if(!$this->isTerminated()){ $this->join(); } } ThreadManager::getInstance()->remove($this); } public function getThreadName() : string{ return (new \ReflectionClass($this))->getShortName(); } }