2018-08-12 14:03:07 +00:00
|
|
|
package com.boydti.fawe.logging.rollback;
|
|
|
|
|
|
|
|
import com.boydti.fawe.database.DBHandler;
|
|
|
|
import com.boydti.fawe.database.RollbackDatabase;
|
|
|
|
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
2020-01-07 00:09:30 +00:00
|
|
|
import com.boydti.fawe.object.changeset.SimpleChangeSetSummary;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2019-11-23 04:31:48 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2020-07-14 02:50:59 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
public class RollbackOptimizedHistory extends DiskStorageHistory {
|
|
|
|
private long time;
|
|
|
|
|
|
|
|
private int minX;
|
|
|
|
private int maxX;
|
|
|
|
private int minY;
|
|
|
|
private int maxY;
|
|
|
|
private int minZ;
|
|
|
|
private int maxZ;
|
2019-11-23 04:31:48 +00:00
|
|
|
private String command;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
public RollbackOptimizedHistory(World world, UUID uuid, int index) {
|
|
|
|
super(world, uuid, index);
|
|
|
|
this.time = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
public RollbackOptimizedHistory(World world, UUID uuid) {
|
|
|
|
super(world, uuid);
|
|
|
|
this.time = System.currentTimeMillis();
|
|
|
|
}
|
2020-03-27 02:26:11 +00:00
|
|
|
|
2019-11-23 04:31:48 +00:00
|
|
|
public RollbackOptimizedHistory(World world, UUID uuid, int index, long time, long size, CuboidRegion region, String command) {
|
|
|
|
super(world, uuid, index);
|
|
|
|
this.time = time;
|
|
|
|
this.minX = region.getMinimumX();
|
|
|
|
this.minY = region.getMinimumY();
|
|
|
|
this.minZ = region.getMinimumZ();
|
|
|
|
this.maxX = region.getMaximumX();
|
|
|
|
this.maxY = region.getMaximumY();
|
|
|
|
this.maxZ = region.getMaximumZ();
|
|
|
|
this.blockSize = (int) size;
|
|
|
|
this.command = command;
|
|
|
|
this.closed = true;
|
2020-01-06 08:36:16 +00:00
|
|
|
System.out.println("Size " + size);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 04:31:48 +00:00
|
|
|
public long getTime() {
|
|
|
|
return time;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 04:31:48 +00:00
|
|
|
@Override
|
2020-01-06 08:36:16 +00:00
|
|
|
protected SimpleChangeSetSummary summarizeShallow() {
|
|
|
|
SimpleChangeSetSummary summary = super.summarizeShallow();
|
2019-11-23 04:31:48 +00:00
|
|
|
summary.minX = this.minX;
|
|
|
|
summary.minZ = this.minZ;
|
|
|
|
summary.maxX = this.maxX;
|
|
|
|
summary.maxZ = this.maxZ;
|
|
|
|
return summary;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 04:31:48 +00:00
|
|
|
public void setCommand(String command) {
|
|
|
|
this.command = command;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 04:31:48 +00:00
|
|
|
public String getCommand() {
|
|
|
|
return command;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-23 16:19:33 +00:00
|
|
|
public void setDimensions(BlockVector3 pos1, BlockVector3 pos2) {
|
2018-08-12 14:03:07 +00:00
|
|
|
this.minX = pos1.getBlockX();
|
|
|
|
this.minY = pos1.getBlockY();
|
|
|
|
this.minZ = pos1.getBlockZ();
|
|
|
|
this.maxX = pos2.getBlockX();
|
|
|
|
this.maxY = pos2.getBlockY();
|
|
|
|
this.maxZ = pos2.getBlockZ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTime(long time) {
|
|
|
|
this.time = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-11-16 00:20:14 +00:00
|
|
|
public void close() throws IOException {
|
|
|
|
super.close();
|
|
|
|
// Save to DB
|
2020-02-18 23:06:19 +00:00
|
|
|
RollbackDatabase db = DBHandler.IMP.getDatabase(getWorld());
|
2019-11-16 00:20:14 +00:00
|
|
|
if (db != null) {
|
|
|
|
db.logEdit(this);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void add(int x, int y, int z, int combinedFrom, int combinedTo) {
|
|
|
|
super.add(x, y, z, combinedFrom, combinedTo);
|
|
|
|
if (x < minX) {
|
|
|
|
minX = x;
|
|
|
|
} else if (x > maxX) {
|
|
|
|
maxX = x;
|
|
|
|
}
|
|
|
|
if (y < minY) {
|
|
|
|
minY = y;
|
|
|
|
} else if (y > maxY) {
|
|
|
|
maxY = y;
|
|
|
|
}
|
|
|
|
if (z < minZ) {
|
|
|
|
minZ = z;
|
|
|
|
} else if (z > maxZ) {
|
|
|
|
maxZ = z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeHeader(OutputStream os, int x, int y, int z) throws IOException {
|
|
|
|
minX = x;
|
|
|
|
maxX = x;
|
|
|
|
minY = y;
|
|
|
|
maxY = y;
|
|
|
|
minZ = z;
|
|
|
|
maxZ = z;
|
|
|
|
super.writeHeader(os, x, y, z);
|
|
|
|
}
|
2019-11-23 04:31:48 +00:00
|
|
|
|
|
|
|
public BlockVector3 getMinimumPoint() {
|
|
|
|
return BlockVector3.at(minX, minY, minZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockVector3 getMaximumPoint() {
|
|
|
|
return BlockVector3.at(maxX, maxY, maxZ);
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|