Skip to content

Create Listener

Eric Lam edited this page Jun 13, 2022 · 1 revision

Creating a listener is simple, create as usual as you define in the original plugin development way.

public class MyListener implements Listener{

// add event handler method

}

and register:

public class TesterRegistry implements ComponentsRegistry {


    @Override
    public void registerCommand(CommandRegistry<CommandSender> commandRegistry) {
    }

    @Override
    public void registerListeners(ListenerRegistry<Listener> listenerRegistry) {
        listenerRegistry.listeners(List.of(
                MyListener.class // MyListener implements Listener
        ));
    }
}

What are the differents?

The most significant difference is that you can use dependency injection in your listener class.

Clone this wiki locally