Explosion reversal function help

Discussion in 'Plugin Development' started by The Zombie Blarger, Jan 5, 2012.

Thread Status:
Not open for further replies.
  1. Im not so sure how to go about doing this. Im getting familiar with bukkit's api, and attempting to create an explosion reversal function.. i can grab a list of affected blocks when a creeper explodes, but what about tnt? what about createExplosion()?

    is there a list of types of explosions, and their listeners?

    And on that matter, what about signs? how would i restore their facing/text? :s

    Basically, i need to create an explosion revert function, that keeps the noise and damage, but prevents/reverts block changes. It'd be really nice to kill it after the noise/damage but im not sure if thats possible.

    Does anyone know what im trying to do? i know essentials does it, but i'd love to be able to do something like this myself. Thanks!
     
  2. Is your goal to literally revert an explosion (perhaps after some duration of time), or prevent it from happening in the first place? If your objective is the latter, this type of approach would be more of a kludge than anything else.
     
  3. Offline

    mindless728

    the easiest way might just be to cancel the explosion event and then send the client the necessary packets so that they see and hear the explosion
     
  4. well technically, i'd love to cancel the explosion, but i still need to have the players hear the explosion, see it, and take the damage.

    that sounds probably like the best way... How do i do that? :s
     
  5. Offline

    mindless728

    well you either need to construct a packet that is the same as the one that is sent to the client (look up the minecraft protocol)

    here is the part of the protocol you need to send the client: Explosion Protocol

    or you could try to find an API that does a lot of the middle ground work for you, maybe try Spout as I know they have a lot of hooks that stock bukkit doesn't have
     
  6. I remember finding a way to do this.
    Code:java
    1.  
    2. event.setCancelled(true);
    3. world.createExplosion(location, 0.0F, false);
    4. world.playEffect(loc, Effect.SMOKE, 1)
    5.  

    Cancels the explosion event, but creates the same effect with no blocks affected (hence the 0.0F, normal tnt power is 4.0F).
     
  7. very nice, thanks!
    is there any way to emulate the player damage though?
     
  8. get nearby entities from the location and damage them accordingly, perhaps.
     
  9. I'm not sure if it works, but try event.setYield(0.0F);
     
  10. Offline

    desht

    You should find that players still take explosion damage, even when the EntityExplodeEvent is cancelled. I've verified that in the past through actual testing (though I haven't checked if it still holds true in MC 1.0, I'd be surprised if it didn't).
     
  11. Yes, i found this. Thank you.


    However, actually, im getting a stack overflow error because im creating an explosion in the cancel explosion function... explosion >cancels that explosion and creates another, which triggers another cancel event, and so on and so forth.. :s

    Code:java
    1. public void onEntityExplode(EntityExplodeEvent event){
    2. Location location = event.getLocation();
    3. event.setCancelled(true);
    4. location.getWorld().createExplosion(location, 0.0F, false);
    5. location.getWorld().playEffect(location, Effect.SMOKE, 1);
    6. }


    edit: derp. the only thing i need is the smoke, isnt it .-.
     
Thread Status:
Not open for further replies.

Share This Page