Listen for a block break

Discussion in 'Spigot Plugin Development' started by Plochem, Oct 5, 2018.

  1. This is question is really me not wanting to type a lot lol . Is there a single event that listens to when a block is broken by any means or do I have to listen to BlockBreakEvent, BlockExplodeEvent, EntityExplodeEvent, etc?
     
    #1 Plochem, Oct 5, 2018
    Last edited: Oct 5, 2018
  2. drives_a_ford

    Moderator

    I would just use them all and see when they are and aren't called.

    Then you can use the ones that you need once you know when which one's called.
     
  3. You can listen for BlockEvent and add checking instanceof BlockBreakEvent, BlockExplodeEvent etc.

    There is no other way to listen for all block related events.
     
  4. Yeah, that works. I also would need another EventHandler for something like EntityChangeBlockEvent since it doesn't extend BlockEvent.
     
    • Agree Agree x 1
  5. could you explain exactly what you want to do?
    PS: sorry, i didn't understand. '-'
     
  6. List<blockstate> Bbreak = new Arraylist<>();

    public void blockbreak (Blockbreakevent e) {
    Bbreak.add(e.getblock().getstate());
    }

    try this i thing this work
     
  7. I just wanted to know if there is a single listener that listen when a block is broken by any means (ex: creeper explosion, tnt explosion, ender dragon, player, etc)

    That only listens to when a player breaks a block.
     
  8. He only wants block breaks. BlockPlaceEvent and others extend BlockEvent
     
  9. That's why I told to listen for BlockEvent. You cannot listen for BlockExplodeEvent while listening for BlockBreakEvent.

    While listening for BlockEvent you listen for all block events - place, break, explode, just add checking if instanceof BlockBreakEvent, BlockExplodeEvent and other you want and you're done.
     
  10. Um what. Just make a second EventHandler function
     
    • Agree Agree x 1
    • Optimistic Optimistic x 1