Solved WorldEdit create schematic

Discussion in 'Spigot Plugin Development' started by C10sp, Jan 19, 2020.

  1. Hi there! I've been sitting here for 30 minutes trying to figure out why
    Code (Text):
    format.getWriter(new FileOutputStream(schemFile)).write(clipboard);
    is null.

    Here's my code:
    Code (Text):
    public void savePreviousArea(Location loc, int counter) {
         
            World w = ConfigManager.getWorld();
            com.sk89q.worldedit.world.World weWorld = new BukkitWorld(w);
         
            Location startLoc = loc;
            startLoc.setZ((startLoc.getZ() - 4));
            startLoc.setX((startLoc.getX() - 5));

            //4 blocks back
            //5 blocks left'
         
            //Select 2
            //7 blocks forward
            //6 blocks right
            //6 blocks up
         
            WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
         
            Location s1Loc = new Location(w, (startLoc.getX() - 5), startLoc.getY(), (startLoc.getZ() + 4));
            Location s2Loc = new Location(w, (startLoc.getX() + 6), (startLoc.getY() + 6), (startLoc.getZ() - 7));
         
            CuboidRegion region = new CuboidRegion(BlockVector3.at(s1Loc.getX(), s1Loc.getY(), s1Loc.getZ()), BlockVector3.at(s2Loc.getX(), s2Loc.getY(), s2Loc.getZ()));
         
            File restoresFolder = new File(this.getDataFolder(), "restores");
            File schemFile = new File(restoresFolder, "restore" + counter + ".schem");
         
            if(!restoresFolder.exists()) {
                makeRestoreFolder(restoresFolder);
            }
         
            if(!schemFile.exists()) {
                makeRestoreFile(schemFile);
            }
         
            try {
                BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
                Extent source = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(w), 99999);
                Extent destination = source;
                ForwardExtentCopy copy = new ForwardExtentCopy(source, region, clipboard.getOrigin(), destination, BlockVector3.at(s1Loc.getX(), s1Loc.getY(), s1Loc.getZ()));
                copy.setSourceMask(new ExistingBlockMask(source));
                Operations.completeLegacy(copy);
             
                ClipboardFormat format = ClipboardFormats.findByFile(schemFile);
             
                format.getWriter(new FileOutputStream(schemFile)).write(clipboard);
             
            }catch(IOException | MaxChangedBlocksException e) {
                e.printStackTrace();
            }
         
        }
    Error:

    Code (Text):
    [18:42:06] [Server thread/ERROR]: Error occurred while enabling RandomTreasure v1.0 (Is it up to date?)
    java.lang.NullPointerException: null
            at me.caleb.RandomTreasure.Main.savePreviousArea(Main.java:198) ~[?:?]
            at me.caleb.RandomTreasure.Main.generateStructures(Main.java:94) ~[?:?]
            at me.caleb.RandomTreasure.Main.onEnable(Main.java:50) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:366) ~[?:?]
            at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:318) ~[?:?]
            at com.rylinaux.plugman.util.PluginUtil.reload(PluginUtil.java:380) ~[?:?]
            at com.rylinaux.plugman.command.ReloadCommand.execute(ReloadCommand.java:122) ~[?:?]
            at com.rylinaux.plugman.PlugManCommandHandler.onCommand(PlugManCommandHandler.java:95) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.PlayerConnection.handleCommand(PlayerConnection.java:1641) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:1481) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.TickTask.run(SourceFile:18) [spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.MinecraftServer.aX(MinecraftServer.java:909) [spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext(MinecraftServer.java:902) [spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick(MinecraftServer.java:886) [spigot.jar:git-Spigot-56f8471-6567017]
            at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:819) [spigot.jar:git-Spigot-56f8471-6567017]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]

    What i'm doing: Writing to a schematic file
     
    #1 C10sp, Jan 19, 2020
    Last edited: Jan 19, 2020
  2. Please provide your solution.
     
  3. I don't remember what the solution was, but i can link you to my GitHub and perhaps you could see what I did.