Creating a Custom Permission System
In this section, you'll learn how to implement a custom permission system using zMenu's Permissible class.
Goal
We want to define custom permission logic that determines whether a button can be interacted with. If the player has permission, a success action is executed; otherwise, a deny action is triggered.
Step 1: Create the Permissible Class
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.requirement.Permissible;
import fr.maxlego08.menu.api.utils.Placeholders;
import org.bukkit.entity.Player;
import java.util.List;
public class ExamplePermissible extends Permissible {
public ExamplePermissible(List<Action> denyActions, List<Action> successActions) {
super(denyActions, successActions);
}
@Override
public boolean hasPermission(Player player, Button button, InventoryEngine inventoryEngine, Placeholders placeholders) {
// Custom logic, always allows in this example
return true;
}
@Override
public boolean isValid() {
return true;
}
}Step 2: Create a Loader for It
Step 3: Register the Permissible Loader
Inside your plugin’s onEnable() method:
Step 4: Use It in Your Configuration
In a YAML inventory file:
Result
When the player clicks the button:
If
hasPermission(...)returns true →successactions are executed.Otherwise →
denyactions are executed.
Last updated