Solved FastAsyncWorldEdit Schematic API

Discussion in 'Spigot Plugin Development' started by GamerNock_, Apr 27, 2017.

Thread Status:
Not open for further replies.
  1. I was trying to figure this out a few weeks ago as well...

    From what I understood from that wiki page, you can use WorldEdit's API to paste the schematic in an Asynchronous task. When I did this it didn't paste the blocks little-by-little like you would see if you used the command, but it runs much faster.
    Code (Text):
        public static void restoreRegion(World world, ProtectedRegion region) throws DataException, IOException, MaxChangedBlocksException {
           
            EditSession es = new EditSession(new BukkitWorld(world), Integer.MAX_VALUE);
            Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
            File regionSchem = new File(Main.getInstance().getDataFolder() + File.separator + "schematics" + File.separator + region.getId() + ".schematic");
           
            Bukkit.getScheduler().runTaskAsynchronously(
                    Main.getInstance(), new Runnable() {
               
                    @Override
                    public void run() {
                       
                        try {
                            CuboidClipboard cc = CuboidClipboard.loadSchematic(regionSchem);
                            cc.paste(es, origin, false);
                            System.out.print(Main.consolePrefix + "Pasted schematic for region " + region.getId());
                        } catch (com.sk89q.worldedit.world.DataException | IOException | MaxChangedBlocksException e) {
                            System.out.print(Main.consolePrefix + "DataException while loading schematic!");
                            e.printStackTrace();
                        }      
                    }
                }
            );
        }
     
    • Friendly Friendly x 1
  2. This helped me a lot! Thank you
     
    • Like Like x 1
Thread Status:
Not open for further replies.