I´m programming a plugin to restore a arena in a multiverse map. I have one problem: placed blocks are not disappearing, only broken blocks My code for this is: Code: @EventHandler public void onBlock(BlockBreakEvent e) { Block b = e.getBlock(); String block = b.getTypeId() + ":" + b.getData() + ":" + b.getWorld().getName() + ":" + b.getX() + ":" + b.getY() + ":" + b.getZ(); CHANGES.add(block); } @EventHandler public void onBlock(BlockPlaceEvent e) { Block b = e.getBlock(); String block = b.getTypeId() + ":" + b.getData() + ":" + b.getWorld().getName() + ":" + b.getX() + ":" + b.getY() + ":" + b.getZ(); CHANGES.add(block); } I hope you can give me good answers
@Tobirogl Try outputting what you are saving in the CHANGES list It might save the new block at blockplace
@Tobirogl You shouldn't use a string array list for this. Try a HashMap<Location, MaterialData> to save the block and it's original form. You should also save it in the config not in a variable so that if the server is reloaded/restarted it can still reset the map correctly and you don't loose your map. But if I had to do this I would clone a world/area and never touch the original map, or use a schematic.
@Tobirogl To create a hashmap, use this : Code: HashMap<Location, MaterialData> changes = new HashMap<Location, MaterialData>(); To insert a lines (each time a block is placed/broken), use : Code: changes.put(b.getLocation(), b.getState().getData()); And to restore the map : Code: for (Location b : changes) { // Loop through all the changes made during the game b.getBlock().getState().setData(changes.get(b)); // Set the block's data to it's original data stored in the hashmap } changes = new HashMap<Location, MaterialData>(); // Finally reset the hashmap to clear the old lines // OR changes.clear(); But note that if players use TNT/creeper, or if they burn things, etc. your plugin won't restore the map correctly. That's why I advise you to use schematics or map cloning even though it is more laggy (if you have separate servers for each game it will be perfectly fine, and you might want to do that without depending on bukkit to restore it while the server is stopped, it will be faster and you can also reset plugins at the same time).