1.15.2 (WorldEdit) "Merging" EditSessions for //undo

Discussion in 'Spigot Plugin Development' started by AtomicZombies, Jan 14, 2020.

  1. So I am pasting many Clipboards, saving each one to a Player's LocalSession. This works fine, but to undo all the pasted Clipboards, players have to use //undo for every time I pasted the Clipboard, which is no good.

    I need some way to merge the EditSessions together so when a player runs //undo, every Clipboard is removed.

    This is how I am currently handling pasting:
    Code (Java):
        private void paste(Clipboard schematic, Player player, Location loc) {
            try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(loc.getWorld()), -1)) {
                ClipboardHolder holder = new ClipboardHolder(schematic);
                Operation operation = holder
                        .to(BlockVector3.at(x, y, z)
                        .ignoreAirBlocks(. . .)
            } catch (...) {. . .}
    If you need to see more code, see the github.
  2. Ok this might be tricky.
    First of all you cant really merge EditSessions. I think you can create one EditSession and chain multiple Operations with it.
    If you want to mess with the EditSession yourself you can take a look at the ChangeSet...
  3. I've tried chaining them before and the operations didn't work properly.
    I can try again.
  4. I tried chaining operations again with no luck.
    Can you explain ChangeSet? I see I can add block changes, but I'm not sure how to get them.