Search in sources :

Example 1 with CuboidClipboard

use of com.sk89q.worldedit.CuboidClipboard in project AreaShop by NLthijs48.

the class WorldEditHandler5 method saveRegionBlocks.

@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
    boolean result = true;
    ProtectedRegion region = regionInterface.getRegion();
    // Get the origin and size of the region
    Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
    Vector size = (new Vector(region.getMaximumPoint().getBlockX(), region.getMaximumPoint().getBlockY(), region.getMaximumPoint().getBlockZ()).subtract(origin)).add(new Vector(1, 1, 1));
    EditSession editSession = new EditSession(new BukkitWorld(regionInterface.getWorld()), pluginInterface.getConfig().getInt("maximumBlocks"));
    // Save the schematic
    editSession.enableQueue();
    CuboidClipboard clipboard = new CuboidClipboard(size, origin);
    clipboard.copy(editSession);
    Exception otherException = null;
    try {
        SchematicFormat.MCEDIT.save(clipboard, file);
    } catch (DataException | IOException e) {
        otherException = e;
    }
    if (otherException != null) {
        pluginInterface.getLogger().warning("Failed to save schematic for region " + regionInterface.getName());
        pluginInterface.debugI(ExceptionUtils.getStackTrace(otherException));
        result = false;
    }
    editSession.flushQueue();
    return result;
}
Also used : DataException(com.sk89q.worldedit.data.DataException) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) CuboidClipboard(com.sk89q.worldedit.CuboidClipboard) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) EditSession(com.sk89q.worldedit.EditSession) IOException(java.io.IOException) Vector(com.sk89q.worldedit.Vector) DataException(com.sk89q.worldedit.data.DataException) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) IOException(java.io.IOException)

Example 2 with CuboidClipboard

use of com.sk89q.worldedit.CuboidClipboard in project RedProtect by FabioZumbi12.

the class WEListener method pasteWithWE.

public static void pasteWithWE(Player p, File file) {
    World world = p.getWorld();
    Location loc = p.getLocation();
    EditSession es = new EditSession(new BukkitWorld(world), 999999999);
    try {
        CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
        cc.paste(es, new com.sk89q.worldedit.Vector(loc.getX(), loc.getY(), loc.getZ()), false);
    } catch (DataException | IOException | MaxChangedBlocksException e) {
        e.printStackTrace();
    }
}
Also used : DataException(com.sk89q.worldedit.world.DataException) CuboidClipboard(com.sk89q.worldedit.CuboidClipboard) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) EditSession(com.sk89q.worldedit.EditSession) IOException(java.io.IOException) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) World(org.bukkit.World) Location(org.bukkit.Location) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 3 with CuboidClipboard

use of com.sk89q.worldedit.CuboidClipboard in project AreaShop by NLthijs48.

the class WorldEditHandler5 method restoreRegionBlocks.

@Override
public boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface) {
    boolean result = true;
    EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(regionInterface.getWorld()), pluginInterface.getConfig().getInt("maximumBlocks"));
    // Get the origin and size of the region
    Vector origin = new Vector(regionInterface.getRegion().getMinimumPoint().getBlockX(), regionInterface.getRegion().getMinimumPoint().getBlockY(), regionInterface.getRegion().getMinimumPoint().getBlockZ());
    editSession.enableQueue();
    Exception otherException = null;
    try {
        CuboidClipboard clipBoard = SchematicFormat.MCEDIT.load(file);
        if (clipBoard.getHeight() != regionInterface.getHeight() || clipBoard.getWidth() != regionInterface.getWidth() || clipBoard.getLength() != regionInterface.getDepth()) {
            pluginInterface.getLogger().warning("Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
            pluginInterface.debugI("schematic|region, x:" + clipBoard.getWidth() + "|" + regionInterface.getWidth() + ", y:" + clipBoard.getHeight() + "|" + regionInterface.getHeight() + ", z:" + clipBoard.getLength() + "|" + regionInterface.getDepth());
        }
        clipBoard.place(editSession, origin, false);
    } catch (MaxChangedBlocksException e) {
        pluginInterface.getLogger().warning("Exeeded the block limit while restoring schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
        result = false;
    } catch (DataException | IOException e) {
        otherException = e;
    }
    if (otherException != null) {
        pluginInterface.getLogger().warning("Failed to restore schematic for region " + regionInterface.getName());
        pluginInterface.debugI(ExceptionUtils.getStackTrace(otherException));
        result = false;
    }
    editSession.flushQueue();
    return result;
}
Also used : DataException(com.sk89q.worldedit.data.DataException) CuboidClipboard(com.sk89q.worldedit.CuboidClipboard) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) EditSession(com.sk89q.worldedit.EditSession) IOException(java.io.IOException) Vector(com.sk89q.worldedit.Vector) DataException(com.sk89q.worldedit.data.DataException) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) IOException(java.io.IOException) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Aggregations

CuboidClipboard (com.sk89q.worldedit.CuboidClipboard)3 EditSession (com.sk89q.worldedit.EditSession)3 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)3 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)3 IOException (java.io.IOException)3 Vector (com.sk89q.worldedit.Vector)2 DataException (com.sk89q.worldedit.data.DataException)2 DataException (com.sk89q.worldedit.world.DataException)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1