classLoaders !== null ? (array) $this->classLoaders : null; } /** * @param \ClassLoader[] $autoloaders */ public function setClassLoaders(?array $autoloaders = null) : void{ $this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH; if($autoloaders === null){ $autoloaders = [Server::getInstance()->getLoader()]; } if($this->classLoaders === null){ $this->classLoaders = new \Threaded(); }else{ foreach($this->classLoaders as $k => $autoloader){ unset($this->classLoaders[$k]); } } foreach($autoloaders as $autoloader){ $this->classLoaders[] = $autoloader; } } /** * Registers the class loaders 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 registerClassLoaders() : void{ if($this->composerAutoloaderPath !== null){ require $this->composerAutoloaderPath; } $autoloaders = $this->classLoaders; if($autoloaders !== null){ foreach($autoloaders as $autoloader){ /** @var \ClassLoader $autoloader */ $autoloader->register(false); } } } final public function run() : void{ error_reporting(-1); $this->registerClassLoaders(); //set this after the autoloader is registered ErrorToExceptionHandler::set(); $this->onRun(); } /** * Runs code on the thread. */ abstract protected function onRun() : void; public function getThreadName() : string{ return (new \ReflectionClass($this))->getShortName(); } }