Skip to content

Add PlayerFlightChangeEvent#90

Open
KermX wants to merge 7 commits into
TownyAdvanced:masterfrom
KermX:master
Open

Add PlayerFlightChangeEvent#90
KermX wants to merge 7 commits into
TownyAdvanced:masterfrom
KermX:master

Conversation

@KermX

@KermX KermX commented Mar 6, 2025

Copy link
Copy Markdown

Adds a new event that triggers whenever a player toggles flight

@LlmDl LlmDl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@KermX KermX requested a review from LlmDl March 6, 2025 13:55
@LlmDl

LlmDl commented Mar 6, 2025

Copy link
Copy Markdown
Member

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.

@KermX

KermX commented Mar 6, 2025

Copy link
Copy Markdown
Author

Would you like a new lang string for when the event is cancelled? Or just an early return in addFlight and removeFlight?

@KermX

KermX commented Mar 6, 2025

Copy link
Copy Markdown
Author

If it's just early return then that should be good I think, otherwise I will revisit later.

@LlmDl LlmDl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if the silent variable is false we should probably send the player the cancelled message from the event before returning.

@KermX

KermX commented Mar 9, 2025

Copy link
Copy Markdown
Author

Since TownyFlight itself never cancels the event wouldn't it make sense to let the plugin cancelling the event handle messaging?

@Warriorrrr

Copy link
Copy Markdown
Member

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use event rather than the plural

import org.jetbrains.annotations.NotNull;

public class PlayerFlightChangeEvent extends CancellableTownyEvent {
private static final HandlerList handlers = new HandlerList();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HANDLER_LIST

@KermX

KermX commented Mar 27, 2025

Copy link
Copy Markdown
Author

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 LlmDl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!silent) {
if (!silent && !event.getCancelMessage() != null && !event.getCancelMessage().isEmpty()) {

BukkitTools.fireEvent(event);
if (event.isCancelled()) {
if (!silent) {
player.sendMessage(event.getCancelMessage());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
player.sendMessage(event.getCancelMessage());
Message.of(event.getCancelMessage()).serious().to(player);

Comment on lines +222 to +223
if (!silent) {
player.sendMessage(event.getCancelMessage());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!silent) {
player.sendMessage(event.getCancelMessage());
if (!silent && !event.getCancelMessage() != null && !event.getCancelMessage().isEmpty()) {
Message.of(event.getCancelMessage()).serious().to(player);

@LlmDl LlmDl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

3 participants