pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.28k stars 1.56k forks source link

Expose Server->autoloader so that plugins may create AsyncPools #6047

Closed Xd-pro closed 1 year ago

Xd-pro commented 1 year ago

Description

Allow plugins to create their own AsyncPools more easily by exposing the autoloader on the Server object.

Justification

Many a time I've seen others' plugins implement what is basically a clone of PM's AsyncPool for doing things like file and network I/O. This is wasteful to me when PM already contains such functionality. Sometimes, this means that plugin developers will just use the server's own AsyncPool for I/O and block compression and chunk generation.

Alternative methods

Reflection on the Server class

        $server = $this->getServer();
        $r = new ReflectionObject($server);
        $p = $r->getProperty('autoloader');
        $p->setAccessible(true);
        $this->pool = new AsyncPool(5, 500, $p->getValue($server), $server->getLogger(), $server->getTickSleeper());
dktapps commented 1 year ago

https://github.com/pmmp/PocketMine-MP/blob/stable/src/Server.php#L419

github-actions[bot] commented 1 year ago

Hi, we only accept bug reports on this issue tracker, but this issue looks like a support request.

Instead of creating an issue, try the following:

Docs | Discord | Forums

Xd-pro commented 1 year ago

oh god that was embarrassing