Improved inventory and window allocation, fixes #2200

This commit is contained in:
Shoghi Cervantes 2014-10-20 09:48:11 +02:00
parent 2f8267aa1e
commit 15de0eece7
4 changed files with 39 additions and 9 deletions

View File

@ -794,10 +794,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
* @return boolean * @return boolean
*/ */
public function sleepOn(Vector3 $pos){ public function sleepOn(Vector3 $pos){
foreach($this->level->getPlayers() as $p){ foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){
if($p->sleeping instanceof Vector3){ if($p instanceof Player){
if($pos->distance($p->sleeping) <= 0.1){ if($p->sleeping instanceof Vector3){
return false; 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->interface->close($this, $reason);
$this->level->freeAllChunks($this); $this->level->freeAllChunks($this);
parent::close(); parent::close();
$this->loggedIn = false; $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() != ""){ if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){
$this->server->broadcastMessage($ev->getQuitMessage()); $this->server->broadcastMessage($ev->getQuitMessage());
} }
$this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);
$this->spawned = false; $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)); $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){ public function teleport(Vector3 $pos, $yaw = null, $pitch = null){
if(parent::teleport($pos, $yaw, $pitch)){ if(parent::teleport($pos, $yaw, $pitch)){
foreach($this->windowIndex as $window){
if($window === $this->inventory){
continue;
}
$this->removeWindow($window);
}
$this->airTicks = 300; $this->airTicks = 300;
$this->fallDistance = 0; $this->fallDistance = 0;
$this->orderChunks(); $this->orderChunks();

View File

@ -1185,8 +1185,8 @@ abstract class Entity extends Location implements Metadatable{
if($this->chunk instanceof FullChunk){ if($this->chunk instanceof FullChunk){
$this->chunk->removeEntity($this); $this->chunk->removeEntity($this);
} }
if(($level = $this->level) instanceof Level){ if($this->level instanceof Level){
$level->removeEntity($this); $this->level->removeEntity($this);
} }
$this->despawnFromAll(); $this->despawnFromAll();
$this->level = null; $this->level = null;

View File

@ -226,4 +226,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $d; 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();
}
}
} }

View File

@ -21,6 +21,7 @@
namespace pocketmine\inventory; namespace pocketmine\inventory;
use pocketmine\level\Level;
use pocketmine\network\protocol\TileEventPacket; use pocketmine\network\protocol\TileEventPacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server; use pocketmine\Server;
@ -48,7 +49,9 @@ class ChestInventory extends ContainerInventory{
$pk->z = $this->getHolder()->getZ(); $pk->z = $this->getHolder()->getZ();
$pk->case1 = 1; $pk->case1 = 1;
$pk->case2 = 2; $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->z = $this->getHolder()->getZ();
$pk->case1 = 1; $pk->case1 = 1;
$pk->case2 = 0; $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); parent::onClose($who);
} }