#getting text form an anvil

1 messages · Page 1 of 1 (latest)

placid crystal
#

im trying to create an anvil gui to get text input from the player but when the item in slot 2 is clicked by the player the meta data always returns null how do i fix this?

public static void searchMenu(Player player) {
    Inventory anvilGUI = getServer().createInventory(player, InventoryType.ANVIL, "Search Menu");
    
    ItemStack inputItem = new ItemStack(Material.PAPER);
    ItemMeta meta = inputItem.getItemMeta();
    meta.setDisplayName("Search: ");
    inputItem.setItemMeta(meta);
    anvilGUI.setItem(0, inputItem);

    player.openInventory(anvilGUI);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent event) throws NoSuchFieldException, IllegalAccessException {
    Player player = (Player) event.getWhoClicked();
    if (event.getInventory().getType() == InventoryType.ANVIL) {
        player.sendMessage("your input" + event.getCurrentItem().getItemMeta().getDisplayName());// this always returns null when the result item in the anvil is clicked
        event.setCancelled(true);
    }
}
hot bloom
#

?paste

fickle flareBOT
hot bloom