1.18 1.18.1 WorldEdit causing issues

Discussion in 'Spigot Plugin Development' started by RandomTomato, Jan 9, 2022.

  1. Hey everyone!

    Within the last week I have updated my project to Maven as well as updating one of my dependencies from WorldEdit to FastAsyncWorldEdit. After doing this, parts of my schematic saving and pasting code was shown to have become deprecated since 1.17, and no longer functioned the way it used to.

    The issue occurs when using the code below to save schematics. However when trying to paste them back in, nothing occurs and no errors are posted into the console.

    I have spent the last couple of days looking at the changes in the WorldEdit API provided here: https://worldedit.enginehub.org/en/latest/api/examples/clipboard/#schematic-examples as the API usage page for FastAsyncWorldEdit recommending to still use it. However parts of the code that they show are deprecated and even with these changes the error still occurs.

    Below are parts of my pom.xml and the two functions I use to save and paste schematics
    Code (Java):
        public void pasteSchematic(File file, Location location) {
            ClipboardFormat format = ClipboardFormats.findByFile(file);
            com.sk89q.worldedit.world.World weWorld = new BukkitWorld(location.getWorld());
            try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
                Clipboard clipboard = reader.read();
                try (EditSession editSession = WorldEdit.getInstance().newEditSession(weWorld)) {
                    // new ClipboardHolder(clipboard) is deprecated?
                    Operation operation = new ClipboardHolder(clipboard).createPaste(editSession).to(BlockVector3.at(location.getX(), location.getY(), location.getZ())).ignoreAirBlocks(false).build();
                    Operations.complete(operation);
                    //editSession.flushSession(); // <-- This was deprecated and commented out as "it is automatically closed/flushed when the code exits the block"
                }
            }
            catch (Exception exception) {
                exception.printStackTrace();
            }
        }
     
        public void saveSchematic(File file, Location location, Location location2) {
            CuboidRegion region = new CuboidRegion(BlockVector3.at(location.getX(), location.getY(), location.getZ()), BlockVector3.at(location2.getX(), location2.getY(), location2.getZ()));
            BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
            com.sk89q.worldedit.world.World weWorld = new BukkitWorld(location.getWorld());
            try (EditSession editSession = WorldEdit.getInstance().newEditSession(weWorld)) {
                ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
                Operations.complete(forwardExtentCopy);
                //editSession.flushSession(); // <-- This was deprecated and commented out as "it is automatically closed/flushed when the code exits the block"
                // The part BuiltInClipboardFormat.SPONGE_SCHEMATIC is also deprecated?
                try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
                    writer.write(clipboard);
                }
            }
            catch (Exception exception) {
                exception.printStackTrace();
            }
        }
    Code (Text):
    <!-- WorldGuard Dependency -->
    <dependency>
       <groupId>com.sk89q.worldguard</groupId>
       <artifactId>worldguard-bukkit</artifactId>
       <version>7.0.7-SNAPSHOT</version>
       <scope>provided</scope>
       <exclusions>
          <exclusion>
             <groupId>com.sk89q.worldedit</groupId>
             <artifactId>worldedit-core</artifactId>
          </exclusion>
       </exclusions>
    </dependency>
    <!-- FastAsyncWorldEdit Dependency -->
    <dependency>
       <groupId>com.fastasyncworldedit</groupId>
       <artifactId>FastAsyncWorldEdit-Core</artifactId>
       <version>2.0.0-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>

    Any help would be much appreciated and thank you in advance for your time

    ~RandomTomato