Solved How do I modify a player's clipboard?

Discussion in 'Plugin Development' started by Didi1150, Dec 17, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Didi1150

    I'm currently trying to work with the WorldEdit API, however , I can't find a solution about my problem. I want to modify a player's clipboard so I can save it to a file. Now, saving isn't the problem, but the modifying of the clipboard is difficult. I'm using 6.1.4 version of the api, and the official github has updated to 7.

    Oh, I btw want to use the CuboidClipboard, because of the BlocksArrayClipboard I always get an EOFExpetion when I want to load the schematic

    Code:
    Code:
    public void loadSchem(String filename, int x, int y, int z, org.bukkit.World world)
        {
            File dataDirectory = getMainFolder();
            File file = new File(dataDirectory, filename + ".schematic"); // The schematic file
            Vector to = new Vector(x, y, z); // Where you want to paste
            World weWorld = new BukkitWorld(world);
            WorldData worldData = weWorld.getWorldData();
            CuboidClipboard clipboard;
            try
            {
                clipboard = MCEditSchematicFormat.getFormat(file).load(file);
                Extent source = clipboard;
                Extent destination = WorldEdit.getInstance().getEditSessionFactory().getEditSession(weWorld, -1);
                ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), clipboard.getOrigin(),
                        destination, to);
                copy.setSourceMask(new ExistingBlockMask(clipboard));
                Operations.completeLegacy(copy);
            } catch (IOException | WorldEditException e)
            {
                e.printStackTrace();
            }
        }
    public void save(String filename, int x1, int y1, int z1, int x2, int y2, int z2, org.bukkit.World world)
        {
            World weWorld = new BukkitWorld(world);
            WorldData worldData = weWorld.getWorldData();
            Vector pos1 = new Vector(x1, y1, z1); // First corner of your cuboid
            Vector pos2 = new Vector(x2, y2, z2); // Second corner fo your cuboid
            CuboidRegion cReg = new CuboidRegion(weWorld, pos1, pos2);
            File dataDirectory = getMainFolder();
            if(!dataDirectory.exists()) {
                dataDirectory.mkdir();
            }
            File file = new File(dataDirectory, filename + ".schematic"); // The schematic file
            try
            {
                BlockArrayClipboard clipboard = new BlockArrayClipboard(cReg);
                Extent source = WorldEdit.getInstance().getEditSessionFactory().getEditSession(weWorld, -1);
                Extent destination = clipboard;
                ForwardExtentCopy copy = new ForwardExtentCopy(source, cReg, clipboard.getOrigin(), destination, pos1);
                copy.setSourceMask(new ExistingBlockMask(source));
                Operations.completeLegacy(copy);
                ClipboardFormat.SCHEMATIC.getWriter(new FileOutputStream(file)).write(clipboard, worldData);
            } catch (IOException | MaxChangedBlocksException e1)
            {
                e1.printStackTrace();
            }
        }
    The above code is the not working code. I get an EOFException when I try to use the loadSchem Method
     
  2. Offline

    Kars

  3. Offline

    Didi1150

    Just forgot to close the writing Output stream XD
     
Thread Status:
Not open for further replies.

Share This Page