Regenerating Exploded Blocks

Discussion in 'Plugin Development' started by scarabcoder, Dec 9, 2013.

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

    scarabcoder

    I want to regenerate blocks damaged by explosions for a PvP plugin I'm working on. I want the blocks to start regenerating slowly after 10 seconds, and put a block back every half a second. How do I do it? Can someone give me the code for this?
     
  2. Offline

    caseif

    If you listen to the EntityExplodeEvent, you can use it to get a Set/List/something similar (I forget exactly what) of the blocks destroyed. Then, you can just loop through those blocks with a delay of (10 seconds * 20 ticks) / # blocks broken, picking a random block to replace each time. Make sure not to replace the same block twice, though.
     
  3. Offline

    Compressions

    scarabcoder An example of ShadyPotato 's explanation:
    Code:
        @EventHandler
        public void onEntityExplode(EntityExplodeEvent e) {
            final List<Block> removed = e.blockList();
            new BukkitRunnable() {
                public void run() {
                    Random random = new Random();
                    int choice = random.nextInt(removed.size());
                    Block block = removed.get(choice);
                    block.getLocation().getBlock().setType(block.getType());
                    removed.remove(block);
                }
            }.runTaskTimer(plugin, 0L, 10L);
        }
     
  4. Offline

    scarabcoder

  5. Offline

    Garris0n

    You can't save blocks, you'll have to save materials etc.
     
  6. Offline

    drtshock

    Well that's just not true. You can save blocks just like any other objects. If you only save materials then you'd also have to save a reference to its location, metadata, and anything else ;3
     
    chaseoes likes this.
  7. Offline

    Garris0n

    I'm pretty sure saving blocks for more than a few ticks doesn't end well, but feel free to test it. I've seen it referenced multiple times, however, and I remember it not working for me (I've done this before, though it was a loong time ago).
     
  8. Save the blockstate in arraylist, then slowly regen them ... if you need abit of a code tell me
     
Thread Status:
Not open for further replies.

Share This Page