[Solved] Detect when a block is destroyed

Discussion in 'Plugin Development' started by sargunster, Apr 2, 2012.

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

    sargunster

    I'm making a plugin that keeps a list of "FireStarter" blocks. When one of these blocks is destroyed, I want it to be removed from the list. I already have code for removing it from the list when it is destroyed by a player, but this doesn't work for other sources such as TNT. How do I detect when a block is destroyed by TNT or set to AIR by another plugin?

    Code for detecting when destroyed by player:
    Code:
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        // A block has been broken, remove it from the list.
        fireStarterLocations.remove(event.getBlock().getLocation());
    }
     
  2. Offline

    JayEffKay

    This is how you can get a list of all blocks destroyed by an explosion

    Code:
    public void onExplode(EntityExplodeEvent event) {
        List<Block> blockListCopy = new ArrayList<Block>();
        blockListCopy.addAll(event.blockList());
    }
    
    I don't know of any good method to keep track of changes that other plugins make.
     
  3. Offline

    sargunster

    Alright, thanks for the help.
     
Thread Status:
Not open for further replies.

Share This Page