Entity: don't flag as closed until just before cycle destruction

this allows stuff that requires a non-cycle-destroyed state to still operate during onDispose().
This commit is contained in:
Dylan K. Taylor 2021-03-19 01:00:49 +00:00
parent c092a2e836
commit 69cb0ba1bb
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -177,6 +177,7 @@ abstract class Entity{
/** @var bool */
protected $closed = false;
private bool $closeInFlight = false;
/** @var bool */
private $needsDespawn = false;
@ -1518,12 +1519,18 @@ abstract class Entity{
* WARNING: Entities are unusable after this has been executed!
*/
final public function close() : void{
if($this->closeInFlight){
return;
}
if(!$this->closed){
$this->closed = true;
$this->closeInFlight = true;
(new EntityDespawnEvent($this))->call();
$this->onDispose();
$this->closed = true;
$this->destroyCycles();
$this->closeInFlight = false;
}
}