Rollback changes
This commit is contained in:
parent
c98d07039d
commit
514b28caa4
@ -67,7 +67,6 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
import javax.management.InstanceAlreadyExistsException;
|
||||
import javax.management.Notification;
|
||||
import javax.management.NotificationEmitter;
|
||||
|
@ -92,9 +92,11 @@ public enum BBC {
|
||||
BRUSH_SMOOTH("Smooth brush equipped (%s0 x %s1 using %s2).", "WorldEdit.Brush"),
|
||||
BRUSH_SPHERE("Sphere brush shape equipped (%s0).", "WorldEdit.Brush"),
|
||||
|
||||
ROLLBACK_ELEMENT("Undoing %s0", "WorldEdit.Rollback"),
|
||||
|
||||
TOOL_INSPECT("Inspect tool bound to %s0.", "WorldEdit.Tool"),
|
||||
TOOL_INSPECT_INFO("&7%s0 changed %s1 to %s2 %s3 ago","Info"),
|
||||
TOOL_INSPECT_INFO_FOOTER("&6Total: &7%s0 changes","Info"),
|
||||
TOOL_INSPECT_INFO("&7%s0 changed %s1 to %s2 %s3 ago","WorldEdit.Tool"),
|
||||
TOOL_INSPECT_INFO_FOOTER("&6Total: &7%s0 changes","WorldEdit.Tool"),
|
||||
TOOL_NONE("Tool unbound from your current item.", "WorldEdit.Tool"),
|
||||
TOOL_INFO("Info tool bound to %s0.", "WorldEdit.Tool"),
|
||||
TOOL_TREE("Tree tool bound to %s0.", "WorldEdit.Tool"),
|
||||
|
@ -33,6 +33,7 @@ public class RollbackDatabase {
|
||||
// private String GET_EDITS_POINT;
|
||||
private String GET_EDITS;
|
||||
private String GET_EDITS_USER;
|
||||
private String DELETE_EDITS_USER;
|
||||
private String PURGE;
|
||||
|
||||
private ConcurrentLinkedQueue<RollbackOptimizedHistory> historyChanges = new ConcurrentLinkedQueue<>();
|
||||
@ -47,8 +48,9 @@ public class RollbackDatabase {
|
||||
INSERT_EDIT = "INSERT INTO `" + prefix + "edits` (`player`,`id`,`x1`,`y1`,`z1`,`x2`,`y2`,`z2`,`time`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
PURGE = "DELETE FROM `" + prefix + "edits` WHERE `time`<?";
|
||||
// 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`>?";
|
||||
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`=?";
|
||||
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";
|
||||
DELETE_EDITS_USER = "DELETE FROM `" + prefix + "edits` WHERE `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=? AND `time`>? AND `player`=?";
|
||||
init();
|
||||
purge((int) TimeUnit.DAYS.toMillis(Settings.HISTORY.DELETE_AFTER_DAYS));
|
||||
TaskManager.IMP.async(new Runnable() {
|
||||
@ -103,7 +105,7 @@ public class RollbackDatabase {
|
||||
});
|
||||
}
|
||||
|
||||
public void getPotentialEdits(final UUID uuid, final long minTime, final Vector pos1, final Vector pos2, final RunnableVal<DiskStorageHistory> onEach, final Runnable whenDone) {
|
||||
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 World world = FaweAPI.getWorld(this.world);
|
||||
addTask(new Runnable() {
|
||||
@Override
|
||||
@ -140,6 +142,21 @@ public class RollbackDatabase {
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (delete && uuid != null) {
|
||||
try (PreparedStatement stmt = connection.prepareStatement(DELETE_EDITS_USER)) {
|
||||
stmt.setInt(1, pos1.getBlockX());
|
||||
stmt.setInt(2, pos2.getBlockX());
|
||||
stmt.setByte(3, (byte) (pos1.getBlockY() - 128));
|
||||
stmt.setByte(4, (byte) (pos2.getBlockY() - 128));
|
||||
stmt.setInt(5, pos1.getBlockZ());
|
||||
stmt.setInt(6, pos2.getBlockZ());
|
||||
stmt.setInt(7, (int) (minTime / 1000));
|
||||
byte[] uuidBytes = ByteBuffer.allocate(16).putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits()).array();
|
||||
stmt.setBytes(8, uuidBytes);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool {
|
||||
public void run() {
|
||||
BBC.TOOL_INSPECT_INFO_FOOTER.send(fp, count);
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,8 @@ import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.database.DBHandler;
|
||||
import com.boydti.fawe.database.RollbackDatabase;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
@ -37,6 +39,7 @@ import com.sk89q.worldedit.WorldVector;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -66,7 +69,7 @@ public class HistoryCommands {
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions("worldedit.history.undo")
|
||||
public void faweRollback(Player player, LocalSession session, String user, int radius, String time) throws WorldEditException {
|
||||
public void faweRollback(final Player player, LocalSession session, final String user, int radius, String time) throws WorldEditException {
|
||||
if (!Settings.HISTORY.USE_DATABASE) {
|
||||
BBC.SETTING_DISABLE.send(player, "history.use-database");
|
||||
return;
|
||||
@ -87,10 +90,24 @@ public class HistoryCommands {
|
||||
Vector bot = origin.subtract(radius, radius, radius);
|
||||
Vector top = origin.add(radius, radius, radius);
|
||||
RollbackDatabase database = DBHandler.IMP.getDatabase(Fawe.imp().getWorldName(world));
|
||||
|
||||
|
||||
|
||||
// TODO
|
||||
final AtomicInteger count = new AtomicInteger();
|
||||
System.out.println("ROLLING BACK");
|
||||
database.getPotentialEdits(other, System.currentTimeMillis() - timeDiff, bot, top, new RunnableVal<DiskStorageHistory>() {
|
||||
@Override
|
||||
public void run(DiskStorageHistory edit) {
|
||||
EditSession session = edit.toEditSession(null);
|
||||
session.undo(session);
|
||||
edit.deleteFiles();
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
Loading…
Reference in New Issue
Block a user