BlockExplodeEvent?

Discussion in 'Plugin Development' started by Cowboys1919, Jul 20, 2012.

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

    Cowboys1919

    Is there a way I can check if the cause of a block breaking was from an explosion? onBlockBreak is only for play break events. I need to cancel blocks breaking from explosions.

    Now, don't direct me to another plugin because I need this to apply to some blocks within some dynamic coordinates that my plugin contains.

    Is there some kind of block.getBreakCause() kind of thing?

    Forget that, never thought entiyExplodeEvent would have to do with the blocks for some reason..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  2. Offline

    gregroberti

    You're using the EntityExplodeEvent to do what exactly? Sorry, this piqued my curiosity as this might help me solve one of my own issues in a more elegant fashion.
     
  3. Offline

    Cowboys1919

    gregroberti
    You see, i have in my config basically 4 values (2 x and y values) that define a rectangle where the players are allowed to break blocks. I want tnt to be allowed, but i want it to only be able to break the same blocks that players can. So you can use getBlockList() and iterate through, checking each blocks location.
     
  4. Offline

    gregroberti

    That's a heck of a lot better than what I was trying to do..

    Code:
    @EventHandler
    public void onExplosion (ExplosionPrimeEvent e)
    {
        if(e.getEntity() instanceof Fireball)
        {
            for(BlockFace blockFace : BlockFace.values())
            {
                Location location = e.getEntity().getLocation();
                Block block = location.getBlock();
                if (bm.isLobbyBlock(block.getRelative(blockFace)))
                    e.setCancelled(true);
            }
        }
    }
    It didn't work 100% and I'm much happier with the solution you've suggested. I don't think I realized that the EntityExplodeEvent would be called in most instances.. thought it was just meant for creepers.

    EDIT: Now that I'm thinking about this I realize that I don't really want to cancel the explosion. I'm going to try and figure out a nice and simple way to restore certain blocks after the explosion happens instead.
     
  5. entityExplodEvent has a list of blocks, for every block you remove from the list, how less there will be exploded
     
Thread Status:
Not open for further replies.

Share This Page