Fake explosion

Discussion in 'Plugin Development' started by BloodShura, Jan 22, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    BloodShura

    Hi!

    Yesterday, I added fake explosion to my plugin. But, today, it doesn't work anymore. I didn't changed anything!

    I tried changing this many times, but without success. The code:

    @EventHandler(event = EntityExplodeEvent.class, priority = EventPriority.HIGH)
    public void onEntityExplode(final EntityExplodeEvent e) {
    Location loc = e.getLocation();
    loc.getWorld().createExplosion(loc, 0.0F);
    e.setCancelled(true);
    }

    I tried also:

    @EventHandler(event = EntityExplodeEvent.class, priority = EventPriority.HIGH)
    public void onEntityExplode(final EntityExplodeEvent e) {
    Location loc = e.getLocation();
    loc.getWorld().createExplosion(loc, 0);
    e.setCancelled(true);
    }

    And:

    @EventHandler(event = EntityExplodeEvent.class, priority = EventPriority.HIGH)
    public void onEntityExplode(final EntityExplodeEvent e) {
    Location loc = e.getLocation();
    e.setCancelled(true);
    loc.getWorld().createExplosion(loc, 0);
    }

    It gives various errors in console (in the line of createExplosion). It shows the explosion and don't break blocks, how I want, but doesn't gives damage to players, and, gives many errors in console.

    Can someone give me a simple code of fake explosion - shows animation, and deals damage?
     
  2. Offline

    AbeJ

    Can you post the stack traces of the errors?
     
  3. Try replacing

    @EventHandler(event = Name.class, priority = EventPriority.PRIORITY)

    with

    @EventHandler(priority = EventPriority.PRIORITY)

    also don't forget to register the event in your main class.
     
  4. Offline

    BloodShura

    Nope. Don't work.
     
  5. Offline

    xpansive

    Post the errors!
     
  6. Offline

    Olof Larsson

  7. Offline

    Carts

    Post the errors! ²
     
  8. Offline

    RROD

    Remove final from: public void onEntityExplode(final EntityExplodeEvent e) {
    Also remove event.setCancelled();


    And: loc.getWorld().createExplosion(loc, 0);
    Should be: loc.getWorld().createExplosion(loc, 0f);
     
  9. Correction 0.0F

    but even I you don't add the .0F it won't make a difference.

    Keir
     
  10. Offline

    Technius

    Code:java
    1.  
    2. public void onEntityExplode(EntityExplodeEvent event)
    3. {
    4. event.blockList().clear();
    5. }
    6. [/syntax=java]
     
  11. Code:java
    1.  
    2.  
    3. So will that create explosions that do no land damage but still entity damage?
     
  12. Offline

    Technius

    Yes.
    Code:java
    1. event.blockList()
    returns a list of all the blocks that will get blown up. So by calling
    Code:java
    1. event.blockList().clear()
    we clear the list of blocks being blown up.
     
  13. Awesome! I will add this to my Plugin :D

    Keir
     
  14. Offline

    BloodShura

    Technius, thanks! õ/
     
  15. How would I do

    event.blockList().clear()

    with

    world.createExplosion(location, 3.5F);

    Basically I want to create an explosion which will do damage to players and mobs in that radius without causing block damage.

    Keir
     
  16. Offline

    Technius

    createExplosion always does block damage. Sorry. Maybe you could spawn a tnt instead.
     
  17. I had an idea from someone else to get the location of the explosion and then in the EntityExplodeEvent check if the explosion is at the same place and then do blockList().clear()

    :D

    Keir
     
Thread Status:
Not open for further replies.

Share This Page