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);
}
}