Removing specific blocks from EntityExplosionEvent

Discussion in 'Plugin Development' started by 1Rogue, Mar 12, 2014.

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

    1Rogue

    So I have a method for handling an explosion event, and will remove relevant blocks from the game's explosion list:

    Code:java
    1. @EventHandler
    2. public void onExplode(EntityExplodeEvent event) {
    3. Game g = this.gm.getGame(event.getEntity().getWorld());
    4. if (g != null) {
    5. this.plugin.debug("Block list pre-handling:\n" + event.blockList());
    6. g.handleExplosion(event.blockList());
    7. this.plugin.debug("Block list post-handling:\n" + event.blockList());
    8. }
    9. }

    Code:java
    1. public void handleExplosion(List<Block> blocks) {
    2. if (this.getStage() == GameStage.PREGAME) { // no blocks should break
    3. blocks.clear();
    4. return;
    5. }
    6. Iterator<Block> itr = blocks.iterator();
    7. nextBlock:
    8. while (itr.hasNext()) {
    9. Location loc = itr.next().getLocation();
    10. this.plugin.debug("Location of block: " + loc); // prints location
    11. Vector v = new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    12. if (this.getStage() == GameStage.PREWALL) { // no "walls" should be destroyed
    13. for (CuboidRegion wall : this.getArena().getWalls()) {
    14. if (wall.contains(v)) {
    15. this.plugin.debug("Block is wall, removing!");
    16. itr.remove();
    17. continue nextBlock;
    18. }
    19. }
    20. }
    21. for (CuboidRegion wall : this.getArena().getProtectedWalls()) { // protected blocks should never break
    22. if (wall.contains(v)) {
    23. this.plugin.debug("Block is protected, removing!");
    24. itr.remove();
    25. continue nextBlock;
    26. }
    27. }
    28. }
    29. }


    It seems that the blocks absolutely are removed from the event.blockList(), but they still end up being destroyed in-game. I would prefer not having to remove the relevant blocks manually and handle the drop percentages, so why isn't removing blocks from the destruction list working?
     
  2. Offline

    Gater12

    1Rogue
    blockList() only returns a list of blocks that would have been destroyed or have been destroyed.
     
  3. Offline

    Garris0n

    It should be modifiable via the event.

    The only thing I can even think of is some plugin is on a higher priority re-adding all the blocks somehow, which seems rather unlikely.

    Edit: I can confirm that it does work on the current CraftBukkit build.
     
  4. Offline

    1Rogue

    I managed to fix my issue. The code seemed to be correct, but I didn't think about protecting the ground underneath the things I wanted to originally protect :(
     
  5. Offline

    Garris0n

    So what exactly was wrong? Or was it blowing up blocks outside the region you were protecting?
     
  6. Offline

    1Rogue

    Precisely.
     
    Garris0n likes this.
Thread Status:
Not open for further replies.

Share This Page