diff --git a/core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java b/core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java index 7eacecb3..f29066d0 100644 --- a/core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java +++ b/core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java @@ -36,6 +36,8 @@ public class RollbackDatabase extends AsyncNotifyQueue { // private String GET_EDITS_POINT; private String GET_EDITS; private String GET_EDITS_USER; + private String GET_EDITS_ASC; + private String GET_EDITS_USER_ASC; private String DELETE_EDITS_USER; private String DELETE_EDIT_USER; private String PURGE; @@ -59,6 +61,8 @@ public class RollbackDatabase extends AsyncNotifyQueue { // GET_EDITS_POINT = "SELECT `player`,`id` FROM `" + prefix + "edits` WHERE `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=?"; GET_EDITS = "SELECT `player`,`id` FROM `" + prefix + "edits` WHERE `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=? AND `time`>? ORDER BY `time` DESC, `id` DESC"; GET_EDITS_USER = "SELECT `player`,`id` FROM `" + prefix + "edits` WHERE `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=? AND `time`>? AND `player`=? ORDER BY `time` DESC, `id` DESC"; + GET_EDITS_ASC = "SELECT `player`,`id` FROM `" + prefix + "edits` WHERE `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=? AND `time`>? ORDER BY `time` ASC, `id` ASC"; + GET_EDITS_USER_ASC = "SELECT `player`,`id` FROM `" + prefix + "edits` WHERE `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=? AND `time`>? AND `player`=? ORDER BY `time` ASC, `id` ASC"; DELETE_EDITS_USER = "DELETE FROM `" + prefix + "edits` WHERE `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=? AND `time`>? AND `player`=?"; DELETE_EDIT_USER = "DELETE FROM `" + prefix + "edits` WHERE `player`=? AND `id`=?"; init(); @@ -122,12 +126,13 @@ public class RollbackDatabase extends AsyncNotifyQueue { }); } - public void getPotentialEdits(final UUID uuid, final long minTime, final Vector pos1, final Vector pos2, final RunnableVal onEach, final Runnable whenDone, final boolean delete) { + public void getPotentialEdits(final UUID uuid, final long minTime, final Vector pos1, final Vector pos2, final RunnableVal onEach, final Runnable whenDone, final boolean delete, final boolean ascending) { final World world = FaweAPI.getWorld(this.worldName); addTask(new Runnable() { @Override public void run() { - try (PreparedStatement stmt = connection.prepareStatement(uuid == null ? GET_EDITS : GET_EDITS_USER)) { + String stmtStr = ascending ? (uuid == null ? GET_EDITS_ASC : GET_EDITS_USER_ASC) : (uuid == null ? GET_EDITS : GET_EDITS_USER); + try (PreparedStatement stmt = connection.prepareStatement(stmtStr)) { stmt.setInt(1, pos1.getBlockX()); stmt.setInt(2, pos2.getBlockX()); stmt.setByte(3, (byte) (pos1.getBlockY() - 128)); diff --git a/core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java b/core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java index e3af69fb..b2bec64c 100644 --- a/core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java +++ b/core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java @@ -105,7 +105,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool { public void run() { BBC.TOOL_INSPECT_INFO_FOOTER.send(fp, count); } - }, false); + }, false, false); return true; } diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 7a01024e..cdeb49a9 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -143,10 +143,19 @@ public class DiskStorageHistory extends FaweStreamChangeSet { deleteFiles(); } + public void redo(FawePlayer fp, Region[] regions) { + EditSession session = toEditSession(fp, regions); + session.redo(session); + } + public void undo(FawePlayer fp) { undo(fp, null); } + public void redo(FawePlayer fp) { + redo(fp, null); + } + public UUID getUUID() { return uuid; } diff --git a/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index 997a1e5d..b597b09b 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -73,21 +73,7 @@ public class HistoryCommands extends MethodCommands { max = 3 ) @CommandPermissions("worldedit.history.rollback") - public void faweRollback(final Player player, LocalSession session, final String user, @Optional("0") @Range(min = 0) int radius, @Optional("0") String time) throws WorldEditException { - - } - - @Command( - aliases = {"/frb", "frb", "fawerollback", "/fawerollback", "/rollback"}, - usage = " ", - desc = "Undo a specific edit. " + - " - The time uses s, m, h, d, y.\n" + - " - Import from disk: /frb #import", - min = 1, - max = 3 - ) - @CommandPermissions("worldedit.history.rollback") - public void faweRollback(final Player player, LocalSession session, final String user, @Optional("0") @Range(min = 0) int radius, @Optional("0") String time) throws WorldEditException { + public void faweRollback(final Player player, LocalSession session, final String user, @Optional("0") @Range(min = 0) int radius, @Optional("0") String time, @Optional("r") boolean restore) throws WorldEditException { if (!Settings.IMP.HISTORY.USE_DATABASE) { BBC.SETTING_DISABLE.send(player, "history.use-database (Import with /frb #import )"); return; @@ -152,7 +138,8 @@ public class HistoryCommands extends MethodCommands { UUID uuid = player.getUniqueId(); DiskStorageHistory file = new DiskStorageHistory(world, uuid, index); if (file.getBDFile().exists()) { - file.undo(FawePlayer.wrap(player)); + if (restore) file.redo(FawePlayer.wrap(player)); + else file.undo(FawePlayer.wrap(player)); BBC.ROLLBACK_ELEMENT.send(player, Fawe.imp().getWorldName(world) + "/" + user + "-" + index); } else { BBC.TOOL_INSPECT_INFO_FOOTER.send(player, 0); @@ -199,19 +186,18 @@ public class HistoryCommands extends MethodCommands { // finalQueue = SetQueue.IMP.getNewQueue(fp.getWorld(), true, false); // } database.getPotentialEdits(other, System.currentTimeMillis() - timeDiff, bot, top, new RunnableVal() { - @Override - public void run(DiskStorageHistory edit) { - edit.undo(fp, allowedRegions); - BBC.ROLLBACK_ELEMENT.send(player, Fawe.imp().getWorldName(edit.getWorld()) + "/" + user + "-" + edit.getIndex()); - count.incrementAndGet(); - } - }, new Runnable() { - @Override - public void run() { - BBC.TOOL_INSPECT_INFO_FOOTER.send(player, count); - } - }, true - ); + @Override + public void run(DiskStorageHistory edit) { + edit.undo(fp, allowedRegions); + BBC.ROLLBACK_ELEMENT.send(player, Fawe.imp().getWorldName(edit.getWorld()) + "/" + user + "-" + edit.getIndex()); + count.incrementAndGet(); + } + }, new Runnable() { + @Override + public void run() { + BBC.TOOL_INSPECT_INFO_FOOTER.send(player, count); + } + }, true, restore); } @Command( @@ -224,32 +210,8 @@ public class HistoryCommands extends MethodCommands { max = 3 ) @CommandPermissions("worldedit.history.rollback") - private void restore(DiskStorageHistory file) { - int times = Math.max(1, context.getInteger(0, 1)); - if (times > 50) { - FawePlayer.wrap(player).checkConfirmation(getArguments(context), times, 50); - } - for (int i = 0; i < times; ++i) { - EditSession undone; - if (context.argsLength() < 2) { - undone = session.undo(session.getBlockBag(player), player); - } else { - player.checkPermission("worldedit.history.undo.other"); - LocalSession sess = worldEdit.getSession(context.getString(1)); - if (sess == null) { - BBC.COMMAND_HISTORY_OTHER_ERROR.send(player, context.getString(1)); - break; - } - undone = sess.undo(session.getBlockBag(player), player); - } - if (undone != null) { - BBC.COMMAND_UNDO_SUCCESS.send(player); - worldEdit.flushBlockBag(player, undone); - } else { - BBC.COMMAND_UNDO_ERROR.send(player); - break; - } - } + private void restore(final Player player, LocalSession session, final String user, @Optional("0") @Range(min = 0) int radius, @Optional("0") String time) throws WorldEditException { + faweRollback(player, session, user, radius, time, true); } @Command(