mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Fixed misuse of kill() and close() when deleting entities (#1490)
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user