From 57f7c930338cc11cec4344eb3b6538951b1bf78d Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 8 Aug 2021 19:35:57 +0100 Subject: [PATCH] Fix history rollback - Fixes #959 --- .../core/history/DiskStorageHistory.java | 19 ++++++++++++++++--- .../history/changeset/AbstractChangeSet.java | 2 +- .../worldedit/command/HistorySubCommands.java | 6 +++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/DiskStorageHistory.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/DiskStorageHistory.java index 4a4f7eee8..f8e7381e3 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/DiskStorageHistory.java @@ -14,6 +14,7 @@ import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.function.operation.ChangeSetExecutor; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.World; @@ -133,8 +134,14 @@ public class DiskStorageHistory extends FaweStreamChangeSet { } public void undo(Player player, Region[] regions) { + try { + close(); + } catch (IOException e) { + e.printStackTrace(); + return; + } EditSession session = toEditSession(player, regions); - session.undo(session); + session.setBlocks(this, ChangeSetExecutor.Type.UNDO); deleteFiles(); } @@ -143,12 +150,18 @@ public class DiskStorageHistory extends FaweStreamChangeSet { } public void redo(Player player, Region[] regions) { + try { + close(); + } catch (IOException e) { + e.printStackTrace(); + return; + } EditSession session = toEditSession(player, regions); - session.redo(session); + session.setBlocks(this, ChangeSetExecutor.Type.REDO); } public void redo(Player player) { - undo(player, null); + redo(player, null); } public UUID getUUID() { diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java index 8519c0bfe..e7e16f5d9 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java @@ -245,7 +245,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { public EditSession toEditSession(Player player, Region[] regions) { EditSessionBuilder builder = new EditSessionBuilder(getWorld()).player(player).autoQueue(false).fastmode(false) - .checkMemory(false).changeSet(this).limitUnlimited(); + .checkMemory(false).limitUnlimited(); if (regions != null) { builder.allowedRegions(regions); } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistorySubCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistorySubCommands.java index a79688a37..0336cb627 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistorySubCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistorySubCommands.java @@ -148,7 +148,11 @@ public class HistorySubCommands { for (Supplier supplier : database.getEdits(other, minTime, bot, top, !restore, restore)) { count++; RollbackOptimizedHistory edit = supplier.get(); - edit.undo(player, allowedRegions); + if (restore) { + edit.redo(player, allowedRegions); + } else { + edit.undo(player, allowedRegions); + } String path = edit.getWorld().getName() + "/" + finalOther + "-" + edit.getIndex(); player.print(Caption.of("fawe.worldedit.rollback.rollback.element", path)); }