Solved FAWE API schematics pasting

Discussion in 'Spigot Plugin Development' started by a.wernon, May 6, 2020.

  1. Hi, i,ve tried to automate schematic pasting on my server (cuz default /paste method has coordinates) and firstly came up with this solution:
    Then I tried to apply WE API and found this link:
    https://matthewmiller.dev/blog/how-to-load-and-save-schematics-with-the-worldedit-api/

    So, my current implementation is:
    Code (Java):
    org.bukkit.entity.Player player = (Player) sender;
            boolean allowUndo = true;
            File file = new File("way111.schematic");
            BlockVector3 to = BlockVector3.at(0, 0, 0);
            //World world = (World) Bukkit.getServer().getWorld("world");
            World world = (World) ((Player) sender).getWorld();
            ClipboardFormat format = ClipboardFormats.findByFile(file);
            ClipboardReader reader = null;
            try {
                reader = format.getReader(new FileInputStream(file));
            } catch (IOException e) {
                e.printStackTrace();
            }
            Clipboard clipboard = null;
            try {
                clipboard = reader.read();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1)) {
                Operation operation = new ClipboardHolder(clipboard)
                        .createPaste(editSession)
                        .to(to)
                        .ignoreAirBlocks(false)
                        .build();
                Operations.complete(operation);
            }
    But it does not work and throws unhandled expections:
    org.bukkit.command.CommandException: Unhandled exception executing command 'bld' in plugin fawetest v0.0.1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[patched_1.15.2.jar:git-Paper-165]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[patched_1.15.2.jar:git-Paper-165]
    at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchCommand(CraftServer.java:752) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.PlayerConnection.handleCommand(PlayerConnection.java:1825) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1633) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:5) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:23) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.MinecraftServer.ba(MinecraftServer.java:1053) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:1046) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:1016) ~[patched_1.15.2.jar:git-Paper-165]
    at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:939) ~[patched_1.15.2.jar:git-Paper-165]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_15_R1.CraftWorld cannot be cast to com.sk89q.worldedit.world.World
    at artemwernon.fawe_t_plugin.BuildLab.onCommand(BuildLab.java:34) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[patched_1.15.2.jar:git-Paper-165]
    ... 17 more

    I have several ideas on what it can be, but have no clue, how to fix it.
    First is casting org.Bukkit.World to com.sk89q.worldedit.world.World which may be the reason of failure. Second is pathname, of schematic. I tried to paste full path, but it won't work either.
    I'll appreciate any help.
     
  2. Try getting the world with
    FaweAPI.getWorld
     
    • Like Like x 1
  3. Ur the best, it worked! Thanks for quick answer!
     
    • Friendly Friendly x 1