Fixed inventories not working after dying with inventory open

closes #4185
closes #4177
This commit is contained in:
Dylan K. Taylor 2021-11-08 23:03:41 +00:00
parent 6fdcfb01c8
commit 6efb1db107
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 12 additions and 2 deletions

View File

@ -111,6 +111,7 @@ use pocketmine\player\UsedChunkStatus;
use pocketmine\player\XboxLivePlayerInfo; use pocketmine\player\XboxLivePlayerInfo;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\timings\Timings; use pocketmine\timings\Timings;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\ObjectSet; use pocketmine\utils\ObjectSet;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
use pocketmine\utils\Utils; use pocketmine\utils\Utils;
@ -714,7 +715,7 @@ class NetworkSession{
public function onServerDeath() : void{ public function onServerDeath() : void{
if($this->handler instanceof InGamePacketHandler){ //TODO: this is a bad fix for pre-spawn death, this shouldn't be reachable at all at this stage :( if($this->handler instanceof InGamePacketHandler){ //TODO: this is a bad fix for pre-spawn death, this shouldn't be reachable at all at this stage :(
$this->setHandler(new DeathPacketHandler($this->player, $this)); $this->setHandler(new DeathPacketHandler($this->player, $this, $this->invManager ?? throw new AssumptionFailedError()));
} }
} }

View File

@ -23,7 +23,9 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\handler; namespace pocketmine\network\mcpe\handler;
use pocketmine\network\mcpe\InventoryManager;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket; use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\network\mcpe\protocol\RespawnPacket; use pocketmine\network\mcpe\protocol\RespawnPacket;
use pocketmine\network\mcpe\protocol\types\PlayerAction; use pocketmine\network\mcpe\protocol\types\PlayerAction;
@ -35,10 +37,12 @@ class DeathPacketHandler extends PacketHandler{
private $player; private $player;
/** @var NetworkSession */ /** @var NetworkSession */
private $session; private $session;
private InventoryManager $inventoryManager;
public function __construct(Player $player, NetworkSession $session){ public function __construct(Player $player, NetworkSession $session, InventoryManager $inventoryManager){
$this->player = $player; $this->player = $player;
$this->session = $session; $this->session = $session;
$this->inventoryManager = $inventoryManager;
} }
public function setUp() : void{ public function setUp() : void{
@ -58,6 +62,11 @@ class DeathPacketHandler extends PacketHandler{
return false; return false;
} }
public function handleContainerClose(ContainerClosePacket $packet) : bool{
$this->inventoryManager->onClientRemoveWindow($packet->windowId);
return true;
}
public function handleRespawn(RespawnPacket $packet) : bool{ public function handleRespawn(RespawnPacket $packet) : bool{
if($packet->respawnState === RespawnPacket::CLIENT_READY_TO_SPAWN){ if($packet->respawnState === RespawnPacket::CLIENT_READY_TO_SPAWN){
$this->session->sendDataPacket(RespawnPacket::create( $this->session->sendDataPacket(RespawnPacket::create(