Previously after a player tick, the player's location would be reset back to the location which they had prior to the tick, only to be (hopefully) corrected at a later point, after the client had attempted (and failed) to acknowledge the location change.
World.addEntity(Entity entity) calls addEntity(entity, SpawnReason.DEFAULT), which contains the code that was originally in addEntity (and some event code).
However, WorldServer previously only had addEntity(Entity entity), so if addEntity(Entity entity, SpawnReason spawnreason) was called directly, the UUID check that's found in it (the call to 'i') is skipped. This happens, among other places, in ChunkRegionLoader.spawnEntity (which /summon uses).
I fixed this by making WorldServer override the SpawnReason version, rather than the regular version. This is safe to do because the World version calls the SpawnReason version - it's not necessary to do the same thing in WorldServer.
Clean up implementation and firing of both of these events by routing
both unload and load behaviors to consistent method calls.
This fixes issues where a few places would not call Load or Unload events
when it should have.
Additionally, reduces diff by moving the neighbor marking code into these
consistent points.
Additional benefits of the change include improving the neighbor marking
methods to use getChunkIfLoaded instead of getLoadedChunkAt in some places,
as the latter will cause chunks to be marked active and not unload.
Finally, this also updates CraftWorld.loadChunk to use the new methods, as the
previous logic did not properly handle the new unload queue.