Solved How can I get chest's custom name?

Discussion in 'Plugin Development' started by Kargond, Jun 23, 2015.

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

    Kargond

    Hey! I want to allow players to open chests if it's custom name is player's name. So, how can I get chest's custom name?
     
  2. You get the inventory of the chest by casting the BlockState of the chest to the Chest class, and use the getBlockInventory() method, and then get the name of the inventory. This should work
     
  3. Offline

    Kargond

    May you please explain better? It sounds hard a bit for me.
     
  4. When you have a Block variable called b for example, you can do b.getState() to get the BlockState. You can cast that to Chest, to get the block state of a Chest. Then you can do getBlockInventory() in the Chest class, to get the Inventory. Then you can do getName() to get the name of the chest.
     
  5. Offline

    TheDevZone

    Chest.getBlockInventory().getName();
     
  6. Offline

    Kargond

    Like this?
    Code:
    Chest chest = (Chest)e.getClickedBlock().getState();
    String chestName = chest.getInventory().getName();
    
     
  7. yes, but you also need to make sure the block is a chest.
     
  8. Offline

    Kargond

    Bram, thank you. Everything works fine.
     
    Last edited: Jun 24, 2015
Thread Status:
Not open for further replies.

Share This Page