Search in sources :

Example 1 with PasteBuilder

use of com.sk89q.worldedit.session.PasteBuilder in project FunnyGuilds by FunnyGuilds.

the class WorldEdit6Hook method pasteSchematic.

@Override
public boolean pasteSchematic(File schematicFile, Location location, boolean withAir) {
    try {
        Object pasteLocation = vectorConstructor.newInstance(location.getX(), location.getY(), location.getZ());
        com.sk89q.worldedit.world.World pasteWorld = new BukkitWorld(location.getWorld());
        Object pasteWorldData = getWorldData.invoke(pasteWorld);
        NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(new FileInputStream(schematicFile)));
        Object reader = schematicReaderConstructor.newInstance(nbtStream);
        Object clipboard = readSchematic.invoke(reader, pasteWorldData);
        EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1);
        ClipboardHolder clipboardHolder = (ClipboardHolder) clipboardHolderConstructor.newInstance(clipboard, pasteWorldData);
        PasteBuilder builder = ((PasteBuilder) pasteConstructor.newInstance(clipboardHolder, editSession, pasteWorldData));
        builder = (PasteBuilder) pasteBuilderSetTo.invoke(builder, pasteLocation);
        builder = builder.ignoreAirBlocks(!withAir);
        Operations.completeLegacy(builder.build());
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException | MaxChangedBlocksException | IOException ex) {
        throw new RuntimeException("Could not paste schematic: " + schematicFile.getAbsolutePath(), ex);
    }
    return true;
}
Also used : ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) GZIPInputStream(java.util.zip.GZIPInputStream) PasteBuilder(com.sk89q.worldedit.session.PasteBuilder) NBTInputStream(com.sk89q.jnbt.NBTInputStream) EditSession(com.sk89q.worldedit.EditSession)

Aggregations

NBTInputStream (com.sk89q.jnbt.NBTInputStream)1 EditSession (com.sk89q.worldedit.EditSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 PasteBuilder (com.sk89q.worldedit.session.PasteBuilder)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1