Creating a Custom Loader
In this section, you'll learn how to create a custom loader for your own button types.
Goal
We will explain how a custom ButtonLoader
works by revisiting the BasicLoader
class used for the BasicButton
.
What Is a Loader?
A loader allows zMenu to load buttons from YAML configuration files dynamically. It maps a custom type:
to the logic that instantiates the corresponding button.
Step 1: Extend ButtonLoader
ButtonLoader
Here’s a breakdown of the BasicLoader
implementation:
Constructor Explained
super(plugin, "BASIC_EXAMPLE")
: This tells zMenu that this loader is responsible for buttons of typeBASIC_EXAMPLE
in your inventories.
Loading Parameters from YAML
This example reads a string from the config using:
You can extract any number of parameters and pass them to your button constructor.
Step 2: Register the Loader
You must register the loader inside your plugin’s onEnable()
method:
Once registered, any button with type: BASIC_EXAMPLE
will be loaded using your custom logic.
Last updated