Search in sources :

Example 1 with Extent

use of com.sk89q.worldedit.extent.Extent in project FunnyGuilds by FunnyGuilds.

the class SchematicHelper method pasteSchematic.

public static boolean pasteSchematic(File schematicFile, Location location, boolean withAir) {
    try {
        Vector pasteLocation = new Vector(location.getX(), location.getY(), location.getZ());
        World pasteWorld = new BukkitWorld(location.getWorld());
        WorldData pasteWorldData = pasteWorld.getWorldData();
        Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(schematicFile)).read(pasteWorldData);
        Region pasteRegion = clipboard.getRegion();
        Extent pasteExtent = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1);
        AffineTransform transform = new AffineTransform();
        ForwardExtentCopy copy = new ForwardExtentCopy(pasteExtent, pasteRegion, clipboard.getOrigin(), pasteExtent, pasteLocation);
        if (!transform.isIdentity()) {
            copy.setTransform(transform);
        }
        if (!withAir) {
            copy.setSourceMask(new ExistingBlockMask(clipboard));
        }
        Operations.completeLegacy(copy);
        return true;
    } catch (IOException | MaxChangedBlocksException e) {
        FunnyLogger.exception(e);
        return false;
    }
}
Also used : Extent(com.sk89q.worldedit.extent.Extent) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) WorldData(com.sk89q.worldedit.world.registry.WorldData) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) FileInputStream(java.io.FileInputStream) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) Region(com.sk89q.worldedit.regions.Region) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Vector(com.sk89q.worldedit.Vector)

Aggregations

MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Vector (com.sk89q.worldedit.Vector)1 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 Extent (com.sk89q.worldedit.extent.Extent)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)1 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)1 AffineTransform (com.sk89q.worldedit.math.transform.AffineTransform)1 Region (com.sk89q.worldedit.regions.Region)1 World (com.sk89q.worldedit.world.World)1 WorldData (com.sk89q.worldedit.world.registry.WorldData)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1