Solved How to get the itemmeta of a chest

Discussion in 'Plugin Development' started by iliasdewachter, Apr 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    iliasdewachter

    Hi all,

    So I got a chest with ItemMeta
    Code:
    ItemStack is = new ItemStack(Material.CHEST, 1);
    ItemMeta im = is.getItemMeta();
    im.setDisplayName(ChatColor.RED + "Tier " + args[0] + " chest.");
    is.setItemMeta(im);
    player.getInventory().addItem(is);
    and in my inventoryOpenEvent:
    Code:
    @EventHandler
        public void onInventoryOpenEvent(InventoryOpenEvent event){
            if (event.getInventory().getHolder() instanceof Chest){
                Chest chest = (Chest) event.getInventory().getHolder();
                //How can I get the chest's ItemMeta?
            }
        }
    But how can I get the chests itemmeta?

    Oh, I think i've figured it out ;)

    Code:
    chest.getData().toItemStack().getItemMeta();
    doesn't work :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. iliasdewachter
    Once the item is placed as a block it's no longer an item and doesn't have ItemMeta... it turns into a tile entity which holds specific data related to the block... for example, chests' tile entity hold an array of items that are stored in it and probably the title of the inventory.

    I'm not sure if renamed chests use the name in the inventory name, but if it does then you can use getInventory().getTitle() and compare that.
     
  3. Offline

    iliasdewachter

    Thanks mate, it works :)
     
Thread Status:
Not open for further replies.

Share This Page