Solved How to regenerate Map

Discussion in 'Spigot Plugin Development' started by RoiEX, Jun 18, 2016.

  1. I guess many of you probably know the Smash gamemode on the Shotbow server...
    Any destroyed block will re-appear after a specific time...
    I will implement this mechanic in my own plugin too, but I'm not quite sure on how to achieve this...
    My idea was to create a list of changed blocks and randomly placing those in the world after some time.
    My problem is, that it does not seem to give a BlockChanged event or something similar.
    Would you suggest to add multiple listeners like block destroyed, block placed etc. to call the same method?
    I'm not sure if this would work like required, since I'm changing blocks using code (Block.setMaterial etc.).
    Or have you a better suggestion?
  2. Save the blocks into an ArrayList when the block gets broken, then use the collection to regenerate after time
    For example:
    Code (Text):
    public ArrayList<Block> blocksToRegen = new ArrayList<Block>();

    public void onBreak(BlockBreakEvent event) {
    From there just make a bukkit runnable or something similar to do it after some time.
    • Agree Agree x 2
  3. But what if the Block does not get broken, but changed to bedrock or something?
  4. Or you could save the Block location and the block type to a hashmap on break event and place them back using a cooldown.
  5. How could it be changed?
  6. Code (Text):
    Or when something get's placed and I want to remove this afterwards
  7. Then make 2 arraylists or hashmaps or whatever.
    blocksToRegen = Save on block break, place back afterwards.
    blocksToRemove = Save on block place, remove afterwards.
  8. We'll that's a good cuestion :p. Maybe you could save all the blocks of the map
    You could make a cuboid then and save all the blocks.. This may help you
    • Agree Agree x 1
  9. Good Idea... I'm going to store the loaded world in an Chunk Array (player.getWorld().getLoadedChunks()) and update it whenever a new chunk gets loaded..
    When the game finished, I'm going to iterate through all blocks and replace them if neccesary
    • Winner Winner x 1

  10. EDIT: For other people reading this:
    I used a Cuboid object to get a List of blocks in the world... whenever a player moves and loads a new chunk, only the new not-touched blocks get added to the block list.
    When we want to regenerate the Map, we get the current block in the world and set it to the old block

    Will probably do a tutorial on this...