2021-07-23 15:48:51 +00:00
|
|
|
package com.fastasyncworldedit.core.history;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.database.DBHandler;
|
|
|
|
import com.fastasyncworldedit.core.database.RollbackDatabase;
|
2021-07-23 15:48:51 +00:00
|
|
|
import com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary;
|
2021-03-29 13:29:16 +00:00
|
|
|
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
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;
|
2021-03-29 13:29:16 +00:00
|
|
|
import org.apache.logging.log4j.Logger;
|
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 {
|
2021-03-29 13:29:16 +00:00
|
|
|
|
|
|
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
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-10-06 18:44:33 +00:00
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
public RollbackOptimizedHistory(
|
|
|
|
World world,
|
|
|
|
UUID uuid,
|
|
|
|
int index,
|
|
|
|
long time,
|
|
|
|
long size,
|
|
|
|
CuboidRegion region,
|
|
|
|
String command
|
|
|
|
) {
|
2019-11-23 04:31:48 +00:00
|
|
|
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;
|
2021-03-29 13:29:16 +00:00
|
|
|
LOGGER.debug("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);
|
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|