[HELP] Cancelling Explosion Event doesn't armorstands

Discussion in 'Spigot Plugin Development' started by Gober, Jun 19, 2018.

  1. So when you cancel an explosion event.
    It doesn't cancel the damage to entities.
    It only cancels the block "destruction" event.

    Example:
    [​IMG]
    Click me if picture doesn't show up.
     
  2. Show the code pls
     
  3. Code (Java):

        @EventHandler
        public void onEntityExplode(EntityExplodeEvent evv) {
               evv.setCancelled(true);
    }
     
    As simple as that.
     
  4. Listen to when an entity gets damaged and if the cause is an explosion, cancel it.
     
  5. I need to cancel the event if there is only a specific block.

    I don't know how to get the blocks from EntityDamageEvent
     
  6. It's kind of weird that cancelling the explosion event doesn't cancel entity damage. I guess I've never noticed that before, but it seems like a bit of a bug. If you're feeling industrious, maybe look at how WorldGuard handles cancelling explosions?

    I did some testing, and to make matters worse the EntityDamageEvent fires before the EntityDamageByEntityEvent, so you can't even check for damage from the specific TNT entity.

    The best thing I can come up with is to set a flag in the explosion event, and cancel all explosion damage while that flag is set. The next time you get an explosion event that's not one you cancel, unset the flag. Seems kind of hacky but I'm not seeing a better way. I'm curious to watch this thread so please let us know if you find a non-hacky solution!
     
    • Winner Winner x 1
  7. I think I'll use that way for the moment. Thanks anyways :D!
     
    • Friendly Friendly x 1