pmmp / PocketMine-MP

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

Setting inventory items during PlayerLoginEvent causes crashes #4275

Closed HashimTheArab closed 3 years ago

HashimTheArab commented 3 years ago

Issue description

Steps to reproduce the issue

$player->getInventory()->addItem() in PlayerLoginEvent

OS and versions

Plugins

Plugins (2): Core v3.2.0, DevTools v1.15.0+dev

Crashdump, backtrace or other files

xDidntPot commented 3 years ago

Furry

xDidntPot commented 3 years ago

I can confirm its crashing, tried it myself.

ethaniccc commented 3 years ago

Everything isn’t fully constructed and created at PlayerLoginEvent. Just do whatever you need to do on PlayerJoinEvent or whatnot

HashimTheArab commented 3 years ago

Yea I know I just thought it should return ?InventoryManager

dktapps commented 3 years ago

Then it would still crash, just in a different place.

HashimTheArab commented 3 years ago

Yea but the error would make sense "cannot call function addItem on null", go ahead and close it I guess

edit: I misunderstood Dylan

xxFLORII commented 3 years ago

if ( !is_null($player->getNetworkSession()) && $player->isConnected() && $player->getNetworkSession()->getInvManager() instanceof InventoryManager ) {

try to add this check @Prim69

dktapps commented 3 years ago

A solution I've previously considered to this and other problems is to move the PlayerLoginEvent call out of the Player constructor.