Skip to content

Menus, dialogs and Bedrock forms ​

Two kinds of menus, opened the same way through a MenuDispatcher:

  • InventoryMenu: a chest GUI, every version. Its items can't be taken: clicks, shift-clicks, number keys and drags into the menu are cancelled.
  • DialogMenu: Minecraft's dialog screen (1.21.6+), with text, text boxes, checkboxes, sliders and option buttons.

Bedrock players (Geyser / Floodgate) get a DialogMenu as a Bedrock form on every version, and an InventoryMenu too when it asks for it.

Inventory menus ​

java
public final class KitMenu extends InventoryMenu {
    public KitMenu() {
        super(27, "Kits");
        addButton(11, new MenuButton()
                .creator(player -> new ItemStack(Material.IRON_SWORD))
                .action(player -> player.sendMessage("Ares selected")));
        setBedrockForm(true);   // Bedrock players get a form, Java players the chest
    }
}

action(player -> ...) runs from the chest and from the Bedrock form. consumer(event -> ...) gets the InventoryClickEvent instead, for the chest only.

With setBedrockForm(true), a Bedrock player sees one button per MenuButton that has an action, in slot order, labelled with the item's name and the last line of its lore.

Register one dispatcher per plugin and open menus through it:

java
MenuDispatcher menus = new MenuDispatcher();
getServer().getPluginManager().registerEvents(new MenuListener(menus), this);

menus.openMenu(new KitMenu(), player);

Dialogs ​

java
public class SettingsDialog extends DialogMenu<Player> {
    public SettingsDialog() { super("Settings"); }

    @Override
    protected void decorate(Player player) {
        addBody("Hello " + player.getName());
        addInput(DialogInput.text("nick", "Nickname").initial(player.getName()));
        addInput(DialogInput.bool("pvp", "PvP").initial(true));
        addButton(new DialogButton<Player>().label("Save")
                .consumer(click -> click.getPlayer().sendMessage(click.getText("nick") + " " + click.getBoolean("pvp"))));
    }
}

Dialogs need 1.21.6+ on Java. Check first and fall back to a chest:

java
// a dialog where the player can see one (1.21.6+ or Bedrock), a chest GUI otherwise
Menu<Player> menu = EranoServices.dialogs().isSupported(player) ? new SettingsDialog() : new SettingsInventory();
menus.openMenu(menu, player);

EranoServices.bedrock().isBedrock(player);   // false without Geyser / Floodgate

Upgrading from 1.0.0-alpha.3 ​

Menu was renamed to InventoryMenu. The old Menu class still works, so plugins built against alpha.3 run unchanged; new code should extend InventoryMenu.

SurvivalGames is a paid plugin. EranoAPI is open source under the MIT license.