mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-28 21:56:33 +01:00
Anvil paste (undo/restrictions)
This commit is contained in:
parent
7359100159
commit
3b77a09e27
@ -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<Object> 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<IAnvilHistory> 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<RegionWrapper> 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());
|
||||
}
|
||||
}
|
@ -155,6 +155,10 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk
|
||||
}
|
||||
|
||||
public void pasteRegion(MCAQueue from, final RegionWrapper regionFrom, Vector offset) throws IOException {
|
||||
pasteRegion(from, regionFrom, offset, new NullAnvilHistory());
|
||||
}
|
||||
|
||||
public void pasteRegion(MCAQueue from, final RegionWrapper regionFrom, Vector offset, IAnvilHistory history) throws IOException {
|
||||
int oX = offset.getBlockX();
|
||||
int oZ = offset.getBlockZ();
|
||||
int oY = offset.getBlockY();
|
||||
@ -199,12 +203,14 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk
|
||||
if (bx >= 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<FaweQueue, FaweChunk, FaweChunk
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, regionTo);
|
||||
}, regionTo, history);
|
||||
from.clear();
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,8 @@ import com.sk89q.worldedit.world.registry.WorldData;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -173,6 +175,20 @@ public abstract class FawePlayer<T> 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<RegionWrapper> 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user