You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During the development process, I may encounter some Post operations that depend on whether the event is ultimately cancelled or not.
Example, After listening to EntityDamageEvent and processing it at LOW priority level, it may be cancelled later, but I still play some special effects.
Alternatively, I don't really want to recalculate certain values between two listening methods, or require some fields to pass them.
Describe the solution you'd like.
This is a very sudden idea, and I want to know if it is possible to implement it, or what is the foolishness of this idea?
Can we add a method for setting the final cancellation result callback for event listeners to the Cancellable interface? This can allow listeners whose listening level is not in MONITOR to re determine whether the event was ultimately cancelled.
So, may this feature help change this situation?
Just like this
Cancellable:
/** * A type characterizing events that may be cancelled by a plugin or the server. */publicinterfaceCancellable {
/** * Gets the cancellation state of this event. A cancelled event will not * be executed in the server, but will still pass to other plugins. * * @return true if this event is cancelled */publicbooleanisCancelled();
/** * Sets the cancellation state of this event. A cancelled event will not * be executed in the server, but will still pass to other plugins. * * @param cancel true if you wish to cancel this event */publicvoidsetCancelled(booleancancel);
/** * Register a callback to determine whether the event is ultimately cancelled. * * @param callback A callback used to receive cancel results. */publicvoidonResult(Consumer<Boolean> callback);
/** * Get the registered result callbacks. * * @return The list of registered result callbacks. */publicList<Consumer<Boolean>> getResultCallbacks();
}
I think there are some fundamental issues with this concept. I do not like introducing any way to thwart/bypass the priority system while we still have modifiable events. In your example, you are re-querying the player from the event. Imagine an event with a mutable field with a getter/setter. This would enable you to modify the event from that callback. That shouldn't be allowed. I much prefer you just have 2 listeners on different priorities.
@Machine-Maker Yes, I agree with your concerns because we can only request that cannot do so, but the request is clearly not as restrictive as the limit.
Therefore, I also agree that this change should not be implemented, at least not in the Paper API. But I also want to know if using it while adhering to immutable requirements would result in performance issues?
Sorry for the late reply, there was an issue with Github when I was replying this morning.
Is your feature request related to a problem?
During the development process, I may encounter some Post operations that depend on whether the event is ultimately cancelled or not.
Example, After listening to
EntityDamageEvent
and processing it atLOW
priority level, it may be cancelled later, but I still play some special effects.Alternatively, I don't really want to recalculate certain values between two listening methods, or require some fields to pass them.
Describe the solution you'd like.
Can we add a method for setting the final cancellation result callback for event listeners to the Cancellable interface? This can allow listeners whose listening level is not in MONITOR to re determine whether the event was ultimately cancelled.
So, may this feature help change this situation?
Just like this
Cancellable:
A simple event class:
And a example listener:
Describe alternatives you've considered.
I am currently using lightweight metadata based on
WeakHashMap
to solve the problem I am encountering.Other
No response
The text was updated successfully, but these errors were encountered: