In attempting to manipulate the text field in an anvil menu, I would create an inventory with Bukkit.createInventory(player, InventoryType.Anvil) which then in all return cases returns CraftInventoryCustom which can be cast to neither CraftInventoryAnvil nor AnvilInventory.