Skip to content

Anvil Input Menu

virtualWinter edited this page Aug 30, 2025 · 2 revisions

Anvil Input Menu

The AnvilInputMenu is a specialized menu that uses an anvil interface to get text input from a player. The player can type text by renaming the input item, and the result is captured when they click the output slot.

Basic Usage

To get text input from a player, you can create an AnvilInputMenu and provide a callback to handle the submitted text.

AnvilInputMenu.create(player, "Enter your name", name -> {
    player.sendMessage("Your name is: " + name);
}).open(player);

Key Methods

  • AnvilInputMenu.create(Player player, String title, Consumer<String> inputHandler): Creates a simple anvil input menu with only an input handler.
  • AnvilInputMenu.create(Player player, String title, Consumer<String> inputHandler, Consumer<Player> cancelHandler): Creates an anvil input menu with both input and cancel handlers.
  • AnvilInputMenu.create(Player player, String title, ItemStack inputItem, Consumer<String> inputHandler): Creates an anvil input menu with a custom input item.

Example

import club.catmc.utils.menu.AnvilInputMenu;
import org.bukkit.entity.Player;

public class MenuExamples {

    public void openAnvilInputMenu(Player player) {
        AnvilInputMenu.create(
            player,
            "Enter your name",
            name -> {
                player.sendMessage("Your name is: " + name);
            },
            p -> {
                p.sendMessage("You cancelled the input.");
            }
        ).open(player);
    }
}

Clone this wiki locally