Paste Schematic With WorldEdit

Discussion in 'Spigot Plugin Development' started by stanjg, May 4, 2017.

  1. Hello guys,

    I'm trying to paste a schematic using the WorldEdit API, I have no success yet.

    If someone could point me in the right direction on how to do this it would be appreciated :)

  2. You could copy your schematic to the clipboard and then use something like this.

    Code (Text):

    import org.bukkit.Bukkit;
    import com.sk89q.worldedit.EditSession;
    import com.sk89q.worldedit.Vector;
    import com.sk89q.worldedit.WorldEdit;
    import com.sk89q.worldedit.WorldEditException;
    import com.sk89q.worldedit.bukkit.WorldEditPlugin;
    import com.sk89q.worldedit.extent.Extent;
    import com.sk89q.worldedit.extent.clipboard.Clipboard;
    import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
    import com.sk89q.worldedit.function.operation.Operations;
    import com.sk89q.worldedit.regions.Region;
    import com.sk89q.worldedit.session.ClipboardHolder;

    public class RegionPaster {
        public void paste(ClipboardHolder holder, EditSession editSession, Vector origin) throws WorldEditException {

            WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
            WorldEdit w = worldEdit.getWorldEdit();
            Clipboard clipboard = holder.getClipboard();
            Extent sourceExtent = clipboard;
            Region region = clipboard.getRegion();
            Vector from = clipboard.getOrigin();
            Extent targetExtent = region.getWorld();
            Vector to = origin;
            ForwardExtentCopy copy = new ForwardExtentCopy(sourceExtent, region, from, targetExtent, to);
    Took me about 2 years to track down the root core of how worldedit does it and finally after lengthy discussions with the developers of worldedit I settled on that solution.

    There are a few other classes you can use but they are mostly all built on ForwardExtentCopy anyway.

    Checkout ScematicCommands
    #2 Stuperfied, May 4, 2017
    Last edited: May 4, 2017
    • Agree Agree x 1
  3. There is this way also which may work

    Code (Text):
        public void pasteSchematics(World world, File schematic) {
            try {
                EditSession es = new EditSession(new BukkitWorld(world), 999999999);
                CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
                cc.paste(es, new Vector(0,90,0), false);// paste the schematic arguments are EditSession, originOfTheSchematic (in Vector form,basically where you want to paste it), and noAir boolean.
            } catch (IOException | MaxChangedBlocksException | DataException e)
    Bear in mind that CuboidClipboard is depreciated which is why i went on my quest to find another more permanent solution.

    Code (Text):
    public class CuboidClipboard {
    #3 Stuperfied, May 4, 2017
    Last edited: May 4, 2017