Search in sources :

Example 1 with ChangeSet

use of com.sk89q.worldedit.history.changeset.ChangeSet 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 2 with ChangeSet

use of com.sk89q.worldedit.history.changeset.ChangeSet in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method undo.

// FAWE end
// FAWE start
/**
 * Restores all blocks to their initial state.
 *
 * @param editSession a new {@link EditSession} to perform the undo in
 */
public void undo(EditSession editSession) {
    UndoContext context = new UndoContext();
    // FAWE start - listen for inventory, flush & prepare changeset
    context.setExtent(editSession.bypassAll);
    ChangeSet changeSet = getChangeSet();
    setChangeSet(null);
    Operations.completeBlindly(ChangeSetExecutor.create(changeSet, context, ChangeSetExecutor.Type.UNDO, editSession.getBlockBag(), editSession.getLimit().INVENTORY_MODE));
    flushQueue();
    editSession.changes = 1;
}
Also used : UndoContext(com.sk89q.worldedit.history.UndoContext) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) AbstractChangeSet(com.fastasyncworldedit.core.history.changeset.AbstractChangeSet)

Example 3 with ChangeSet

use of com.sk89q.worldedit.history.changeset.ChangeSet in project FastAsyncWorldEdit by IntellectualSites.

the class HistorySubCommands method find.

@Command(name = "find", aliases = { "inspect", "search", "near" }, desc = "Find nearby edits")
@CommandPermissions("worldedit.history.find")
public synchronized void find(Player player, World world, RollbackDatabase database, Arguments arguments, @ArgFlag(name = 'u', def = "", desc = "String user") UUID other, @ArgFlag(name = 'r', def = "0", desc = "radius") @Range(from = 0, to = Integer.MAX_VALUE) Integer radius, @ArgFlag(name = 't', desc = "Time e.g. 20s", def = "0") @Time Long timeDiff, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws WorldEditException {
    if (!Settings.settings().HISTORY.USE_DATABASE) {
        player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with //history import )"));
        return;
    }
    if (other == null && radius == 0 && timeDiff == 0) {
        throw new InsufficientArgumentsException(Caption.of("fawe.error.invalid-user"));
    }
    checkCommandArgument(radius > 0, Caption.of("fawe.error.radius-too-small"));
    checkCommandArgument(timeDiff > 0, Caption.of("fawe.error.time-too-less"));
    Location origin = player.getLocation();
    String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
    Reference<List<Supplier<? extends ChangeSet>>> cached = player.getMeta(pageCommand);
    List<Supplier<? extends ChangeSet>> history = cached == null ? null : cached.get();
    if (page == null || history == null) {
        if (other == null) {
            other = player.getUniqueId();
        }
        if (!other.equals(player.getUniqueId())) {
            player.checkPermission("worldedit.history.undo.other");
        }
        if (other == Identifiable.EVERYONE) {
            other = null;
        }
        BlockVector3 bot = origin.toBlockPoint().subtract(radius, radius, radius);
        BlockVector3 top = origin.toBlockPoint().add(radius, radius, radius);
        bot = bot.clampY(world.getMinY(), world.getMaxY());
        top = top.clampY(world.getMinY(), world.getMaxY());
        long minTime = System.currentTimeMillis() - timeDiff;
        Iterable<Supplier<RollbackOptimizedHistory>> edits = database.getEdits(other, minTime, bot, top, false, false);
        history = Lists.newArrayList(edits);
        player.setMeta(pageCommand, new SoftReference<>(history));
        page = 1;
    }
    PaginationBox box = list(database, pageCommand, history, origin.toBlockPoint());
    player.print(box.create(page));
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) List(java.util.List) 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 4 with ChangeSet

use of com.sk89q.worldedit.history.changeset.ChangeSet in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method redo.

// FAWE end
/**
 * Sets to new state.
 *
 * @param editSession a new {@link EditSession} to perform the redo in
 */
public void redo(EditSession editSession) {
    UndoContext context = new UndoContext();
    // FAWE start - listen for inventory, flush & prepare changeset
    context.setExtent(editSession.bypassAll);
    ChangeSet changeSet = getChangeSet();
    setChangeSet(null);
    Operations.completeBlindly(ChangeSetExecutor.create(changeSet, context, ChangeSetExecutor.Type.REDO, editSession.getBlockBag(), editSession.getLimit().INVENTORY_MODE));
    flushQueue();
    editSession.changes = 1;
}
Also used : UndoContext(com.sk89q.worldedit.history.UndoContext) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) AbstractChangeSet(com.fastasyncworldedit.core.history.changeset.AbstractChangeSet)

Example 5 with ChangeSet

use of com.sk89q.worldedit.history.changeset.ChangeSet in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method popMissingBlocks.

/**
 * Gets the list of missing blocks and clears the list for the next
 * operation.
 *
 * @return a map of missing blocks
 */
public Map<BlockType, Integer> popMissingBlocks() {
    BlockBag bag = getBlockBag();
    if (bag != null) {
        bag.flushChanges();
        Map<BlockType, Integer> missingBlocks;
        ChangeSet changeSet = getChangeSet();
        if (changeSet instanceof BlockBagChangeSet) {
            missingBlocks = ((BlockBagChangeSet) changeSet).popMissing();
        } else {
            ExtentTraverser<BlockBagExtent> find = new ExtentTraverser<>(getExtent()).find(BlockBagExtent.class);
            if (find != null && find.get() != null) {
                missingBlocks = find.get().popMissing();
            } else {
                missingBlocks = null;
            }
        }
        if (missingBlocks != null && !missingBlocks.isEmpty()) {
            StringBuilder str = new StringBuilder();
            int size = missingBlocks.size();
            int i = 0;
            for (Map.Entry<BlockType, Integer> entry : missingBlocks.entrySet()) {
                BlockType type = entry.getKey();
                int amount = entry.getValue();
                str.append((type.getName())).append((amount != 1 ? "x" + amount : ""));
                ++i;
                if (i != size) {
                    str.append(", ");
                }
            }
            actor.print(Caption.of("fawe.error.worldedit.some.fails.blockbag", str.toString()));
        }
    }
    return Collections.emptyMap();
}
Also used : BlockBagExtent(com.sk89q.worldedit.extent.inventory.BlockBagExtent) BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlockType(com.sk89q.worldedit.world.block.BlockType) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) AbstractChangeSet(com.fastasyncworldedit.core.history.changeset.AbstractChangeSet) Map(java.util.Map) HashMap(java.util.HashMap) BlockMap(com.sk89q.worldedit.util.collection.BlockMap)

Aggregations

ChangeSet (com.sk89q.worldedit.history.changeset.ChangeSet)5 AbstractChangeSet (com.fastasyncworldedit.core.history.changeset.AbstractChangeSet)3 BlockBagChangeSet (com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet)3 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 UndoContext (com.sk89q.worldedit.history.UndoContext)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 Location (com.sk89q.worldedit.util.Location)2 PaginationBox (com.sk89q.worldedit.util.formatting.component.PaginationBox)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 RollbackDatabase (com.fastasyncworldedit.core.database.RollbackDatabase)1 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)1 SimpleChangeSetSummary (com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary)1 RegionWrapper (com.fastasyncworldedit.core.regions.RegionWrapper)1 MainUtil (com.fastasyncworldedit.core.util.MainUtil)1 StringMan (com.fastasyncworldedit.core.util.StringMan)1 Function (com.google.common.base.Function)1