Fix history rollback

- Fixes #959
Dieser Commit ist enthalten in:
dordsor21 2021-08-08 19:35:57 +01:00
Ursprung f06ba41f91
Commit 57f7c93033
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
3 geänderte Dateien mit 22 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -14,6 +14,7 @@ import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.operation.ChangeSetExecutor;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
@ -133,8 +134,14 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
} }
public void undo(Player player, Region[] regions) { public void undo(Player player, Region[] regions) {
try {
close();
} catch (IOException e) {
e.printStackTrace();
return;
}
EditSession session = toEditSession(player, regions); EditSession session = toEditSession(player, regions);
session.undo(session); session.setBlocks(this, ChangeSetExecutor.Type.UNDO);
deleteFiles(); deleteFiles();
} }
@ -143,12 +150,18 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
} }
public void redo(Player player, Region[] regions) { public void redo(Player player, Region[] regions) {
try {
close();
} catch (IOException e) {
e.printStackTrace();
return;
}
EditSession session = toEditSession(player, regions); EditSession session = toEditSession(player, regions);
session.redo(session); session.setBlocks(this, ChangeSetExecutor.Type.REDO);
} }
public void redo(Player player) { public void redo(Player player) {
undo(player, null); redo(player, null);
} }
public UUID getUUID() { public UUID getUUID() {

Datei anzeigen

@ -245,7 +245,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
public EditSession toEditSession(Player player, Region[] regions) { public EditSession toEditSession(Player player, Region[] regions) {
EditSessionBuilder builder = EditSessionBuilder builder =
new EditSessionBuilder(getWorld()).player(player).autoQueue(false).fastmode(false) new EditSessionBuilder(getWorld()).player(player).autoQueue(false).fastmode(false)
.checkMemory(false).changeSet(this).limitUnlimited(); .checkMemory(false).limitUnlimited();
if (regions != null) { if (regions != null) {
builder.allowedRegions(regions); builder.allowedRegions(regions);
} else { } else {

Datei anzeigen

@ -148,7 +148,11 @@ public class HistorySubCommands {
for (Supplier<RollbackOptimizedHistory> supplier : database.getEdits(other, minTime, bot, top, !restore, restore)) { for (Supplier<RollbackOptimizedHistory> supplier : database.getEdits(other, minTime, bot, top, !restore, restore)) {
count++; count++;
RollbackOptimizedHistory edit = supplier.get(); RollbackOptimizedHistory edit = supplier.get();
if (restore) {
edit.redo(player, allowedRegions);
} else {
edit.undo(player, allowedRegions); edit.undo(player, allowedRegions);
}
String path = edit.getWorld().getName() + "/" + finalOther + "-" + edit.getIndex(); String path = edit.getWorld().getName() + "/" + finalOther + "-" + edit.getIndex();
player.print(Caption.of("fawe.worldedit.rollback.rollback.element", path)); player.print(Caption.of("fawe.worldedit.rollback.rollback.element", path));
} }