use of com.sk89q.worldedit.regions.NullRegion in project FastAsyncWorldEdit by IntellectualSites.
the class ClipboardCommands method copy.
@Command(name = "/copy", aliases = "/cp", desc = "Copy the selection to the clipboard")
@CommandPermissions("worldedit.clipboard.copy")
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void copy(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Switch(name = 'e', desc = "Also copy entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes") boolean copyBiomes, // FAWE start
@Switch(name = 'c', desc = "Set the origin of the clipboard to the center of the region, at the region's lowest " + "y-level.") boolean centerClipboard, @ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air", def = "") Mask mask) throws WorldEditException {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
FaweLimit limit = actor.getLimit();
if (volume >= limit.MAX_CHECKS) {
throw FaweCache.MAX_CHECKS;
}
session.setClipboard(null);
Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
clipboard.setOrigin(centerClipboard ? region.getCenter().toBlockPoint().withY(region.getMinimumY()) : session.getPlacementPosition(actor));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setCopyingEntities(copyEntities);
copy.setCopyingBiomes(copyBiomes);
Mask sourceMask = editSession.getSourceMask();
Region[] regions = editSession.getAllowedRegions();
Region allowedRegion;
if (regions == null || regions.length == 0) {
allowedRegion = new NullRegion();
} else {
allowedRegion = new RegionIntersection(regions);
}
final Mask firstSourceMask = mask != null ? mask : sourceMask;
final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
if (finalMask != Masks.alwaysTrue()) {
copy.setSourceMask(finalMask);
}
if (sourceMask != null) {
editSession.setSourceMask(null);
new MaskTraverser(sourceMask).reset(editSession);
editSession.setSourceMask(null);
}
try {
Operations.completeLegacy(copy);
} catch (Throwable e) {
throw e;
} finally {
clipboard.flush();
}
session.setClipboard(new ClipboardHolder(clipboard));
copy.getStatusMessages().forEach(actor::print);
// FAWE end
}
use of com.sk89q.worldedit.regions.NullRegion in project FastAsyncWorldEdit by IntellectualSites.
the class ClipboardCommands method cut.
/*
@Command(
name = "/lazycut",
desc = "Lazily cut the selection to the clipboard"
)
@CommandPermissions("worldedit.clipboard.lazycut")
public void lazyCut(Actor actor, LocalSession session, EditSession editSession,
@Selection final Region region,
@Switch(name = 'e', desc = "Skip copy entities")
boolean skipEntities,
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
Mask maskOpt,
@Switch(name = 'b', desc = "Also copy biomes")
boolean copyBiomes) throws WorldEditException {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
FaweLimit limit = actor.getLimit();
if (volume >= limit.MAX_CHECKS) {
throw FaweCache.MAX_CHECKS;
}
if (volume >= limit.MAX_CHANGES) {
throw FaweCache.MAX_CHANGES;
}
session.setClipboard(null);
ReadOnlyClipboard lazyClipboard = new WorldCutClipboard(editSession, region, !skipEntities, copyBiomes);
clipboard.setOrigin(session.getPlacementPosition(actor));
session.setClipboard(new ClipboardHolder(lazyClipboard));
actor.print(Caption.of("fawe.worldedit.cut.command.cut.lazy", region.getArea()));
}*/
// FAWE end
@Command(name = "/cut", desc = "Cut the selection to the clipboard", descFooter = "WARNING: Cutting and pasting entities cannot be undone!")
@CommandPermissions("worldedit.clipboard.cut")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void cut(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "Pattern to leave in place of the selection", def = "air") Pattern leavePattern, @Switch(name = 'e', desc = "Also cut entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes, source biomes are unaffected") boolean copyBiomes, @ArgFlag(name = 'm', desc = "Set the exclude mask, non-matching blocks become air") Mask mask) throws WorldEditException {
// FAWE start - Inject limits & respect source mask
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
FaweLimit limit = actor.getLimit();
if (volume >= limit.MAX_CHECKS) {
throw FaweCache.MAX_CHECKS;
}
if (volume >= limit.MAX_CHANGES) {
throw FaweCache.MAX_CHANGES;
}
session.setClipboard(null);
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
clipboard.setOrigin(session.getPlacementPosition(actor));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
copy.setCopyingEntities(copyEntities);
copy.setRemovingEntities(true);
copy.setCopyingBiomes(copyBiomes);
Mask sourceMask = editSession.getSourceMask();
Region[] regions = editSession.getAllowedRegions();
Region allowedRegion;
if (regions == null || regions.length == 0) {
allowedRegion = new NullRegion();
} else {
allowedRegion = new RegionIntersection(regions);
}
final Mask firstSourceMask = mask != null ? mask : sourceMask;
final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
if (finalMask != Masks.alwaysTrue()) {
copy.setSourceMask(finalMask);
}
if (sourceMask != null) {
editSession.setSourceMask(null);
new MaskTraverser(sourceMask).reset(editSession);
editSession.setSourceMask(null);
}
try {
Operations.completeLegacy(copy);
} catch (Throwable e) {
throw e;
} finally {
clipboard.flush();
}
session.setClipboard(new ClipboardHolder(clipboard));
if (!actor.hasPermission("fawe.tips")) {
actor.print(Caption.of("fawe.tips.tip.lazycut"));
}
copy.getStatusMessages().forEach(actor::print);
// FAWE end
}
use of com.sk89q.worldedit.regions.NullRegion in project FastAsyncWorldEdit by IntellectualSites.
the class RequestSelection method getRegion.
/**
* Get the delegate region.
*
* @return the delegate region
*/
protected Region getRegion() {
LocalSession session = Request.request().getSession();
World world = Request.request().getWorld();
if (session != null && world != null) {
try {
return session.getSelection(world);
} catch (IncompleteRegionException ignored) {
}
}
return new NullRegion();
}
use of com.sk89q.worldedit.regions.NullRegion in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method moveRegion.
/**
* Move the blocks in a region a certain direction.
*
* @param region the region to move
* @param offset the offset. Is directional.
* @param multiplier the number to multiply the offset by
* @param moveEntities true to move entities
* @param copyBiomes true to copy biomes (source biome is unchanged)
* @param mask source mask for the operation (only matching blocks are moved)
* @param replacement the replacement pattern to fill in after moving, or null to use air
* @return number of blocks moved
* @throws MaxChangedBlocksException thrown if too many blocks are changed
* @throws IllegalArgumentException thrown if the region is not a flat region, but copyBiomes is true
*/
public int moveRegion(Region region, BlockVector3 offset, int multiplier, boolean moveEntities, boolean copyBiomes, Mask mask, Pattern replacement) throws MaxChangedBlocksException {
checkNotNull(region);
checkNotNull(offset);
checkArgument(multiplier >= 1, "distance >= 1 required");
checkArgument(!copyBiomes || region instanceof FlatRegion, "can't copy biomes from non-flat region");
// FAWE start - add up distance
BlockVector3 to = region.getMinimumPoint().add(offset.multiply(multiplier));
final BlockVector3 displace = offset.multiply(multiplier);
final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
BlockVector3 disAbs = displace.abs();
if (disAbs.getBlockX() < size.getBlockX() && disAbs.getBlockY() < size.getBlockY() && disAbs.getBlockZ() < size.getBlockZ()) {
// Buffer if overlapping
enableQueue();
}
ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);
if (replacement == null) {
replacement = BlockTypes.AIR.getDefaultState();
}
BlockReplace remove = replacement instanceof ExistingPattern ? null : new BlockReplace(this, replacement);
// Remove
copy.setSourceFunction(remove);
copy.setCopyingEntities(moveEntities);
copy.setRemovingEntities(moveEntities);
copy.setCopyingBiomes(copyBiomes);
copy.setRepetitions(1);
final Region allowedRegion;
if (allowedRegions == null || allowedRegions.length == 0) {
allowedRegion = new NullRegion();
} else {
allowedRegion = new RegionIntersection(allowedRegions);
}
Mask sourceMask = this.getSourceMask();
mask = MaskIntersection.of(sourceMask, mask, new RegionMask(allowedRegion)).optimize();
if (mask != Masks.alwaysTrue()) {
copy.setSourceMask(mask);
if (sourceMask != null && sourceMask.equals(mask)) {
setSourceMask(null);
}
}
Operations.completeBlindly(copy);
return this.changes = copy.getAffected();
// FAWE end
}
use of com.sk89q.worldedit.regions.NullRegion in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method stackCuboidRegion.
// FAWE start
/**
* Stack a cuboid region.
*
* @param region the region to stack
* @param offset how far to move the contents each stack. Is directional.
* @param count the number of times to stack
* @param copyEntities true to copy entities
* @param copyBiomes true to copy biomes
* @param mask source mask for the operation (only matching blocks are copied)
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int stackCuboidRegion(Region region, BlockVector3 offset, int count, boolean copyEntities, boolean copyBiomes, Mask mask) throws MaxChangedBlocksException {
checkNotNull(region);
checkNotNull(offset);
checkArgument(count >= 1, "count >= 1 required");
BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
BlockVector3 to = region.getMinimumPoint();
ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);
copy.setRepetitions(count);
copy.setTransform(new AffineTransform().translate(offset.multiply(size)));
copy.setCopyingEntities(copyEntities);
copy.setCopyingBiomes(copyBiomes);
final Region allowedRegion;
if (allowedRegions == null || allowedRegions.length == 0) {
allowedRegion = new NullRegion();
} else {
allowedRegion = new RegionIntersection(allowedRegions);
}
mask = MaskIntersection.of(getSourceMask(), mask, new RegionMask(allowedRegion)).optimize();
if (mask != Masks.alwaysTrue()) {
setSourceMask(null);
copy.setSourceMask(mask);
}
Operations.completeLegacy(copy);
return this.changes = copy.getAffected();
}
Aggregations