Fixed entity visibility Player object memory leak, close #416

This commit is contained in:
Dylan K. Taylor 2017-03-28 12:23:49 +01:00
parent 217f66e180
commit 2079e2fd88
2 changed files with 9 additions and 4 deletions

View File

@ -3100,6 +3100,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
foreach($this->usedChunks as $index => $d){
Level::getXZ($index, $chunkX, $chunkZ);
$this->level->unregisterChunkLoader($this, $chunkX, $chunkZ);
foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){
$entity->despawnFrom($this, false);
}
unset($this->usedChunks[$index]);
}

View File

@ -708,11 +708,13 @@ abstract class Entity extends Location implements Metadatable{
/**
* @param Player $player
*/
public function despawnFrom(Player $player){
public function despawnFrom(Player $player, bool $send = true){
if(isset($this->hasSpawned[$player->getLoaderId()])){
if($send){
$pk = new RemoveEntityPacket();
$pk->eid = $this->id;
$player->dataPacket($pk);
}
unset($this->hasSpawned[$player->getLoaderId()]);
}
}