Rolling back a region on request

Discussion in 'Plugin Development' started by LeoFSU, May 7, 2014.

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


    Well hello,

    I'm looking into a possible to save a region at a specific date and roll it back at a later date. I've tried using BlockState's, but saving a bigger region with it takes a lot of time. I figured out how I could save the material, location and the data (the data returned by getData()). However, that approach will not save tile entities. Another approach I looked at was disabling the auto-save, saving the chunk manually and after that unload the chunk without saving it, then loading it again. I also don't need to save the region permanently, so no storing to a file is needed. I would also prefer not to use external tools such as WorldEdit or similar.

    tl;dr: I'm looking for a way to capture the state of a region into the memory and restoring it later.


  2. Offline



    I know you said you don't want to use an external source - but is there an important reason for that? The simplest and best solution would be to use teh WorldEdit API. It's great.

    Doing so yourself, you don't only have to save TileEntities - you will also have to make sure Blocks are placed back in the right order (RedstoneWire after the stone it is on, A torch after the wall it is on, double plants in the right order, buttons after the block they are on, ...), and much more. Why reinventing the wheel?
    NathanWolf likes this.
  3. Offline


    I am making use of this (the WorldEdit API) in RegionForSale. Feel free to have a look.

    Let me just paste one of my functions...
    2. import com.sk89q.worldedit.CuboidClipboard;
    3. import com.sk89q.worldedit.EditSession;
    4. import com.sk89q.worldedit.Vector;
    5. import com.sk89q.worldedit.bukkit.BukkitWorld;
    6. import;
    7. import com.sk89q.worldedit.schematic.SchematicFormat;
    8. import;
    12. public static void saveToSchematic(TradeableRegion region) throws IOException, DataException {
    13. World world = region.getWorld();
    14. String worldName = world.getName();
    15. String regionName = region.getName();
    16. ProtectedRegion wgRegion = region.getWorldGuardRegion();
    18. Vector minimumPoint = wgRegion.getMinimumPoint();
    19. Vector maximumPoint = wgRegion.getMaximumPoint();
    21. // *snip* (uninteresting code)
    23. Vector regionSize = maximumPoint.subtract(minimumPoint).add(1, 1, 1);
    24. int regionVolume = regionSize.getBlockX() * regionSize.getBlockY() * regionSize.getBlockZ();
    26. File schematicFile = new File(SCHEMATICS_FOLDER, worldName + File.separator + regionName + ".schematic");
    27. schematicFile.getParentFile().mkdirs();
    29. SchematicFormat format = SchematicFormat.MCEDIT;
    30. CuboidClipboard clipboard = new CuboidClipboard(regionSize, minimumPoint);
    31. EditSession editSession = new EditSession(new BukkitWorld(world), regionVolume);
    32. clipboard.copy(editSession);
    33., schematicFile);
    34. }

    Maybe that helps :)
Thread Status:
Not open for further replies.

Share This Page