Entity: defer kill() until post-construct

this fixes crashes and various bugs with death logic executing during the creation of entities, as well as an age-old Player crash after quitting the server when dying.
This commit is contained in:
Dylan K. Taylor 2020-06-27 23:28:03 +01:00
parent 2a9586f6fd
commit 2104b2d32b
2 changed files with 7 additions and 5 deletions

View File

@ -554,7 +554,7 @@ abstract class Entity{
} }
if($amount <= 0){ if($amount <= 0){
if($this->isAlive()){ if($this->isAlive() and !$this->justCreated){
$this->kill(); $this->kill();
} }
}elseif($amount <= $this->getMaxHealth() or $amount < $this->health){ }elseif($amount <= $this->getMaxHealth() or $amount < $this->health){
@ -591,7 +591,12 @@ abstract class Entity{
protected function entityBaseTick(int $tickDiff = 1) : bool{ protected function entityBaseTick(int $tickDiff = 1) : bool{
//TODO: check vehicles //TODO: check vehicles
$this->justCreated = false; if($this->justCreated){
$this->justCreated = false;
if(!$this->isAlive()){
$this->kill();
}
}
$changedProperties = $this->getSyncedNetworkData(true); $changedProperties = $this->getSyncedNetworkData(true);
if(count($changedProperties) > 0){ if(count($changedProperties) > 0){

View File

@ -2105,9 +2105,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
} }
protected function onDeath() : void{ protected function onDeath() : void{
if(!$this->spawned){ //TODO: drop this hack
return;
}
//Crafting grid must always be evacuated even if keep-inventory is true. This dumps the contents into the //Crafting grid must always be evacuated even if keep-inventory is true. This dumps the contents into the
//main inventory and drops the rest on the ground. //main inventory and drops the rest on the ground.
$this->doCloseInventory(); $this->doCloseInventory();