use of com.fastasyncworldedit.core.database.RollbackDatabase in project FastAsyncWorldEdit by IntellectualSites.
the class HistorySubCommands method importdb.
@Command(name = "import", desc = "Import history into the database" + " - The time uses s, m, h, d, y.\n" + " - Import from disk: /history import")
@CommandPermissions("fawe.rollback.import")
@Confirm
public synchronized void importdb(Actor actor) throws WorldEditException {
File folder = MainUtil.getFile(Fawe.platform().getDirectory(), Settings.settings().PATHS.HISTORY);
if (folder.exists()) {
for (File worldFolder : Objects.requireNonNull(folder.listFiles())) {
if (worldFolder != null && worldFolder.isDirectory()) {
String worldName = worldFolder.getName();
World world = FaweAPI.getWorld(worldName);
if (world != null) {
for (File userFolder : worldFolder.listFiles()) {
if (!userFolder.isDirectory()) {
continue;
}
String userUUID = userFolder.getName();
try {
UUID uuid = UUID.fromString(userUUID);
for (File historyFile : userFolder.listFiles()) {
String name = historyFile.getName();
if (!name.endsWith(".bd")) {
continue;
}
RollbackOptimizedHistory rollback = new RollbackOptimizedHistory(world, uuid, Integer.parseInt(name.substring(0, name.length() - 3)));
SimpleChangeSetSummary summary = rollback.summarize(RegionWrapper.GLOBAL(), false);
if (summary != null) {
rollback.setDimensions(BlockVector3.at(summary.minX, world.getMinY(), summary.minZ), BlockVector3.at(summary.maxX, world.getMaxY(), summary.maxZ));
rollback.setTime(historyFile.lastModified());
RollbackDatabase db = DBHandler.IMP.getDatabase(world);
db.logEdit(rollback);
actor.print(TextComponent.of("Logging: " + historyFile));
}
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
}
}
actor.print(TextComponent.of("Done import!"));
}
}
use of com.fastasyncworldedit.core.database.RollbackDatabase in project FastAsyncWorldEdit by IntellectualSites.
the class HistorySubCommands method list.
@Command(name = "list", desc = "List your history")
@CommandPermissions("worldedit.history.list")
public void list(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) {
int index = session.getHistoryIndex();
List<Supplier<? extends ChangeSet>> history = Lists.transform(session.getHistory(), (Function<ChangeSet, Supplier<ChangeSet>>) input -> () -> input);
Location origin = player.getLocation();
String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
Reference<PaginationBox> cached = player.getMeta(pageCommand);
PaginationBox pages = cached == null ? null : cached.get();
if (page == null || pages == null) {
pages = list(database, pageCommand, history, origin.toBlockPoint());
page = 1;
}
player.print(pages.create(page));
}
use of com.fastasyncworldedit.core.database.RollbackDatabase in project FastAsyncWorldEdit by IntellectualSites.
the class RollbackOptimizedHistory method close.
@Override
public void close() throws IOException {
super.close();
// Save to DB
RollbackDatabase db = DBHandler.dbHandler().getDatabase(getWorld());
if (db != null) {
db.logEdit(this);
}
}
use of com.fastasyncworldedit.core.database.RollbackDatabase in project FastAsyncWorldEdit by IntellectualSites.
the class DiskStorageHistory method delete.
@Override
public void delete() {
deleteFiles();
if (Settings.settings().HISTORY.USE_DATABASE) {
RollbackDatabase db = DBHandler.dbHandler().getDatabase(getWorld());
db.delete(uuid, index);
}
}
use of com.fastasyncworldedit.core.database.RollbackDatabase in project FastAsyncWorldEdit by IntellectualSites.
the class InspectBrush method perform.
public boolean perform(final Player player, LocalSession session, boolean rightClick) {
if (!player.hasPermission("worldedit.tool.inspect")) {
player.print(Caption.of("fawe.error.no-perm", "worldedit.tool.inspect"));
return false;
}
if (!Settings.settings().HISTORY.USE_DATABASE) {
player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with /history import )"));
return false;
}
try {
BlockVector3 target = getTarget(player, rightClick).toBlockPoint();
final int x = target.getBlockX();
final int y = target.getBlockY();
final int z = target.getBlockZ();
World world = player.getWorld();
RollbackDatabase db = DBHandler.dbHandler().getDatabase(world);
int count = 0;
for (Supplier<RollbackOptimizedHistory> supplier : db.getEdits(target, false)) {
count++;
RollbackOptimizedHistory edit = supplier.get();
Iterator<MutableFullBlockChange> iter = edit.getFullBlockIterator(null, 0, false);
while (iter.hasNext()) {
MutableFullBlockChange change = iter.next();
if (change.x != x || change.y != y || change.z != z) {
continue;
}
int from = change.from;
int to = change.to;
UUID uuid = edit.getUUID();
String name = Fawe.platform().getName(uuid);
int index = edit.getIndex();
long age = System.currentTimeMillis() - edit.getBDFile().lastModified();
String ageFormatted = MainUtil.secToTime(age / 1000);
BlockState blockFrom = BlockState.getFromOrdinal(from);
BlockState blockTo = BlockState.getFromOrdinal(to);
TranslatableComponent msg = Caption.of("fawe.worldedit.tool.tool.inspect.info", name, blockFrom, blockTo, ageFormatted);
TextComponent hover = TextComponent.of("/tool inspect", TextColor.GOLD);
String infoCmd = "//history summary " + uuid + " " + index;
msg = msg.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, hover));
msg = msg.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, infoCmd));
player.print(msg);
}
}
player.print(Caption.of("fawe.worldedit.tool.tool.inspect.info.footer", count));
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
Aggregations