So, I'm developing a Bukkit wrapper usable for Clojure. I'm wondering if there is any way at all to listen to all events at once? I'd much rather to that than make eventhandlers for each and every event there is in the API, naturally..
Try listening to this event: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/Event.html PS, one year later: this doesn't work, but I did write an article on this subject, check it out: https://www.spigotmc.org/threads/listening-to-all-events-listing-all-events.337466/
I'd say this should work: Code (Java): @EventHandler public void onEvent(Event event){ // should be called for all events }
If I understand what you mean correctly, you could do Code (Text): @EventHandler public void onEvent(Event e) { } and then you would need to do some stuff with the handlers. I've done this before and I'll send the code when I get home.
I assume I'll need to scan packages of events and add the listener to the HandlerList after this. I'll try it out when I get home.
Ok, I just tested it out of curiosity and this is the error you get: Code (Text): org.bukkit.plugin.IllegalPluginAccessException: Unable to find handler list for event org.bukkit.event.Event. Static getHandlerList method required! The next thing I tried was using all the direct known subclasses of event. For some (for example AsyncPlayerPreLoginEvent) that works but others get the same error as above (for example BlockEvent).
Only the events that are having no children can be used by the event system. That's also the reason why you can't listen to the PlayerEvent.
That's not necessarily true. Take for example, InventoryClickEvent, which has 2 events that extend it, CraftItemEvent and InventoryCreativeEvent. The true statement would be, "You can only listen for events that contain a HandlerList field and a static #getHandlerList() method to retrieve it" Events are Bukkit-specific. They are called by patching NMS and injecting code rather than wrapping NMS. If Bukkit were not to exist, events would not exist in vanilla Minecraft
I should correct myself. If you listen to InventoryClickEvent you aren't automatically listen to CraftItemEvent or InventoryCreativeEvent.
Then something changed. In the past it didn't work. Around 1.6/1.7 I tested it with no success. Checks like inventoryClickEvent instanceof CraftItemEvent didn't work.
Code (Text): RegisteredListener registeredListener = new RegisteredListener(this, (listener, event) -> onEvent(event), EventPriority.NORMAL, MAINCLASS, false); for (HandlerList handler : HandlerList.getHandlerLists()) handler.register(registeredListener); I'll leave it up to you to figure out where to put this. (Will remove the error from the code above)
Wow, nice. That works. Now I get a feeling for how many events are being fired all the time Edit: I find it quit interesting which events get called when and in what order. For example on login: Code (Text): [23:33:08] [User Authenticator #2/INFO]: AsyncPlayerPreLoginEvent [23:33:08] [Server thread/INFO]: PlayerPreLoginEvent [23:33:08] [User Authenticator #2/INFO]: UUID of player Arvindir is 35b4cd5b-e53f-304d-8f13-0a22d8ea4bf9 [23:33:08] [Server thread/INFO]: PlayerLoginEvent [23:33:08] [Server thread/INFO]: PlayerSpawnLocationEvent [23:33:08] [Server thread/INFO]: PlayerJoinEvent [23:33:08] [Server thread/INFO]: PlayerTeleportEvent [23:33:08] [Server thread/INFO]: Arvindir[/127.0.0.1:59163] logged in with entity id 9060 at ([world]187.45244950975015, 99.0, 247.35947289219186) [23:33:08] [Server thread/INFO]: ChunkLoadEvent [23:33:08] [Server thread/INFO]: ChunkLoadEvent [23:33:08] [Server thread/INFO]: ChunkLoadEvent