Creating a Custom Action
In this section, you'll learn how to define a custom action that can be triggered by a button or a condition.
Goal
We want to define an action that sends a message to the player. This action can be linked to a button click or to permission success/failure.
Step 1: Create the Action Class
Create a class that extends Action:
import fr.maxlego08.menu.api.button.Button;
import fr.maxlego08.menu.api.engine.InventoryEngine;
import fr.maxlego08.menu.api.requirement.Action;
import fr.maxlego08.menu.api.utils.Placeholders;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class ExampleAction extends Action {
@Override
protected void execute(Player player, Button button, InventoryEngine inventoryEngine, Placeholders placeholders) {
player.sendMessage(Component.text("You clicked on me"));
}
}This action simply sends a message when executed.
Step 2: Create an Action Loader
The loader defines how the action is loaded and which identifier it uses in the configuration.
Step 3: Register the Action Loader
Inside your onEnable() method:
Step 4: Use It in an Inventory or Permission
Example usage in an inventory:
The action will be triggered when the button is clicked.
Result
Clicking the button will display:
Last updated