Invalid usage of event API
See original GitHub issueDescription
Describe the bug
Because BentoBox uses the Bukkit event API wrongly, registered listeners are called for events they didn’t sign up for.
Steps to reproduce the behavior
Register a listener for an event, such as BentoBoxReadyEvent
, not using the @EventHandler
annotation, but by registering your own EventExecutor, with this method.
This listener (/ executor) will be called for all of BentoBox’s events, not just the BentoBoxReadyEvent
that it was registered to listen to.
Example code:
Listener listener = new Listener() { };
EventExecutor eventExecutor = (execListener, event) -> Bukkit.broadcastMessage("Event " + event + " called");
Bukkit.getPluginManager().registerEvent(BentoBoxReadyEvent.class, listener, EventPriority.NORMAL, eventExecutor, this);
Expected behavior
The listener (/ executor) should only be called for the event it was registered to listen to.
Additional context (Optional)
https://gist.github.com/TPGamesNL/ee79fc4c348721925e2b4cfafb1a9ea0
Because BentoBox’s events use the abstract class BentoBoxEvent
, which contains the required HandlerList
, Bukkit sees all of BentoBox’s events as one event: BentoBoxEvent
, therefore registered listeners will be called for all of its events, not just the event it was registered to listen to.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top GitHub Comments
Handler list should be per each event, instead single global in abstract bentobox event
Yes, I’ll mark the current BentoBoxEvent as deprecated for 1.15.4 and then 1.16.0 can have the new version.