[WorldEdit API] Pasting a schematic?

Discussion in 'Spigot Plugin Development' started by XxFroggyKnightxX, May 21, 2018.

  1. Hello everyone. I'm currenty making a gamemode and I kinda need to paste schematics on the fly. So basically I'm in need of the API methods to do this. I've already googled and found some old Bukkit threads but when I tried it, it just simply did not do anything? There was no errors or anything, but also most of the methods being used were depricated so that's probably why. Anyways, here's what I'm currently using that does not work.

    Code (Text):

    public static void loadArea(World world, String str, Vector origin) throws DataException, IOException, MaxChangedBlocksException {
        File file = new File(str);
        EditSession es = new EditSession(new BukkitWorld(world), 999999999);
        CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
        cc.paste(es, origin, false);
    }
     
    If anyone has a better idea of going about this, please do comment.

    Thanks.
     
  2. Okay so I have that all now. When starting the server I get this

    Code (Text):

    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: com/sk89q/worldedit/world/World
     
    It's saying I don't have the WorldEdit in? Like I have it in the server, tried various other things and it still gives me this..

    My code for pasting is:

    Code (Text):


    public void pasteAsync(World world, Vector loc, String fil){
        try {
            boolean allowUndo = true;
            com.sk89q.worldedit.world.World weWorld = new BukkitWorld(world);
            EditSession editSession = ClipboardFormat.SCHEMATIC.load(new File(fil)).paste(weWorld, loc, allowUndo, true, null);
        }catch(IOException e){
            e.printStackTrace();
        }
    }
     
    I don't know what's going on, I even made it wait to initialize the plugin.
     
  3. What do you mean by "wait to initialize the plugin"? The only thing you should have done is add FastAsyncWorldEdit to the "depend" list in the plugin.yml file of your plugin. That already makes sure that your plugin loads after FAWE. The plugins exact name for the depend list is "FastAsyncWorldEdit".
     
  4. Which WorldEdit version do you use? In version 6 and later your approach is deprecated. I’ll add my solution when I’m on my pc.


    Code (Text):

    public class WorldEditUtils {
     
        private EditSessionFactory editSessionFactory;

        public WorldEditUtils(EditSessionFactory editSessionFactory) {
            this.editSessionFactory = editSessionFactory;
        }


        public void loadArea(World world, File file, Vector origin) throws DataException, IOException, MaxChangedBlocksException {
            EditSession editSession = editSessionFactory.getEditSession((com.sk89q.worldedit.world.World) new BukkitWorld(world), 999999999);
            MCEditSchematicFormat.getFormat(file).load(file).paste(editSession, origin, false);
        }
    }
     
    #5 ysl3000, May 21, 2018
    Last edited: May 21, 2018
  5. Okay yeah thanks I totally forgot about the depending. So it works now like it actually loads up and what not. But running the command to make it paste. I get this in console.
    [​IMG]
    https://gyazo.com/19e1db2f7aa392140cab32e480c4490f
    I even went to the config.ymlfor FAWE and set region-restrictions: false to false. Originally it was true, so now I have no idea what's causing it to stop the pasting...