๐Ÿ‡ฑ๐Ÿ‡ท
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
  • Step 1: Create the Material Loader Class
  • Constructor Explained
  • Step 2: Register the Material Loader
  • Step 3: Use It in a Configuration
  • Result
Edit on GitHub
  1. API

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:

import fr.maxlego08.menu.api.loader.MaterialLoader;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

public class ExampleMaterialLoader extends MaterialLoader {

    public ExampleMaterialLoader() {
        super("example-material");
    }

    @Override
    public ItemStack load(Player player, YamlConfiguration yamlConfiguration, String path, String materialString) {
        return new ItemStack(Material.DIAMOND);
    }
}

Constructor Explained

  • super("example-material"): Registers this loader under the identifier example-material. You will use this value in the material: field in YAML.

Step 2: Register the Material Loader

In your pluginโ€™s onEnable() method:

inventoryManager.registerMaterialLoader(new ExampleMaterialLoader());

Step 3: Use It in a Configuration

You can now reference your custom material type like this:

example-item:
  material: "example-material:hey"
  name: "&fExample Item"
  lore:
    - "&fThis is an example item"
    - "&fYou can use it to test zMenu"

Result

Every time the example-material string is encountered in the config, a diamond item will be returned.

PreviousCreating a Custom ActionNextCreating a Custom Permission System

Last updated 1 day ago