Skip to content

Entity change world event - #14437

Open
Codestech1 wants to merge 3 commits into
PaperMC:mainfrom
Codestech1:feat/entity-world-change-event
Open

Codestech1 wants to merge 3 commits into
PaperMC:mainfrom
Codestech1:feat/entity-world-change-event

Conversation

@Codestech1

Copy link
Copy Markdown

Adds an event that is called whenever an entity changes their world. I'm aware of that EntityTeleportEvent exists, but I decided to PR this new event because it can be very useful in some situations.

For example, I'm implementing a wrapper over Bukkit entities in my plugin that can be used to obtain those entities at any time, even if they are unloaded. It's done by storing their unload locations, and then whenever an entity instance is needed, chunks at unload locations are requested to be loaded. But since entities can teleport to unloaded chunks, and those chunks are not fully loaded after teleporting, the unload location needs to be manually updated when changing worlds of entities.

EntityTeleportEvent indeed could be used for my use case, but it would be pain to implement as I need to ignore the following EntityRemoveFromWorldEvent (I listen to that event to store unload locations), because it is fired before the new entity is placed, and as I said, chunk of the new entity is not loaded. This means that both EntityTeleportEvent and EntityRemoveFromWorldEvent are called while the entity is still in the previous world, and there is no event called in the new world. This is the perfect example where EntityChangeWorldEvent would be handy, because it is called after the world change.

@Codestech1
Codestech1 requested a review from a team as a code owner October 30, 2026 19:45
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Oct 30, 2026
@lynxplay

Copy link
Copy Markdown
Contributor

I think we'd be best off making the Player event extend this one then?
Not having event listeners for EntityChangeWorld event fire when a player changes worlds seems off.

@Codestech1

Copy link
Copy Markdown
Author

I think we'd be best off making the Player event extend this one then? Not having event listeners for EntityChangeWorld event fire when a player changes worlds seems off.

Alright, I can change it in a moment, but I need to update the branch with latest changes first.

@Codestech1

Copy link
Copy Markdown
Author

I think we'd be best off making the Player event extend this one then? Not having event listeners for EntityChangeWorld event fire when a player changes worlds seems off.

I've just looked at PlayerChangedWorldEvent and it extends PlayerEvent. Is it even possible to make that event extend this new event without breaking ABI then? I suppose that PlayerMoveEvent does not extend EntityMoveEvent for the same reason.

# Conflicts:
#	paper-server/patches/features/0003-Moonrise-optimisation-patches.patch
#	paper-server/patches/features/0016-Optimise-EntityScheduler-ticking.patch
@Codestech1
Codestech1 force-pushed the feat/entity-world-change-event branch from 149a42b to d2e4410 Compare October 31, 2026 16:44
@Codestech1

Copy link
Copy Markdown
Author

Rebased with latest changes.

@lynxplay

Copy link
Copy Markdown
Contributor

Eh, right, PlayerEvent does not extend entity event... Rather unfun for us (we cope that event interface moves happen at some point).

This event at least sounds sane, I think we are not going to be too happy with #14440 so maybe it is worth exploring other solutions if/once people reviewed on #14440. Otherwise I guess this event is fine then ™️

@Codestech1

Copy link
Copy Markdown
Author

Eh, right, PlayerEvent does not extend entity event... Rather unfun for us (we cope that event interface moves happen at some point).

This event at least sounds sane, I think we are not going to be too happy with #14440 so maybe it is worth exploring other solutions if/once people reviewed on #14440. Otherwise I guess this event is fine then ™️

Unfortunate for me, though I think I get why.

Well, it is unlikely for an entity to move when it's not tracked, but it's still possible from what I get. Is there any chance for that event to be merged if I changed it to entity change chunk event for example? I'll leave that pull request alone for now though until there's any feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

2 participants