Muqsit / FakePlayer

Test your PocketMine-MP server by having (real-looking) fake players assist you.
https://poggit.pmmp.io/ci/Muqsit/FakePlayer
57 stars 22 forks source link

Fix `Loader::addPlayer()` Crash when Player is created asynchronously #28

Closed Swift-Strider closed 2 years ago

Swift-Strider commented 2 years ago

Fixes Issues

Problem

Loader::addPlayer() would oftentimes fail because it mistakenly assumes that a player object will be created after it sends a finishing ResourcePackClientResponsePacket::STATUS_COMPLETED message. However if the server is brand new, or hasn't generated spawn chunks yet, PocketMine-MP may potentially defer on creating the Player object way after Loader::addPlayer() has returned.

Proposed Solution

Change Load::addPlayer()'s signature to this:

Loader::addPlayer(FakePlayerInfo $info) : Promise;

And have addPlayer() return a promise that resolves with a Player after registering it as a FakePlayer, to be consistent with how the previous version similarly returned a Player after registering its corresponding FakePlayer.

Justification

FakePlayer is very useful for automated testing. Capital's suite tests rely on creating a brand new PocketMine-MP instance for its tests. For FakePlayer to work in that sort of situation, it has to handle the occasions where a player isn't created immediately.