EssentialsX

EssentialsX

2M Downloads

Invalid usage of event API

TPGamesNL opened this issue ยท 0 comments

commented

Information

Full output of /ess version:

> ess version
[17:59:18 INFO]: CONSOLE issued server command: /ess version
[17:59:18 INFO]: Server version: 1.16.4-R0.1-SNAPSHOT git-Paper-338 (MC: 1.16.4)
[17:59:18 INFO]: EssentialsX version: 2.18.2.0
[17:59:18 INFO]: Vault is not installed. Chat and permissions may not work.

Server startup log:

https://gist.github.com/TPGamesNL/a300684c6fcb3a46320a6a269f2c94f1

EssentialsX config:

https://gist.github.com/TPGamesNL/9ff832cf54b58d2faa6a55e2012662ad

Details

Description:

Bukkit's event API calls registered EventExecutors for the wrong (Essentials) events, due to Essentials's invalid usage of the event API.

Steps to reproduce:
Use the following code to register a listener / executor for the FlyStatusChangeEvent, not using the @EventHandler annotation:

Listener listener = new Listener() { };
EventExecutor eventExecutor = (execListener, event) -> Bukkit.broadcastMessage("Event " + event + " called");
Bukkit.getPluginManager().registerEvent(FlyStatusChangeEvent.class, listener, EventPriority.NORMAL, eventExecutor, this);

and trigger a different event with the same superclass, such as the NickChangeEvent, by using the nick command. You'll see a broadcast like Event net.ess3.api.events.NickChangeEvent@12384f27 called.

Expected behavior:

The executor shouldn't have been called for the NickChangeEvent.

Console stack trace:

-

Screenshots:

-

This problem occurs, because a lot of the events from Essentials have a common superclass, which deals with the HandlerList stuff for them. This shouldn't be done, as the HandlerList stores listeners for that event, so the listener will be called for every subclass of the common superclass. This can be fixed by giving each event its own HandlerList, and have each event class implement the methods for their HandlerList.