Add PlayerFlightChangeEvent#90
Conversation
LlmDl
left a comment
There was a problem hiding this comment.
The event class should be moved into a event package in case more events are added later.
The Bukkit.getServer().getPluginManager().callEvent(new PlayerFlightChangeEvent(player, true)); should be switched to BukkitTools.fireEvent(new PlayerFlightChangeEvent(player, true)); to stay in line with how Towny handles firing events and to make future changes to event firing easier.
|
The only other thing that might made sense is to make the event implement CancellableTownyEvent, so that it could be used by other plugins to stop flight in areas they don't want players flying. |
|
Would you like a new lang string for when the event is cancelled? Or just an early return in addFlight and removeFlight? |
|
If it's just early return then that should be good I think, otherwise I will revisit later. |
LlmDl
left a comment
There was a problem hiding this comment.
I think that if the silent variable is false we should probably send the player the cancelled message from the event before returning.
|
Since TownyFlight itself never cancels the event wouldn't it make sense to let the plugin cancelling the event handle messaging? |
That doesn't really make sense to me, the plugin cancelling it wouldn't know what the value of silent is and we've already got a getter/setter for the cancel message on the CancellableTownyEvent class |
| @@ -0,0 +1,34 @@ | |||
| package com.gmail.llmdlio.townyflight.events; | |||
There was a problem hiding this comment.
Use event rather than the plural
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public class PlayerFlightChangeEvent extends CancellableTownyEvent { | ||
| private static final HandlerList handlers = new HandlerList(); |
|
I forgot I'd done the silent flag a while ago and was waiting on response to the pr before pushing. I think I understand what preferred solution is now. With this implementation plugins cancelling the event can use setCancelMessage, however, they cannot modify if it should be silent or not. Let me know if I got that right, thanks! |
LlmDl
left a comment
There was a problem hiding this comment.
Found a couple more small things. Please make sure the suggestions work and test that the PR is still good.
| PlayerFlightChangeEvent event = new PlayerFlightChangeEvent(player, false); | ||
| BukkitTools.fireEvent(event); | ||
| if (event.isCancelled()) { | ||
| if (!silent) { |
There was a problem hiding this comment.
| if (!silent) { | |
| if (!silent && !event.getCancelMessage() != null && !event.getCancelMessage().isEmpty()) { | |
| BukkitTools.fireEvent(event); | ||
| if (event.isCancelled()) { | ||
| if (!silent) { | ||
| player.sendMessage(event.getCancelMessage()); |
There was a problem hiding this comment.
| player.sendMessage(event.getCancelMessage()); | |
| Message.of(event.getCancelMessage()).serious().to(player); |
| if (!silent) { | ||
| player.sendMessage(event.getCancelMessage()); |
There was a problem hiding this comment.
| if (!silent) { | |
| player.sendMessage(event.getCancelMessage()); | |
| if (!silent && !event.getCancelMessage() != null && !event.getCancelMessage().isEmpty()) { | |
| Message.of(event.getCancelMessage()).serious().to(player); | |
LlmDl
left a comment
There was a problem hiding this comment.
OK, there's just one last thing, and that is the default cancelled message.
A CancellableTownyEvent comes with a default cancel message of "Sorry, this event was cancelled." which is not really going to look great if someone cancels the flight change and doesn't set their own message.
I'd like to see two new lang strings added, one for when flight was prevented from being granted, and one for when flight is prevented from being taken. Then the PlayerFlightChangeEvent constructor can set its cancel message properly.
Adds a new event that triggers whenever a player toggles flight