🇱🇷
zMenu
Marketplace
English
English
  • 🍾Getting started
  • 🔌Installing zMenu
  • ➕Supported Plugins
  • 👍zMenu+
  • ⛰️Configurations
    • ℹ️Informations
    • 📜Commands and Permissions
    • 🪧PlaceHolder
    • How to create an inventory step by step
    • 👨‍💻Inventories
    • ⏹️Buttons
    • 🏁Requirements
    • ☢️Actions
    • 🪁Items
    • Global Placeholders
    • 🔋Patterns
    • Commands
    • 🛝Player data
    • 🦬Config.json
  • API
    • ℹ️Getting Started with zMenu API
    • Creating a Basic Button
    • Creating a Pagination Button
    • Creating a Custom Loader
    • Creating a Custom Action
    • Creating a Custom Material Loader
    • Creating a Custom Permission System
    • Creating and Using Inventory Files
  • Plugin Initialization and Registration
  • 🗃️Plugin's files
  • Update to new API
Powered by GitBook
On this page
  • Goal
  • What Is a Loader?
  • Step 1: Extend ButtonLoader
  • Constructor Explained
  • Loading Parameters from YAML
  • Step 2: Register the Loader
Edit on GitHub
  1. API

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

Here’s a breakdown of the BasicLoader implementation:

import fr.maxlego08.example.buttons.BasicButton;
import fr.maxlego08.menu.api.button.Button;
import fr.maxlego08.menu.api.button.DefaultButtonValue;
import fr.maxlego08.menu.api.loader.ButtonLoader;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;

public class BasicLoader extends ButtonLoader {

    public BasicLoader(Plugin plugin) {
        super(plugin, "BASIC_EXAMPLE");
    }

    @Override
    public Button load(YamlConfiguration configuration, String path, DefaultButtonValue defaultButtonValue) {
        String key = configuration.getString(path + "key-example", "default key");
        return new BasicButton(key);
    }
}

Constructor Explained

  • super(plugin, "BASIC_EXAMPLE"): This tells zMenu that this loader is responsible for buttons of type BASIC_EXAMPLE in your inventories.

Loading Parameters from YAML

This example reads a string from the config using:

String key = configuration.getString(path + "key-example", "default key");

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:

buttonManager.register(new BasicLoader(this));

Once registered, any button with type: BASIC_EXAMPLE will be loaded using your custom logic.

PreviousCreating a Pagination ButtonNextCreating a Custom Action

Last updated 1 day ago