Clean up inventory auto close mess from PM3

on PM3 there was no concept of 'current window', we had no idea which window the player was actually looking at.
This commit is contained in:
Dylan K. Taylor
2021-11-08 23:51:25 +00:00
parent 5be429a8c4
commit c7beb0a702
2 changed files with 6 additions and 8 deletions

View File

@ -1316,7 +1316,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* as a command.
*/
public function chat(string $message) : bool{
$this->doCloseInventory();
$this->removeCurrentWindow();
$message = TextFormat::clean($message, false);
foreach(explode("\n", $message) as $messagePart){
@ -1572,7 +1572,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* @return bool if the block was successfully broken, false if a rollback needs to take place.
*/
public function breakBlock(Vector3 $pos) : bool{
$this->doCloseInventory();
$this->removeCurrentWindow();
if($this->canInteract($pos->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 7)){
$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
@ -1991,7 +1991,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
//prevent the player receiving their own disconnect message
$this->server->unsubscribeFromAllBroadcastChannels($this);
$this->doCloseInventory();
$this->removeCurrentWindow();
$ev = new PlayerQuitEvent($this, $quitMessage ?? $this->getLeaveMessage(), $reason);
$ev->call();
@ -2104,7 +2104,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
protected function onDeath() : void{
//Crafting grid must always be evacuated even if keep-inventory is true. This dumps the contents into the
//main inventory and drops the rest on the ground.
$this->doCloseInventory();
$this->removeCurrentWindow();
$ev = new PlayerDeathEvent($this, $this->getDrops(), $this->getXpDropAmount(), null);
$ev->call();
@ -2322,7 +2322,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* @internal Called to clean up crafting grid and cursor inventory when it is detected that the player closed their
* inventory.
*/
public function doCloseInventory() : void{
private function doCloseInventory() : void{
$inventories = [$this->craftingGrid, $this->cursorInventory];
if($this->currentWindow instanceof TemporaryInventory){
$inventories[] = $this->currentWindow;