Search in sources :

Example 1 with SimpleChangeSetSummary

use of com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary 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!"));
    }
}
Also used : SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) World(com.sk89q.worldedit.world.World) UUID(java.util.UUID) File(java.io.File) RollbackDatabase(com.fastasyncworldedit.core.database.RollbackDatabase) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with SimpleChangeSetSummary

use of com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary in project FastAsyncWorldEdit by IntellectualSites.

the class RollbackOptimizedHistory method summarizeShallow.

@Override
protected SimpleChangeSetSummary summarizeShallow() {
    SimpleChangeSetSummary summary = super.summarizeShallow();
    summary.minX = this.minX;
    summary.minZ = this.minZ;
    summary.maxX = this.maxX;
    summary.maxZ = this.maxZ;
    return summary;
}
Also used : SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary)

Example 3 with SimpleChangeSetSummary

use of com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary in project FastAsyncWorldEdit by IntellectualSites.

the class HistorySubCommands method distr.

@Command(name = "distr", aliases = { "distribution" }, desc = "View block distribution for an edit")
@CommandPermissions("worldedit.history.distr")
public void distr(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws ExecutionException, InterruptedException {
    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) {
        RollbackOptimizedHistory edit = database.getEdit(other, index).get();
        SimpleChangeSetSummary summary = edit.summarize(RegionWrapper.GLOBAL(), false);
        if (summary != null) {
            List<Countable<BlockState>> distr = summary.getBlockDistributionWithData();
            SelectionCommands.BlockDistributionResult distrPages = new SelectionCommands.BlockDistributionResult(distr, true, pageCommand);
            pages = new PaginationBox.MergedPaginationBox("Block Distribution", pageCommand, pages, distrPages);
            player.setMeta(pageCommand, new SoftReference<>(pages));
        }
        page = 1;
    }
    if (pages == null) {
        player.print(Caption.of("fawe.worldedit.history.distr.summary_null"));
    } else {
        player.print(pages.create(page));
    }
}
Also used : Countable(com.sk89q.worldedit.util.Countable) SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 4 with SimpleChangeSetSummary

use of com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary in project FastAsyncWorldEdit by IntellectualSites.

the class ArrayListHistory method summarize.

// FAWE start
@Override
public ChangeSetSummary summarize(Region region, boolean shallow) {
    SimpleChangeSetSummary summary = new SimpleChangeSetSummary();
    for (Change change : changes) {
        if (change instanceof BlockChange) {
            BlockChange blockChange = (BlockChange) change;
            BlockVector3 pos = blockChange.getPosition();
            summary.add(pos.getX(), pos.getZ(), blockChange.getCurrent().getOrdinal());
        }
    }
    return summary;
}
Also used : BlockChange(com.sk89q.worldedit.history.change.BlockChange) SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) Change(com.sk89q.worldedit.history.change.Change) BlockChange(com.sk89q.worldedit.history.change.BlockChange) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Aggregations

SimpleChangeSetSummary (com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary)4 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 Command (org.enginehub.piston.annotation.Command)2 RollbackDatabase (com.fastasyncworldedit.core.database.RollbackDatabase)1 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)1 BlockChange (com.sk89q.worldedit.history.change.BlockChange)1 Change (com.sk89q.worldedit.history.change.Change)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 Countable (com.sk89q.worldedit.util.Countable)1 PaginationBox (com.sk89q.worldedit.util.formatting.component.PaginationBox)1 World (com.sk89q.worldedit.world.World)1 File (java.io.File)1 UUID (java.util.UUID)1