1.14.4 Canceling TNT explosions

Discussion in 'Spigot Plugin Development' started by DavidMa, Feb 15, 2020.

  1. Hello.
    I am trying to cancel TNT explosions, including entity damage and sound effect.
    I created a listener for EntityExplodeEvent and canceled the event. This canceled the block damage; however, there are still entity damage and sound effect.
    What would be the optimal way to cancel TNT explosions completely?
     
  2. The ExplosionPrimeEvent gets fired when stuff (Creepers, TNT, Ender Crystals, ...) tries to explode. Just cancel the event when the right conditions are met; e.g. if it's a TNT explosion.

    The EntityExplodeEvent gets fired a bit later when the entity actually explodes (and thus when it's too late).

    [edit]Woopsy, apparently copied the wrong tab's url[/edit]
     
    #2 Coww, Feb 15, 2020
    Last edited: Feb 15, 2020
    • Like Like x 2
  3. *ExplosionPrimeEvent (wrong link)
    Doesn't it mean that entity will not explode and will remain on map, like, forever? If so, it's better to cancel damage in EntityDamageEvent.
     
  4. I am pretty sure that that would not happen, as the removing of the entity is separate from the actual explosion. From my understanding the code triggering the event would be similar to (i.e. in TNT's case):
    Code (Text):
    fire ExplosionPrimeEvent with <instance of ExplosionPrimeEvent>;
    if <instance of ExplosionPrimeEvent> is not canceled:
      create explosion in world;

    remove this entity from world;
    As you can see, whether the event is canceled only affect the creation of the explosion.
     
    • Agree Agree x 1
  5. Just looked at source code, and yeah, it's *similar* to your scheme. Also I didn't pay attention that you need to cancel sound too, so, I'm sorry for disturbing you.
     
  6. You didn't. New ideas (and perspectives) are always welcome.