-
Notifications
You must be signed in to change notification settings - Fork 3
Handlers
Handlers are an easy way to register a class and keep it contained in a Map where it is easily accessible. These help keep code manageable, readable and extendable.
A handler can be created by implementing the IHandler interface. This can be done as follows:
public class ExampleHandler implements IHandler {
@Override
public void load() {
// Logic when the handler is loaded
}
@Override
public void unload() {
// Logic when the handler is unloaded
}
}Handlers can be easily registered by creating a new instance of the HandlerManager class. This has all the methods necessary to store, register and unregister handlers.
The handler can be registered by executing the following code:
HandlerManager handlerManager = new HandlerManager();
handlerManager.registerHandler(new ExampleHandler());or alternatively, you can register multiple handlers parsing a String List or multiple IHandler objects to the registerHandlers(...) method.
Handlers can be easily unregistered by accessing the HandlerManager instance and executing the unregisterHandler(...) method. This can be done as follows:
handlerManager.unregisterHandler(ExampleHandler.class);You can easily retrieve a handler with the use of the HandlerManager#getHandler() method.
This can be done as follows:
handlerManager.getHandler(ExampleHandler.class);You can easily retrieve all registered handlers with the use of the HandlerManager#getHandlers() method.
This method returns Collection<IHandler>