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));
}
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;
}
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));
}
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;
}
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();
}
Aggregations