Fixed misuse of kill() and close() when deleting entities (#1490)

This commit is contained in:
Dylan K. Taylor
2017-11-04 19:30:48 +00:00
committed by GitHub
parent e84ab8fec2
commit eab7b93483
10 changed files with 27 additions and 13 deletions

View File

@ -471,6 +471,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** @var bool */
protected $closed = false;
/** @var bool */
private $needsDespawn = false;
/** @var TimingsHandler */
protected $timings;
@ -1280,15 +1282,20 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->lastUpdate = $currentTick;
if($this->needsDespawn){
$this->close();
return false;
}
if(!$this->isAlive()){
$this->deadTicks += $tickDiff;
if($this->deadTicks >= $this->maxDeadTicks){
$this->despawnFromAll();
if(!$this->isPlayer){
$this->close();
$this->flagForDespawn();
}
}
return $this->deadTicks < $this->maxDeadTicks;
return true;
}
@ -1930,6 +1937,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
}
/**
* Flags the entity to be removed from the world on the next tick.
*/
public function flagForDespawn() : void{
$this->needsDespawn = true;
}
/**
* Returns whether the entity has been "closed".
* @return bool