Creating a Custom Material Loader
In this section, you'll learn how to define a custom material loader. This is useful if you want to dynamically generate items that aren't just simple Material.valueOf(...) items.
Goal
We will create a material loader that always returns a DIAMOND
item, regardless of the input.
Step 1: Create the Material Loader Class
Create a class that extends MaterialLoader
:
Constructor Explained
super("example-material")
: Registers this loader under the identifierexample-material
. You will use this value in thematerial:
field in YAML.
Step 2: Register the Material Loader
In your pluginโs onEnable()
method:
Step 3: Use It in a Configuration
You can now reference your custom material type like this:
Result
Every time the example-material
string is encountered in the config, a diamond item will be returned.
Last updated