Search in sources :

Example 1 with RollbackDatabase

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!"));
    }
}
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 RollbackDatabase

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));
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockVector3(com.sk89q.worldedit.math.BlockVector3) RollbackDatabase(com.fastasyncworldedit.core.database.RollbackDatabase) Player(com.sk89q.worldedit.entity.Player) World(com.sk89q.worldedit.world.World) Fawe(com.fastasyncworldedit.core.Fawe) Caption(com.fastasyncworldedit.core.configuration.Caption) Arg(org.enginehub.piston.annotation.param.Arg) Time(com.sk89q.worldedit.command.util.annotation.Time) Component(com.sk89q.worldedit.util.formatting.text.Component) AllowedRegion(com.sk89q.worldedit.command.util.annotation.AllowedRegion) CommandContainer(org.enginehub.piston.annotation.CommandContainer) Location(com.sk89q.worldedit.util.Location) Function(com.google.common.base.Function) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) Identifiable(com.sk89q.worldedit.util.Identifiable) UUID(java.util.UUID) Settings(com.fastasyncworldedit.core.configuration.Settings) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) ArgFlag(org.enginehub.piston.annotation.param.ArgFlag) Reference(java.lang.ref.Reference) Objects(java.util.Objects) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) List(java.util.List) SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) Countable(com.sk89q.worldedit.util.Countable) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) MainUtil(com.fastasyncworldedit.core.util.MainUtil) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) Switch(org.enginehub.piston.annotation.param.Switch) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) Supplier(java.util.function.Supplier) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) StringMan(com.fastasyncworldedit.core.util.StringMan) Lists(com.google.common.collect.Lists) WorldEditException(com.sk89q.worldedit.WorldEditException) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) Direction(com.sk89q.worldedit.util.Direction) SoftReference(java.lang.ref.SoftReference) RegionWrapper(com.fastasyncworldedit.core.regions.RegionWrapper) Nonnull(javax.annotation.Nonnull) Region(com.sk89q.worldedit.regions.Region) Nullable(javax.annotation.Nullable) Range(org.jetbrains.annotations.Range) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) CommandUtil.checkCommandArgument(com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument) File(java.io.File) Actor(com.sk89q.worldedit.extension.platform.Actor) ExecutionException(java.util.concurrent.ExecutionException) Command(org.enginehub.piston.annotation.Command) DBHandler(com.fastasyncworldedit.core.database.DBHandler) Arguments(com.sk89q.worldedit.command.argument.Arguments) FaweAPI(com.fastasyncworldedit.core.FaweAPI) LocalSession(com.sk89q.worldedit.LocalSession) BlockState(com.sk89q.worldedit.world.block.BlockState) Supplier(java.util.function.Supplier) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 3 with RollbackDatabase

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);
    }
}
Also used : RollbackDatabase(com.fastasyncworldedit.core.database.RollbackDatabase)

Example 4 with RollbackDatabase

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);
    }
}
Also used : RollbackDatabase(com.fastasyncworldedit.core.database.RollbackDatabase)

Example 5 with RollbackDatabase

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;
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) IOException(java.io.IOException) BlockVector3(com.sk89q.worldedit.math.BlockVector3) World(com.sk89q.worldedit.world.World) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) BlockState(com.sk89q.worldedit.world.block.BlockState) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) MutableFullBlockChange(com.fastasyncworldedit.core.history.change.MutableFullBlockChange) UUID(java.util.UUID) RollbackDatabase(com.fastasyncworldedit.core.database.RollbackDatabase)

Aggregations

RollbackDatabase (com.fastasyncworldedit.core.database.RollbackDatabase)5 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)3 World (com.sk89q.worldedit.world.World)3 UUID (java.util.UUID)3 SimpleChangeSetSummary (com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)2 File (java.io.File)2 Command (org.enginehub.piston.annotation.Command)2 Fawe (com.fastasyncworldedit.core.Fawe)1 FaweAPI (com.fastasyncworldedit.core.FaweAPI)1 Caption (com.fastasyncworldedit.core.configuration.Caption)1 Settings (com.fastasyncworldedit.core.configuration.Settings)1 DBHandler (com.fastasyncworldedit.core.database.DBHandler)1 MutableFullBlockChange (com.fastasyncworldedit.core.history.change.MutableFullBlockChange)1 RegionWrapper (com.fastasyncworldedit.core.regions.RegionWrapper)1 MainUtil (com.fastasyncworldedit.core.util.MainUtil)1 StringMan (com.fastasyncworldedit.core.util.StringMan)1