-
-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(API): Mutable Location in PlayerTeleportToPlotEvent #4196
Conversation
I wonder if two events for teleport would be better. If the event is cancelled it would be good to not search for a location and possibly load chunks needlessly. Perhaps add a new "PlayerTeleportToPlotLocationChosenEvent" :D |
I may have an idea to mitigate that issue. Tbh, I'm not that big of a fan for an additional event (especially with that very java-ish name :D) |
Should be better now I'd say - usage would be now: @Subscribe
public void yeet(PlayerTeleportToPlotEvent event) {
event.setLocationTransformer(origin -> origin.add(-15, 0, 0));
} Therefore, only if the event is not cancelled, the transformer is called and no unnecessary chunk loads would be performed. Obviously, a new Location instance may be returned instead of calling methods on the origin Location |
Core/src/main/java/com/plotsquared/core/events/PlayerTeleportToPlotEvent.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. The only thing we could potentially change is to make it non-null and use UnaryOperator.identity() as default value, but I don't have a strong opinion on that.
Overview
In case of some more abstract plot layouts (e.g. floating balloons in the sky), the event now provides the ability to set the location for any teleport programmatically.
Example:
I did not deprecate the constructor nor the event dispatcher method itself. Events should not be called by end-users either way. If no location is passed, weird behavior can occur when trying to mutate the original location (which is null in case of those deprecated methods)
Submitter Checklist