Entity: Fire EntitySpawnEvent/ItemSpawnEvent on the first entity tick, instead of in the constructor (#5314)

This allows plugins to modify the entity via setters in EntitySpawnEvent without their changes getting overwritten by setter calls directly after the 'new YourEntity' statement.

As well as benefiting plugins, this also clears a path for a BC-breaking change in PM5 (to have the programmer use addEntity() to spawn entities, instead of the constructor doing it, which will improve on a number of data handling aspects).

fixes #4973

This targets next-minor because it has some side effects on plugins that depended on the old behaviour, such as VanillaHopper, so it's not suitable for a patch release.
This commit is contained in:
Dylan T
2022-09-29 22:30:12 +01:00
committed by GitHub
parent 0c7f8470b9
commit 41970feb57
3 changed files with 20 additions and 3 deletions

View File

@ -1343,6 +1343,10 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->lastUpdate = $currentTick;
if($this->justCreated){
$this->onFirstUpdate($currentTick);
}
if(!$this->isAlive() && $this->spawned){
$this->onDeathUpdate($tickDiff);
return true;