As of recent API changes in PocketMine-MP, the onCompletion() function of AsyncTasks does no longer receive a Server Instance. e.g.: Code: public function onCompletion(Server $server) : void { } changed to Code: public function onCompletion() : void { } Now: How do we get the server instance again WITHOUT having to try to serialize it in the constructor (which sometime is impossible)? The answer is very simple: Create a direct call to the static getInstance() function of the Server class. To use this, make sure you have Code: use pocketmine\Server; in you asynctask's imports. Now, to regain your $server variable, just create the direct call to the Server::getInstance() function in your onCompletion() function. So the code changed from: Code: public function onCompletion(Server $server) : void { } to: Code: public function onCompletion() : void { $server = Server::getInstance(); } Small notice for staff: It might be a good idea to move this in the low quality section as it is not relevant for a lot of people...
This is very easy and I do not think it would help, but if anyone has that issue, the class for Server is pocketmine\Server. This means you have to add use pocketmine\Server; in the imported classes.
4.0.0 is indev and subject to change, so this cannot be considered a "resource". This is a "quick fix" solution which anyone with half a brain could come up with on their own. A walkthrough of the usage of thread-local storage would have been more valuable (most plugin tasks don't need a server, they need their plugin instance).
I agree. I just thought the developemnt section might be the wrong place to post this since this is a small fix description rather than a request. I designed this with the hope that it will save a bit of someone's time, but if you think a how to get a plugin's instance guide would be more usefull I could do that aswell, of course. I will post the next guide directly in the facepalm section, just to make sure.