Skip to content

Add world to Entity AddTo/RemoveFrom Events#10182

Closed
1stGlitch wants to merge 1 commit into
PaperMC:masterfrom
1stGlitch:master
Closed

Add world to Entity AddTo/RemoveFrom Events#10182
1stGlitch wants to merge 1 commit into
PaperMC:masterfrom
1stGlitch:master

Conversation

@1stGlitch
Copy link
Copy Markdown
Contributor

When a plugin listens to the EntityAddToWorld and EntityRemoveFromWorld events, I don't believe there is currently any method of directly obtaining which world the entity was actually added to/removed from. Using event.getEntity().getWorld() works in many cases, but not all. Specifically, when an entity is teleported from one world to another, the location of the entity is updated prior to the removal event being called. This means that when an entity goes through a nether/end portal or is teleported between worlds with a command, a plugin listening to the EntityRemoveFromWorldEvent has no way of determining which world the entity was actually removed from (without relying on other events).

To resolve this, I've added the world as a field in the events along with a getter to retrieve it. I also removed an unused import and made the documentation more clear on the event behaviour when chunks load/unload.

@1stGlitch 1stGlitch requested a review from a team as a code owner January 20, 2024 21:40
@github-actions
Copy link
Copy Markdown

Please do not open pull requests from the master branch, create a new branch instead.

@github-actions github-actions Bot closed this Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant