diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index a87296ed2..c76f617fd 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -562,6 +562,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ /** @var bool */ protected $constructed = false; + /** @var bool */ + private $closeInFlight = false; public function __construct(Level $level, CompoundTag $nbt){ $this->constructed = true; @@ -2109,7 +2111,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ * WARNING: Entities are unusable after this has been executed! */ public function close() : void{ + if($this->closeInFlight){ + return; + } + if(!$this->closed){ + $this->closeInFlight = true; (new EntityDespawnEvent($this))->call(); $this->closed = true; @@ -2128,6 +2135,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->namedtag = null; $this->lastDamageCause = null; + $this->closeInFlight = false; } }