messageMenu API

Overview

The Menu API provides a clean interface for external plugins to interact with PhantomDungeons config-driven menu system. Open menus for players, pass variables between menus, and access menu contexts seamlessly.

circle-info

All menus are defined in YAML files in the menus/ folder and loaded dynamically at runtime.

Getting Started

1

Get the API Instance

In your plugin's onEnable, grab the API instance.

import me.fergs.phantomdungeons.modules.menu.api.MenuAPI;

// Get the singleton instance
MenuAPI menuAPI = MenuAPI.get();
circle-exclamation
2

Cache for Performance

Store it in your main plugin class.

public class MyPlugin extends JavaPlugin {
    private MenuAPI menuAPI;
    
    @Override
    public void onEnable() {
        try {
            this.menuAPI = MenuAPIProvider.get();
        } catch (IllegalStateException e) {
            getLogger().warning("PhantomDungeons not loaded!");
        }
    }
}
3

Safe Null Checks

Always check availability before using.

if (menuAPI == null) {
    getLogger().warning("Menu API not available!");
    return;
}

Core Operations

Opening Menus

Open configured menus for players.

// Open a menu by ID
boolean success = menuAPI.openMenu(player, "sword-upgrade-inventory");

if (success) {
    player.sendMessage("§aMenu opened!");
} else {
    player.sendMessage("§cMenu not found!");
}

Opening Menus with Variables

Pass custom variables to menus for dynamic content.

circle-check

Closing Menus

Close a player's open menu programmatically.

Getting Active Context

Retrieve the current menu context for a player.

circle-info

Menu contexts persist throughout menu navigation and can be passed between parent and child menus.

Checking Menu Existence

Validate menu IDs before opening.

Action Chaining

Multiple actions can be executed in sequence.

Variable System

Variables are powerful for creating dynamic menus.

Variable Sources

1

Passed Variables

Variables explicitly passed via API.

2

Parent Variables

Variables inherited from parent menu.

3

PlaceholderAPI

Any PAPI placeholder (e.g., %player_name%).

4

Menu Variables

Variables set within the menu itself.

Variable Syntax

Frequently Asked Questions

chevron-rightHow do I create a new menu?hashtag

Create a new YAML file in plugins/PhantomDungeons/menus/ with your menu configuration. The file name becomes the menu ID. Reload the plugin with /dungeons reload or restart the server.

Example file: menus/my-custom-menu.yml

chevron-rightCan variables persist across multiple menu navigations?hashtag

Yes. Variables are stored in the MenuVariableContext which persists as players navigate between menus. Child menus inherit variables from their parent context.

chevron-rightHow do I debug menu issues?hashtag

Use the admin commands:

  • /dungeons menu list - Show all loaded menus

  • /dungeons menu reload [menu_id] - Reload specific menu or all menus

  • Check the console for parsing errors during startup or reload

chevron-rightCan I use PlaceholderAPI placeholders in menus?hashtag

Yes. All PlaceholderAPI placeholders work in menu configurations including titles, item names, lore, and conditions. Variables and placeholders are processed together.

chevron-rightWhat happens if a player disconnects with a menu open?hashtag

Menu contexts are session-based and automatically cleaned up when a player disconnects. No data persists beyond the session.


sack-dollarEconomy APIchevron-rightbottle-waterBoosters APIchevron-rightcodepenEnchants APIchevron-rightrectangle-terminalLevelling APIchevron-rightswordSword APIchevron-right

Last updated