Add world to Entity AddTo/RemoveFrom Events#10183
Merged
Owen1212055 merged 3 commits intoJan 23, 2024
Merged
Conversation
kennytv
approved these changes
Jan 22, 2024
Member
Machine-Maker
left a comment
There was a problem hiding this comment.
Should the javadocs include a note that it might not be the same as the entity's world? or is that not worth mentioning.
Contributor
|
I think it doesn't hurt to add it. |
Contributor
Author
|
Sure, it certainly doesn't hurt to clarify things. I added a note to the javadoc in the EntityRemoveFromWorld event. Though I don't believe it's necessary to note it in the EntityAddToWorld event. While I did add a getWorld() method to the EntityAddToWorld event as a precaution, this issue mainly pertains to the EntityRemoveFromWorld event, and I can't think of a scenario where the world would differ from the entity's world when the EntityAddToWorld event is being fired. |
Owen1212055
approved these changes
Jan 23, 2024
902f313 to
512f017
Compare
lynxplay
pushed a commit
to lynxplay/paper
that referenced
this pull request
Feb 23, 2024
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.
LeonTG
pushed a commit
to LeonTG/Paper
that referenced
this pull request
May 17, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.