Search in sources :

Example 1 with BlockArrayClipboard

use of com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard in project AreaShop by NLthijs48.

the class WorldEditHandler6 method saveRegionBlocks.

@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
    com.sk89q.worldedit.world.World world = null;
    if (regionInterface.getWorld() != null) {
        world = LocalWorldAdapter.adapt(new BukkitWorld(regionInterface.getWorld()));
    }
    if (world == null) {
        pluginInterface.getLogger().warning("Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
        return false;
    }
    EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
    // Create a clipboard
    CuboidRegion selection = new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint());
    BlockArrayClipboard clipboard = new BlockArrayClipboard(selection);
    clipboard.setOrigin(regionInterface.getRegion().getMinimumPoint());
    ForwardExtentCopy copy = new ForwardExtentCopy(editSession, new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint()), clipboard, regionInterface.getRegion().getMinimumPoint());
    try {
        Operations.completeLegacy(copy);
    } catch (MaxChangedBlocksException e) {
        pluginInterface.getLogger().warning("Exeeded the block limit while saving schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
        return false;
    }
    try (Closer closer = Closer.create()) {
        FileOutputStream fos = closer.register(new FileOutputStream(file));
        BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
        ClipboardWriter writer = closer.register(ClipboardFormat.SCHEMATIC.getWriter(bos));
        writer.write(clipboard, world.getWorldData());
    } catch (IOException e) {
        pluginInterface.getLogger().warning("An error occured while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
        pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
        return false;
    }
    return true;
}
Also used : Closer(com.sk89q.worldedit.util.io.Closer) ClipboardWriter(com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) IOException(java.io.IOException) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) FileOutputStream(java.io.FileOutputStream) EditSession(com.sk89q.worldedit.EditSession) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

EditSession (com.sk89q.worldedit.EditSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)1 ClipboardWriter (com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter)1 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Closer (com.sk89q.worldedit.util.io.Closer)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1