diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index e98f5067f..4a2fb14cd 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -794,10 +794,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ * @return boolean */ public function sleepOn(Vector3 $pos){ - foreach($this->level->getPlayers() as $p){ - if($p->sleeping instanceof Vector3){ - if($pos->distance($p->sleeping) <= 0.1){ - return false; + foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){ + if($p instanceof Player){ + if($p->sleeping instanceof Vector3){ + if($pos->distance($p->sleeping) <= 0.1){ + return false; + } } } } @@ -2273,10 +2275,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } + foreach($this->windowIndex as $window){ + $this->removeWindow($window); + } + $this->interface->close($this, $reason); $this->level->freeAllChunks($this); - parent::close(); $this->loggedIn = false; @@ -2284,6 +2289,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){ $this->server->broadcastMessage($ev->getQuitMessage()); } + $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->spawned = false; $this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . str_replace(["\n", "\r"], [" ", ""], $reason)); @@ -2514,6 +2520,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ public function teleport(Vector3 $pos, $yaw = null, $pitch = null){ if(parent::teleport($pos, $yaw, $pitch)){ + + foreach($this->windowIndex as $window){ + if($window === $this->inventory){ + continue; + } + $this->removeWindow($window); + } + $this->airTicks = 300; $this->fallDistance = 0; $this->orderChunks(); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 164bac8f6..476ec0c64 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1185,8 +1185,8 @@ abstract class Entity extends Location implements Metadatable{ if($this->chunk instanceof FullChunk){ $this->chunk->removeEntity($this); } - if(($level = $this->level) instanceof Level){ - $level->removeEntity($this); + if($this->level instanceof Level){ + $this->level->removeEntity($this); } $this->despawnFromAll(); $this->level = null; diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index a23e8e46e..1e0c3b16e 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -226,4 +226,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ return $d; } + public function close(){ + if(!$this->closed){ + var_dump("CLOSED"); + foreach($this->getInventory()->getViewers() as $player){ + $this->getInventory()->close($player); + } + $this->inventory = null; + parent::close(); + } + } + } diff --git a/src/pocketmine/inventory/ChestInventory.php b/src/pocketmine/inventory/ChestInventory.php index acd04533b..5ed416101 100644 --- a/src/pocketmine/inventory/ChestInventory.php +++ b/src/pocketmine/inventory/ChestInventory.php @@ -21,6 +21,7 @@ namespace pocketmine\inventory; +use pocketmine\level\Level; use pocketmine\network\protocol\TileEventPacket; use pocketmine\Player; use pocketmine\Server; @@ -48,7 +49,9 @@ class ChestInventory extends ContainerInventory{ $pk->z = $this->getHolder()->getZ(); $pk->case1 = 1; $pk->case2 = 2; - Server::broadcastPacket($this->getHolder()->getLevel()->getPlayers(), $pk); + if(($level = $this->getHolder()->getLevel()) instanceof Level){ + Server::broadcastPacket($level->getUsingChunk($this->getHolder()->getX() >> 4, $this->getHolder()->getZ() >> 4), $pk); + } } } @@ -60,7 +63,9 @@ class ChestInventory extends ContainerInventory{ $pk->z = $this->getHolder()->getZ(); $pk->case1 = 1; $pk->case2 = 0; - Server::broadcastPacket($this->getHolder()->getLevel()->getPlayers(), $pk); + if(($level = $this->getHolder()->getLevel()) instanceof Level){ + Server::broadcastPacket($level->getUsingChunk($this->getHolder()->getX() >> 4, $this->getHolder()->getZ() >> 4), $pk); + } } parent::onClose($who); }