Add history restore command

This commit is contained in:
Jesse Boyd 2018-08-03 11:29:34 +10:00
parent f2412bca13
commit 55a8978869
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 34 additions and 58 deletions

View File

@ -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<DiskStorageHistory> onEach, final Runnable whenDone, final boolean delete) {
public void getPotentialEdits(final UUID uuid, final long minTime, final Vector pos1, final Vector pos2, final RunnableVal<DiskStorageHistory> 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));

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 = "<user=Empire92> <radius=5> <time=3d4h>",
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);
@ -210,8 +197,7 @@ public class HistoryCommands extends MethodCommands {
public void run() {
BBC.TOOL_INSPECT_INFO_FOOTER.send(player, count);
}
}, true
);
}, 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(