Check connection status on batch, check sleep when players leave a level

This commit is contained in:
Shoghi Cervantes 2015-05-10 14:58:07 +02:00
parent 925b0c1b07
commit 13906b32b8
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
4 changed files with 11 additions and 6 deletions

View File

@ -2668,10 +2668,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
foreach($this->windowIndex as $window){
$this->removeWindow($window);
}
$this->interface->close($this, $notify ? $reason : "");
$chunkX = $chunkZ = null;
foreach($this->usedChunks as $index => $d){
Level::getXZ($index, $chunkX, $chunkZ);
$this->level->freeChunk($chunkX, $chunkZ, $this);
@ -2680,6 +2677,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
parent::close();
$this->interface->close($this, $notify ? $reason : "");
$this->loggedIn = false;
if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){

View File

@ -1833,7 +1833,9 @@ class Server{
$targets = [];
foreach($players as $p){
$targets[] = $this->identifiers[spl_object_hash($p)];
if($p->isConnected()){
$targets[] = $this->identifiers[spl_object_hash($p)];
}
}
if(!$forceSync and $this->networkCompressionAsync){

View File

@ -1460,13 +1460,13 @@ abstract class Entity extends Location implements Metadatable{
if(!$this->closed){
$this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
$this->closed = true;
$this->despawnFromAll();
if($this->chunk !== null){
$this->chunk->removeEntity($this);
}
if($this->level instanceof Level){
$this->level->removeEntity($this);
}
$this->despawnFromAll();
}
}

View File

@ -659,6 +659,10 @@ class Level implements ChunkManager, Metadatable{
}
public function checkSleep(){
if(count($this->players) === 0){
return;
}
$resetTime = true;
foreach($this->getPlayers() as $p){
if(!$p->isSleeping()){
@ -2078,7 +2082,7 @@ class Level implements ChunkManager, Metadatable{
if($entity instanceof Player){
unset($this->players[$entity->getId()]);
//$this->everyoneSleeping();
$this->checkSleep();
}else{
$entity->kill();
}