[SPIGOT-6279] Ability to listen to org.bukkit.event.Event (so all events) with a Listener Created: 15/Dec/20  Updated: 16/Dec/20

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Lauriichan Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None

Version: CraftBukkit version git-Spigot-a19903d-5b74714 (MC: 1.16.4) (Implementing API version 1.16.4-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

Adding the possibility to register a Listener that listens to all Events.
For example by adding another HandlerList in the SimplePluginManager of Bukkit that is only for the abstract Event class

import org.bukkit.event.*

public class GlobalEventListener implements Listener {

  @EventHandler
  public void onEvent(Event event) {
    // Do some stuff with the event called
  }

}

This can help on certain applications that got for example a module system on their own to provide the ability to hot load certain features or remove them completely or just update them.



 Comments   
Comment by Lauriichan [ 16/Dec/20 ]

With that I could achieve something like a workaround yeah, didn't notice that method to be honest.
But you can't still subscribe to every event available out there, since you still have to specify the needed event and what I'm searching for is a Listener that I can register that reacts to every Event that is fired, currently I'm using a code generated Listeners with over 1000 lines of code which listens to all events but don't you think that this is a bit too much just for listening to all events?

And every event that I want to support, for example a third-party plugin event, would need a listener too, or with that dynamic method I would need to extract the event (which bukkit does already) lookup If I already got a listener and then register that listener if not, so that's more a workaround than a good solution in my opinion, don't you think so?

Comment by Shane Bee [ 15/Dec/20 ]

Unless there is something I am missing here, this isn't really needed.

There is this method:
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/SimplePluginManager.html#registerEvent(java.lang.Class,org.bukkit.event.Listener,org.bukkit.event.EventPriority,org.bukkit.plugin.EventExecutor,org.bukkit.plugin.Plugin,boolean)

Which allows you to dynamically handle event listeners without actually knowing the event class at the time of coding.
This is what Skript uses internally to handle events, since we clearly don't want to have to manually type out a listener for every event Skript offers.

Generated at Sat Apr 05 09:53:35 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.