Solved Which Event is triggered on world.createExplosion() ?

Discussion in 'Plugin Development' started by pizzafreak08, Nov 8, 2012.

Thread Status:
Not open for further replies.
  1. Hey,

    i want to have a small ExplosiveArrow plugin. The Explosion works now. But is there a way to catch the Event which is triggered upon world.createExplosion ? I don't want BlockDrops to appear. Or do i have to use like a BlockDestroyEvent and get the cause or something?

    Thanks
    pizza
     
  2. Offline

    hutattedonmyarm

  3. yeah i tested that one but i got some weird null pointer exceptions when i checked the entity like: if (event.getEntity().getType and so on. it seems that there is the event triggered but without an entity or something
     
  4. Offline

    messageofdeath

    pizzafreak08
    just a snippet from my creeper nerf plugin

    Code:java
    1. @EventHandler
    2. public void tnt(EntityExplodeEvent event) {
    3. EntityType creeper = EntityType.CREEPER;
    4. EntityType tnt = EntityType.PRIMED_TNT;
    5. EntityType fireball = EntityType.FIREBALL;
    6. EntityType type = event.getEntityType();
    7. if(event.getEntity() != null) {
    8. if(event.getEntityType() != null) {
    9. if(type == creeper || type == tnt || type == fireball) {
    10. createExplosionSound(event.getLocation());
    11. event.setCancelled(true);
    12. }
    13. }
    14. }
    15. }
     
  5. Offline

    desht

    Well, it did :) event.getEntity() will indeed be null when you cause an explosion with world.createExplosion(), because there really is no entity involved. See https://github.com/Bukkit/CraftBukk...a/org/bukkit/craftbukkit/CraftWorld.java#L445 where the NMS world.createExplosion() method is called, with a null for the entity.

    Do as messageofdeath suggested and verify that the entity is non-null before doing anything with it.
     
  6. okay i will try that :D thanks
     
Thread Status:
Not open for further replies.

Share This Page