Solved [Help] EntityExplodeEvent!

Discussion in 'Plugin Development' started by XvBaseballkidvX, Nov 14, 2013.

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

    XvBaseballkidvX

    Hello everyone!

    I am having some trouble with the Entity Explode Event.

    CODE:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onCumbust(final EntityExplodeEvent event){
    4. new BukkitRunnable(){
    5. @Override
    6. public void run(){
    7. for(Block block: event.blockList()){
    8. Material mat = block.getType();
    9. Location loc = block.getLocation();
    10. loc.getBlock().setType(mat);
    11. loc.getWorld().playEffect(loc, Effect.STEP_SOUND, (mat == Material.AIR ? block.getType().getId() : mat.getId()));
    12. }
    13. }
    14. }.runTaskLater(Main.getInstance(), 2*20);
    15. }


    The problem that I am having is that the blocks won't regenerate! D:
    I did something similar with the BlockBreakEvent, and that works just fine (And by that I mean that the blocks regenerated).

    In case someone asks: Yes, I registered the event :p

    Thank you for reading!
    All help is much appreciated :)
     
  2. Offline

    adam753

    You're getting the material (mat) inside the runnable, which means you're doing it 2 seconds after the explosion rather than just before it. Outside the BukkitRunnable, you need to store all the blocks' materials in a HashMap or something similar.
     
  3. Offline

    maxben34

    That doesn't make sense, since the block list are all the blocks effected by the explosion. The block list for that explosion won't change unless another explosion occurs in those 2 seconds I think.
     
  4. Offline

    adam753

    maxben34
    The block list is the same, but they all change to air immediately after the event is fired.
     
  5. Offline

    XvBaseballkidvX

    adam753
    maxben34
    Okay, thank you both for replying so quickly! Let me test those things and I will reply shortly.

    Great! It works!
    Thank you for your answer adam753 !

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page