-
Notifications
You must be signed in to change notification settings - Fork 2
Handlers and Wrappers
With BPU there is a Handlers and Wrappers API which allows you to handle multiple plugin dependencies within one handler. By default there are handlers to handle permissions and economy.
There is a common abstract layout for all plugin wrappers and handlers.
The handler is the front side which the plugin will use. The handler handles the different plugins and the plugin can call the plugin via this handler.
The opposite of the handler is the wrapper which allows the handler to call the plugin methods. So if a plugin call a method of the handler it will call the active wrapper to call the plugin method.
By default the plugin only should use the handler. This makes it possible to add/change/remove wrappers without breaking the compatibility. The handler normally needs following things:
- The plugin manager to get plugins on their own.
- The default plugin name.
- A logger instance.
With the default plugin name it is possible to choose a plugin beside the default. For example if the server is using Essentials and iConomy which are both supported by the economy handler it is possible to select a specific one to prevent that the plugin accidentally choose the wrong.
It is possible that the specific handler adds some information.
To use the handler it needs some steps prepare everything.
At first the handler should be created. This could be easily done by calling the constructor of the requested handler.
Then the handler needs to be informed when a plugin enables or disables. With BPU 1.3 the library itself supports the listener so it only needs to be initiated. If the plugin only needs the listener to inform the handlers it is possible to call WrapperServerListener.createAndRegisterEvents(this, all handlers...);
which will create a listener object, registers the Event.Type.PLUGIN_ENABLE
and Event.Type.PLUGIN_DISABLE
and redirect the calls to the handlers. To extend the listener it is possible to extend WrapperServerListener
and add the additional needed stuff. The class WrapperServerListener
also has a static method registerEvents(Plugin, ServerListener)
which registers the plugin enable and disable event for the plugin and server listener.
After all there is only a single step needed: Initially there is a Handler.load()
call needed for all handlers after the handler was created.
Now the handler should be operational and could be used.