How to stop certain blocks from being exploded?

Discussion in 'Plugin Development' started by tommycake50, Aug 2, 2013.

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

    tommycake50

    Ok, so i need to stop certain blocks from being broken when tnt explodes, so far this is my code.
    Code:java
    1.  
    2. @EventHandler(priority=EventPriority.HIGHEST)
    3. public void onBlockExplodeEvent(EntityExplodeEvent e){
    4. final ArrayList<Block> restoreblocks = new ArrayList<Block>();
    5. for(Block b : e.blockList()){
    6. if(b.getTypeId() == 15 || b.getTypeId() == 19){
    7. restoreblocks.add(b);
    8. }
    9. }
    10. inst.getServer().getScheduler().scheduleSyncDelayedTask(inst, new Runnable(){public void run(){
    11. for(Block b : restoreblocks){
    12. b.getLocation().getBlock().setType(b.getType());
    13. }
    14. }}, 20);
    15. }
    16.  

    Thats my code so far.
    noworks.
    halp.
    lol.
     
  2. Offline

    blablubbabc

    event.blockList returns a list of all blocks which would have been broken by the explosion. You can remove the blocks you want to stay from that list.
    Pseudocode:
    Iterator<Block> iterator = event.blockList.iterator();
    while(iterator.hasNext()) {
    int typeId = iterator.next().getTypeId();
    if (typeId == 15 || typeId == 19) iterator.remove();
    }
     
    tommycake50 likes this.
  3. Offline

    tommycake50

    thanks, i thought about doing that.
     
Thread Status:
Not open for further replies.

Share This Page