Explosion, check each block.

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

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

    Cowboys1919

    I replied to this thread here but i realized it had been marked as solved, without any real answer. I want to be able to cancel specific blocks when they explode. For example, if a block exploded on the borderline of the "safe zone" then it would explode blocks that aren't in the safe zone and prevent the ones that are in the safe zone. Hopefully it is understood what i am saying. Thanks for your help.
     
  2. Concept: EntityExplodeEvent has a list of affected blocks that you can modify, iterate through it and remove any blocks that are protected.

    Code:
        @EventHandler(priority = EventPriority.LOW)
        public void onEntityExplode(EntityExplodeEvent event) {
            List<Block> destroyed = event.blockList();
            Iterator<Block> it = destroyed.iterator();
            while (it.hasNext()) {
                Block block = it.next();
                if (blockIsProtectedSomehow(block, foobar))
                    it.remove();
            }
        }
     
  3. Offline

    Cowboys1919

    Okay, removing from that iterator doesn't actually remove the block from the list, however i cancelled the event and did more like a if (!blockIsProtectedSomehow(block)) and set it to air if it was to protected.

    Thanks!
     
  4. From my experiences, it should in fact remove it from the list and make it unaffected. In my applications, it does work fine. Are you sure it doesn't do it for you?
     
Thread Status:
Not open for further replies.

Share This Page