A way for event handlers to see why an event was cancelled #6542
Labels
Category: API
Related to the plugin API
Opinions Wanted
Request for comments & opinions from the community
Type: Enhancement
Contributes features or other improvements to PocketMine-MP
Problem description
There's currently no way for plugins to know why an event was cancelled.
In the event of stuff like player interactions, this leads to plugins either blindly uncancelling events (which may lead to problems like spectator players being able to do stuff they aren't supposed to), or having to bake in extra checks to avoid uncancelling the event in certain conditions (e.g. checking if the player's gamemode is spectator to avoid uncancelling
PlayerInteractEvent
).Proposed solution
Two possible options have appeared so far:
Event cancellation events
This would involve removing
Cancellable->uncancel()
as per #3823.Plugins cancelling events, if they want to allow uncancelling, would dispatch events notifying other plugins of the event cancellation.
While this initially seems like a good solution, it presents a couple of problems:
Add cause info to
Cancellable
Require passing a cause parameter to
Cancellable->cancel()
. This would allow plugins to decide if they want to uncancel an event or not.This might look something like how
PlayerPreLoginEvent
's kick flag system works in PM4+ (implemented in 9f4bb44). However, in the event ofKICK_FLAG_PLUGIN
being set, there's no way to tell any more information besides this, so a more fine-grained version is probably called for.Further notes
This seems most commonly a problem for events which can be fired in a pre-cancelled state by the server itself, like
PlayerInteractEvent
. Unclear if anything more specific than a flag for "cancelled by plugin" is actually even necessary. Please discuss.The text was updated successfully, but these errors were encountered: