From 3b77a09e27c4d3506b725c9ba2683f131de02d63 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 20 Aug 2017 15:26:27 +1000 Subject: [PATCH] Anvil paste (undo/restrictions) --- .../boydti/fawe/command/AnvilCommands.java | 41 ++++++++++--------- .../com/boydti/fawe/jnbt/anvil/MCAQueue.java | 20 +++++---- .../com/boydti/fawe/object/FawePlayer.java | 16 ++++++++ 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/command/AnvilCommands.java b/core/src/main/java/com/boydti/fawe/command/AnvilCommands.java index eacd2155..d09ba15e 100644 --- a/core/src/main/java/com/boydti/fawe/command/AnvilCommands.java +++ b/core/src/main/java/com/boydti/fawe/command/AnvilCommands.java @@ -19,19 +19,18 @@ import com.boydti.fawe.jnbt.anvil.filters.RemapFilter; import com.boydti.fawe.jnbt.anvil.filters.RemoveLayerFilter; import com.boydti.fawe.jnbt.anvil.filters.ReplacePatternFilter; import com.boydti.fawe.jnbt.anvil.filters.ReplaceSimpleFilter; +import com.boydti.fawe.jnbt.anvil.history.IAnvilHistory; +import com.boydti.fawe.jnbt.anvil.history.NullAnvilHistory; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RunnableVal4; import com.boydti.fawe.object.changeset.AnvilHistory; import com.boydti.fawe.object.clipboard.ClipboardRemapper; -import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.object.mask.FaweBlockMatcher; -import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.StringMan; -import com.boydti.fawe.util.WEManager; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.worldedit.EditSession; @@ -49,15 +48,15 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.parametric.Optional; +import com.sk89q.worldedit.world.World; import java.io.IOException; import java.io.RandomAccessFile; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.function.Consumer; import static com.google.common.base.Preconditions.checkNotNull; @@ -129,23 +128,22 @@ public class AnvilCommands { FaweQueue tmp = SetQueue.IMP.getNewQueue(worldName, true, false); MCAQueue queue = new MCAQueue(tmp); FawePlayer fp = FawePlayer.wrap(player); + fp.checkAllowedRegion(selection); + recordHistory(fp, editSession.getWorld(), iAnvilHistory -> { + queue.filterCopy(filter, wrappedRegion, iAnvilHistory); + }); + return filter; + } + + public static void recordHistory(FawePlayer fp, World world, Consumer run) { LocalSession session = fp.getSession(); if (session == null || session.hasFastMode()) { - queue.filterCopy(filter, wrappedRegion); + run.accept(new NullAnvilHistory()); } else { - RegionWrapper[] allowed = WEManager.IMP.getMask(fp, FaweMaskManager.MaskType.OWNER); - HashSet allowedSet = new HashSet<>(Arrays.asList(allowed)); - RegionWrapper wrappedSelection = new RegionWrapper(selection.getMinimumPoint(), selection.getMaximumPoint()); - if (allowed.length == 0) { - throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION); - } else if (!WEManager.IMP.regionContains(wrappedSelection, allowedSet)) { - throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); - } - AnvilHistory history = new AnvilHistory(worldName, player.getUniqueId()); - queue.filterCopy(filter, wrappedRegion, history); - session.remember(player, editSession.getWorld(), history, fp.getLimit()); + AnvilHistory history = new AnvilHistory(Fawe.imp().getWorldName(world), fp.getUUID()); + run.accept(history); + session.remember(fp.getPlayer(), world, history, fp.getLimit()); } - return filter; } @Command( @@ -590,7 +588,12 @@ public class AnvilCommands { MCAQueue copyQueue = clipboard.getQueue(); MCAQueue pasteQueue = new MCAQueue(tmpTo); - pasteQueue.pasteRegion(copyQueue, copyRegion, offset); + fp.checkAllowedRegion(pasteRegion); + recordHistory(fp, editSession.getWorld(), iAnvilHistory -> { + try { + pasteQueue.pasteRegion(copyQueue, copyRegion, offset, iAnvilHistory); + } catch (IOException e) { throw new RuntimeException(e); } + }); BBC.COMMAND_PASTE.send(player, player.getPosition()); } } \ No newline at end of file diff --git a/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java b/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java index cc227924..83729d12 100644 --- a/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java +++ b/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java @@ -155,6 +155,10 @@ public class MCAQueue extends NMSMappedFaweQueue= regionTo.minX && tx <= regionTo.maxX && bz >= regionTo.minZ && tz <= regionTo.maxZ) { FaweChunk chunk = from.getFaweChunk(cx - oCX, cz - oCZ); if (!(chunk instanceof NullFaweChunk)) { - if (regionTo.minY == 0 && regionTo.maxY == 255) { - MCAChunk mcaChunk = (MCAChunk) chunk; - mcaChunk.setLoc(null, cx, cz); - mcaChunk.setModified(); - mcaFile.setChunk(mcaChunk); - } else { +// if (regionTo.minY == 0 && regionTo.maxY == 255) { +// System.out.println("Vertical"); +// MCAChunk mcaChunk = (MCAChunk) chunk; +// mcaChunk.setLoc(null, cx, cz); +// mcaChunk.setModified(); +// mcaFile.setChunk(mcaChunk); +// } else + { MCAChunk newChunk = mcaFile.getChunk(cx, cz); if (newChunk == null) { newChunk = new MCAChunk(MCAQueue.this, cx, cz); @@ -277,7 +283,7 @@ public class MCAQueue extends NMSMappedFaweQueue extends Metadatable { } } + public void checkAllowedRegion(Region selection) { + checkAllowedRegion(new RegionWrapper(selection.getMinimumPoint(), selection.getMaximumPoint())); + } + + public void checkAllowedRegion(RegionWrapper wrappedSelection) { + RegionWrapper[] allowed = WEManager.IMP.getMask(this, FaweMaskManager.MaskType.OWNER); + HashSet allowedSet = new HashSet<>(Arrays.asList(allowed)); + if (allowed.length == 0) { + throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION); + } else if (!WEManager.IMP.regionContains(wrappedSelection, allowedSet)) { + throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); + } + } + public boolean confirm() { String confirm = deleteMeta("cmdConfirm"); if (confirm == null) {