Solved BlockBreakEvent-> get Title of Chest

Discussion in 'Plugin Development' started by PizzaBote2.4, Aug 22, 2019.

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

    PizzaBote2.4

    I want to have a BlockBreakEvent in which my Block is a Chest, and I want to get the title of the chest.
    I tried adding a Chest-cast on the Block:
    Chest c = (Chest) event.getBlock().getState();
    I think this would work, but my current problem is, I don't know how to get the Title of this Chest, since in the newer versions the InventoryView was added....
    If I try to get the view of the chest with c.getView(); it wants me to cast that which won't work.
    I also tried to just get its Inventory[c.getInventory()] and then its title[c.getInventory().getTitle()], but then it forces me to cast it witch InventoryVied which also doesn't work.
    If I try to run the Plugin it just sends me tons of useless errors.

    Would be very great if someone could help me out<3
    PS: sry for the bad english
     
  2. Offline

    wand555

    Try
    Code:java
    1. if(event.getBlock().getState() instanceof Chest) {
    2. Chest chest = (Chest) event.getBlock().getState();
    3. String chestName = (chest.getCustomName() != null) ? chest.getCustomName() : "Chest";
    4. }
     
  3. Offline

    PizzaBote2.4

    It worked.
    Thank you man, struggled about two days for solution.
    Have a nice day!
     
    wand555 likes this.
Thread Status:
Not open for further replies.

Share This Page