Entity: added a guard to prevent __construct() from running multiple times

this typically happens due to flawed logic in child classes in plugins which causes parent::__construct() to get called multiple times.
This commit is contained in:
Dylan K. Taylor 2022-03-22 15:33:31 +00:00
parent a5dab0f61e
commit 2b8a54f8ff
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -216,7 +216,13 @@ abstract class Entity{
/** @var int|null */
protected $targetId = null;
private bool $constructorCalled = false;
public function __construct(Location $location, ?CompoundTag $nbt = null){
if($this->constructorCalled){
throw new \LogicException("Attempted to call constructor for an Entity multiple times");
}
$this->constructorCalled = true;
Utils::checkLocationNotInfOrNaN($location);
$this->timings = Timings::getEntityTimings($this);