2014-04-03 02:08:50 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.FaweAPI;
|
|
|
|
import com.fastasyncworldedit.core.FaweCache;
|
|
|
|
import com.fastasyncworldedit.core.configuration.Caption;
|
|
|
|
import com.fastasyncworldedit.core.configuration.Settings;
|
2021-07-24 15:34:05 +00:00
|
|
|
import com.fastasyncworldedit.core.event.extent.PasteEvent;
|
2021-09-27 13:39:21 +00:00
|
|
|
import com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard;
|
2021-07-23 15:48:51 +00:00
|
|
|
import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder;
|
|
|
|
import com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard;
|
|
|
|
import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder;
|
|
|
|
import com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream;
|
2021-10-09 11:02:26 +00:00
|
|
|
import com.fastasyncworldedit.core.limit.FaweLimit;
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.util.ImgurUtility;
|
|
|
|
import com.fastasyncworldedit.core.util.MainUtil;
|
|
|
|
import com.fastasyncworldedit.core.util.MaskTraverser;
|
2021-07-24 15:34:05 +00:00
|
|
|
import com.fastasyncworldedit.core.util.task.RunnableVal;
|
2020-04-23 16:01:17 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
2019-06-23 18:00:22 +00:00
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.LocalSession;
|
2019-11-20 00:11:54 +00:00
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
|
|
|
import com.sk89q.worldedit.command.util.Logging;
|
2019-11-21 06:50:37 +00:00
|
|
|
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
2021-08-17 00:47:09 +00:00
|
|
|
import com.sk89q.worldedit.command.util.annotation.Preload;
|
2019-10-09 20:15:26 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
2019-01-31 15:08:58 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
2019-01-31 15:08:58 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.function.block.BlockReplace;
|
2014-07-02 19:55:18 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2021-01-10 14:59:21 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
|
|
|
import com.sk89q.worldedit.function.mask.Masks;
|
|
|
|
import com.sk89q.worldedit.function.mask.RegionMask;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.function.operation.Operation;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
2019-08-15 19:21:24 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.ClipboardMask;
|
2014-07-02 09:56:21 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.Direction;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.Selection;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
import com.sk89q.worldedit.math.Vector3;
|
2014-07-02 09:56:21 +00:00
|
|
|
import com.sk89q.worldedit.math.transform.AffineTransform;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.math.transform.Transform;
|
2021-01-10 14:59:21 +00:00
|
|
|
import com.sk89q.worldedit.regions.NullRegion;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2021-01-10 14:59:21 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionIntersection;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionSelector;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
2014-07-02 09:56:21 +00:00
|
|
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
2019-10-13 11:47:26 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
2020-05-13 14:23:38 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
2020-04-23 16:01:17 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2019-11-02 11:13:42 +00:00
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
|
|
|
import org.enginehub.piston.annotation.param.ArgFlag;
|
|
|
|
import org.enginehub.piston.annotation.param.Switch;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.util.HashSet;
|
2020-04-23 16:01:17 +00:00
|
|
|
import java.util.List;
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
2020-04-23 16:01:17 +00:00
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
|
2019-04-05 23:40:25 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
/**
|
|
|
|
* Clipboard commands.
|
|
|
|
*/
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
|
|
|
public class ClipboardCommands {
|
2014-06-28 08:01:49 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/copy",
|
|
|
|
aliases = "/cp",
|
|
|
|
desc = "Copy the selection to the clipboard"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.copy")
|
2021-08-17 00:47:09 +00:00
|
|
|
@Preload(Preload.PreloadCheck.PRELOAD)
|
2019-11-21 06:50:37 +00:00
|
|
|
@Confirm(Confirm.Processor.REGION)
|
2021-07-24 15:34:05 +00:00
|
|
|
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
|
2021-09-19 19:47:21 +00:00
|
|
|
@Switch(name = 'c', desc = "Set the origin of the clipboard to the center of the region, at the region's lowest " +
|
|
|
|
"y-level.")
|
2021-07-24 15:34:05 +00:00
|
|
|
boolean centerClipboard,
|
|
|
|
@ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air", def = "")
|
|
|
|
Mask mask
|
|
|
|
) throws WorldEditException {
|
2019-07-06 00:46:48 +00:00
|
|
|
BlockVector3 min = region.getMinimumPoint();
|
|
|
|
BlockVector3 max = region.getMaximumPoint();
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2019-08-06 15:29:49 +00:00
|
|
|
long volume =
|
2021-07-24 15:34:05 +00:00
|
|
|
((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min
|
|
|
|
.getZ() + 1);
|
2019-10-09 20:15:26 +00:00
|
|
|
FaweLimit limit = actor.getLimit();
|
2018-09-07 15:31:30 +00:00
|
|
|
if (volume >= limit.MAX_CHECKS) {
|
2020-01-29 20:01:38 +00:00
|
|
|
throw FaweCache.MAX_CHECKS;
|
2018-09-07 15:31:30 +00:00
|
|
|
}
|
2019-11-21 06:50:37 +00:00
|
|
|
session.setClipboard(null);
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2021-09-10 23:27:26 +00:00
|
|
|
Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
|
2021-09-19 19:47:21 +00:00
|
|
|
clipboard.setOrigin(centerClipboard ? region.getCenter().toBlockPoint().withY(region.getMinimumY()) :
|
|
|
|
session.getPlacementPosition(actor));
|
2021-09-13 12:19:57 +00:00
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
|
|
|
copy.setCopyingEntities(copyEntities);
|
|
|
|
copy.setCopyingBiomes(copyBiomes);
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2021-09-13 12:19:57 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-01-10 14:59:21 +00:00
|
|
|
|
2021-09-13 12:19:57 +00:00
|
|
|
try {
|
2021-09-10 16:46:21 +00:00
|
|
|
Operations.completeLegacy(copy);
|
2021-09-10 23:27:26 +00:00
|
|
|
} catch (Throwable e) {
|
|
|
|
throw e;
|
2021-09-13 12:19:57 +00:00
|
|
|
} finally {
|
2021-09-13 14:07:16 +00:00
|
|
|
clipboard.flush();
|
2021-09-10 16:46:21 +00:00
|
|
|
}
|
2021-09-13 12:19:57 +00:00
|
|
|
session.setClipboard(new ClipboardHolder(clipboard));
|
|
|
|
|
|
|
|
copy.getStatusMessages().forEach(actor::print);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/lazycopy",
|
|
|
|
desc = "Lazily copy the selection to the clipboard"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.lazycopy")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void lazyCopy(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession, @Selection Region region,
|
|
|
|
@Switch(name = 'e', desc = "Skip copy entities")
|
|
|
|
boolean skipEntities,
|
|
|
|
@Switch(name = 'b', desc = "Also copy biomes")
|
|
|
|
boolean copyBiomes
|
|
|
|
) throws WorldEditException {
|
2019-07-06 00:46:48 +00:00
|
|
|
BlockVector3 min = region.getMinimumPoint();
|
|
|
|
BlockVector3 max = region.getMaximumPoint();
|
2021-07-24 15:34:05 +00:00
|
|
|
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min
|
|
|
|
.getZ() + 1));
|
2019-10-09 20:15:26 +00:00
|
|
|
FaweLimit limit = actor.getLimit();
|
2019-07-06 00:46:48 +00:00
|
|
|
if (volume >= limit.MAX_CHECKS) {
|
2021-09-01 14:36:03 +00:00
|
|
|
throw FaweCache.MAX_CHECKS;
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
session.setClipboard(null);
|
2019-11-06 09:29:20 +00:00
|
|
|
ReadOnlyClipboard lazyClipboard = ReadOnlyClipboard.of(region, !skipEntities, copyBiomes);
|
2019-07-06 00:46:48 +00:00
|
|
|
|
2019-11-11 22:34:33 +00:00
|
|
|
lazyClipboard.setOrigin(session.getPlacementPosition(actor));
|
|
|
|
session.setClipboard(new ClipboardHolder(lazyClipboard));
|
2020-10-05 17:41:41 +00:00
|
|
|
actor.print(Caption.of("fawe.worldedit.copy.command.copy", region.getVolume()));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-05 17:41:41 +00:00
|
|
|
/*
|
|
|
|
@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));
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("fawe.worldedit.cut.command.cut.lazy", region.getArea()));
|
2020-10-05 17:41:41 +00:00
|
|
|
}*/
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/cut",
|
|
|
|
desc = "Cut the selection to the clipboard",
|
|
|
|
descFooter = "WARNING: Cutting and pasting entities cannot be undone!"
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.cut")
|
|
|
|
@Logging(REGION)
|
2021-08-17 00:47:09 +00:00
|
|
|
@Preload(Preload.PreloadCheck.PRELOAD)
|
2019-11-21 06:50:37 +00:00
|
|
|
@Confirm(Confirm.Processor.REGION)
|
2021-07-24 15:34:05 +00:00
|
|
|
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 {
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start - Inject limits & respect source mask
|
2019-07-06 00:46:48 +00:00
|
|
|
BlockVector3 min = region.getMinimumPoint();
|
|
|
|
BlockVector3 max = region.getMaximumPoint();
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min
|
|
|
|
.getZ() + 1));
|
2019-10-09 20:15:26 +00:00
|
|
|
FaweLimit limit = actor.getLimit();
|
2018-09-07 15:31:30 +00:00
|
|
|
if (volume >= limit.MAX_CHECKS) {
|
2020-01-29 20:01:38 +00:00
|
|
|
throw FaweCache.MAX_CHECKS;
|
2018-09-07 15:31:30 +00:00
|
|
|
}
|
|
|
|
if (volume >= limit.MAX_CHANGES) {
|
2020-01-29 20:01:38 +00:00
|
|
|
throw FaweCache.MAX_CHANGES;
|
2018-09-07 15:31:30 +00:00
|
|
|
}
|
2019-11-21 06:50:37 +00:00
|
|
|
session.setClipboard(null);
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2019-11-21 06:50:37 +00:00
|
|
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
|
2021-09-13 12:19:57 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-09-10 23:27:26 +00:00
|
|
|
try {
|
|
|
|
Operations.completeLegacy(copy);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
throw e;
|
2021-09-13 12:19:57 +00:00
|
|
|
} finally {
|
2021-09-13 14:07:16 +00:00
|
|
|
clipboard.flush();
|
2021-09-13 12:19:57 +00:00
|
|
|
}
|
|
|
|
session.setClipboard(new ClipboardHolder(clipboard));
|
|
|
|
|
|
|
|
if (!actor.hasPermission("fawe.tips")) {
|
|
|
|
actor.print(Caption.of("fawe.tips.tip.lazycut"));
|
2019-11-21 06:50:37 +00:00
|
|
|
}
|
2021-09-13 12:19:57 +00:00
|
|
|
copy.getStatusMessages().forEach(actor::print);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start
|
2019-06-23 18:00:22 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "download",
|
|
|
|
aliases = {"/download"},
|
|
|
|
desc = "Downloads your clipboard through the configured web interface"
|
2019-06-23 18:00:22 +00:00
|
|
|
)
|
2018-08-12 14:03:07 +00:00
|
|
|
@Deprecated
|
|
|
|
@CommandPermissions({"worldedit.clipboard.download"})
|
2021-07-24 15:34:05 +00:00
|
|
|
public void download(
|
2021-09-28 14:59:52 +00:00
|
|
|
final Actor actor,
|
2021-07-24 15:34:05 +00:00
|
|
|
final LocalSession session,
|
|
|
|
@Arg(name = "format", desc = "String", def = "fast") final String formatName
|
|
|
|
) throws WorldEditException {
|
2019-01-31 15:08:58 +00:00
|
|
|
final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
|
2018-08-12 14:03:07 +00:00
|
|
|
if (format == null) {
|
2021-09-28 14:59:52 +00:00
|
|
|
actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.invalid.format", formatName));
|
2018-08-12 14:03:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-28 14:59:52 +00:00
|
|
|
actor.print(Caption.of("fawe.web.generating.link", formatName));
|
2018-08-12 14:03:07 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
|
|
|
|
URL url;
|
|
|
|
if (holder instanceof MultiClipboardHolder) {
|
|
|
|
MultiClipboardHolder multi = (MultiClipboardHolder) holder;
|
|
|
|
Set<File> files = new HashSet<>();
|
|
|
|
Set<URI> invalid = new HashSet<>();
|
|
|
|
for (ClipboardHolder cur : multi.getHolders()) {
|
|
|
|
if (cur instanceof URIClipboardHolder) {
|
|
|
|
URIClipboardHolder uriHolder = (URIClipboardHolder) cur;
|
|
|
|
URI uri = uriHolder.getUri();
|
|
|
|
File file = new File(uri.getPath());
|
|
|
|
if (file.exists() && file.isFile()) {
|
|
|
|
files.add(file.getAbsoluteFile());
|
|
|
|
} else if (!uri.getPath().isEmpty()) {
|
|
|
|
invalid.add(uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-20 00:11:54 +00:00
|
|
|
final LocalConfiguration config = WorldEdit.getInstance().getConfiguration();
|
|
|
|
final File working = WorldEdit.getInstance().getWorkingDirectoryFile(config.saveDir).getAbsoluteFile();
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
url = MainUtil.upload(null, null, "zip", new RunnableVal<>() {
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
|
|
|
public void run(OutputStream out) {
|
|
|
|
try (ZipOutputStream zos = new ZipOutputStream(out)) {
|
|
|
|
for (File file : files) {
|
|
|
|
String fileName = file.getName();
|
2019-07-06 00:46:48 +00:00
|
|
|
if (MainUtil.isInSubDirectory(working, file)) {
|
|
|
|
fileName = working.toURI().relativize(file.toURI()).getPath();
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
ZipEntry ze = new ZipEntry(fileName);
|
|
|
|
zos.putNextEntry(ze);
|
|
|
|
Files.copy(file.toPath(), zos);
|
|
|
|
zos.closeEntry();
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Clipboard clipboard = holder.getClipboard();
|
|
|
|
final Transform transform = holder.getTransform();
|
|
|
|
final Clipboard target;
|
|
|
|
// If we have a transform, bake it into the copy
|
|
|
|
if (!transform.isIdentity()) {
|
|
|
|
final FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform);
|
2021-09-28 14:59:52 +00:00
|
|
|
target = new BlockArrayClipboard(result.getTransformedRegion(), actor.getUniqueId());
|
2018-08-12 14:03:07 +00:00
|
|
|
target.setOrigin(clipboard.getOrigin());
|
|
|
|
Operations.completeLegacy(result.copyTo(target));
|
|
|
|
} else {
|
|
|
|
target = clipboard;
|
|
|
|
}
|
2019-04-15 11:05:26 +00:00
|
|
|
if (format == BuiltInClipboardFormat.PNG) {
|
|
|
|
try {
|
|
|
|
FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE);
|
|
|
|
ClipboardWriter writer = format.getWriter(baos);
|
|
|
|
writer.write(target);
|
|
|
|
baos.flush();
|
2019-10-23 04:23:52 +00:00
|
|
|
url = ImgurUtility.uploadImage(baos.toByteArray());
|
2019-04-15 11:05:26 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2018-08-12 14:03:07 +00:00
|
|
|
url = null;
|
2019-04-15 11:05:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Settings.IMP.WEB.URL.isEmpty()) {
|
2021-09-28 14:59:52 +00:00
|
|
|
actor.print(Caption.of("fawe.error.setting.disable", "web.url"));
|
2019-04-15 11:05:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
url = FaweAPI.upload(target, format);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-10-23 14:35:04 +00:00
|
|
|
}
|
|
|
|
if (url == null) {
|
2021-09-28 14:59:52 +00:00
|
|
|
actor.print(Caption.of("fawe.web.generating.link.failed"));
|
2019-10-23 14:35:04 +00:00
|
|
|
} else {
|
|
|
|
String urlText = url.toString();
|
2021-09-28 14:59:52 +00:00
|
|
|
actor.print(Caption.of("fawe.web.download.link", urlText).clickEvent(ClickEvent.openUrl(urlText)));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2020-04-23 16:01:17 +00:00
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
@Command(
|
|
|
|
name = "/place",
|
|
|
|
desc = "Place the clipboard's contents without applying transformations (e.g. rotate)"
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.place")
|
|
|
|
@Logging(PLACEMENT)
|
2021-07-24 15:34:05 +00:00
|
|
|
public void place(
|
|
|
|
Actor actor, World world, LocalSession session, final EditSession editSession,
|
|
|
|
@Switch(name = 'a', desc = "Skip air blocks")
|
|
|
|
boolean ignoreAirBlocks,
|
|
|
|
@Switch(name = 'o', desc = "Paste at the original position")
|
|
|
|
boolean atOrigin,
|
|
|
|
@Switch(name = 's', desc = "Select the region after pasting")
|
|
|
|
boolean selectPasted,
|
|
|
|
@Switch(name = 'e', desc = "Paste entities if available")
|
|
|
|
boolean pasteEntities,
|
|
|
|
@Switch(name = 'b', desc = "Paste biomes if available")
|
|
|
|
boolean pasteBiomes
|
|
|
|
) throws WorldEditException {
|
2021-07-23 15:48:51 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
final Clipboard clipboard = holder.getClipboard();
|
|
|
|
final BlockVector3 origin = clipboard.getOrigin();
|
|
|
|
final BlockVector3 to = atOrigin ? origin : session.getPlacementPosition(actor);
|
|
|
|
checkPaste(actor, editSession, to, holder, clipboard);
|
|
|
|
|
|
|
|
clipboard.paste(editSession, to, !ignoreAirBlocks, pasteEntities, pasteBiomes);
|
|
|
|
|
|
|
|
Region region = clipboard.getRegion().clone();
|
|
|
|
if (selectPasted) {
|
|
|
|
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
|
|
|
BlockVector3 realTo = to.add(holder.getTransform().apply(clipboardOffset.toVector3()).toBlockPoint());
|
2021-07-24 15:34:05 +00:00
|
|
|
BlockVector3 max = realTo.add(holder
|
|
|
|
.getTransform()
|
|
|
|
.apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3())
|
|
|
|
.toBlockPoint());
|
2021-07-23 15:48:51 +00:00
|
|
|
RegionSelector selector = new CuboidRegionSelector(world, realTo, max);
|
|
|
|
session.setRegionSelector(world, selector);
|
|
|
|
selector.learnChanges();
|
|
|
|
selector.explainRegionAdjust(actor, session);
|
|
|
|
}
|
|
|
|
actor.print(Caption.of("fawe.worldedit.paste.command.paste", to));
|
|
|
|
|
|
|
|
if (!actor.hasPermission("fawe.tips")) {
|
|
|
|
actor.print(Caption.of("fawe.tips.tip.copypaste"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//FAWE end
|
|
|
|
|
2020-04-12 02:38:46 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/paste",
|
|
|
|
aliases = {"/p", "/pa"},
|
|
|
|
desc = "Paste the clipboard's contents"
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.paste")
|
|
|
|
@Logging(PLACEMENT)
|
2021-07-24 15:34:05 +00:00
|
|
|
public void paste(
|
|
|
|
Actor actor, World world, LocalSession session, EditSession editSession,
|
|
|
|
@Switch(name = 'a', desc = "Skip air blocks")
|
|
|
|
boolean ignoreAirBlocks,
|
|
|
|
@Switch(name = 'o', desc = "Paste at the original position")
|
|
|
|
boolean atOrigin,
|
|
|
|
@Switch(name = 's', desc = "Select the region after pasting")
|
|
|
|
boolean selectPasted,
|
|
|
|
@Switch(name = 'n', desc = "No paste, select only. (Implies -s)")
|
|
|
|
boolean onlySelect,
|
|
|
|
@Switch(name = 'e', desc = "Paste entities if available")
|
|
|
|
boolean pasteEntities,
|
|
|
|
@Switch(name = 'b', desc = "Paste biomes if available")
|
|
|
|
boolean pasteBiomes,
|
|
|
|
@ArgFlag(name = 'm', desc = "Only paste blocks matching this mask")
|
|
|
|
@ClipboardMask
|
|
|
|
Mask sourceMask
|
|
|
|
) throws WorldEditException {
|
2019-06-25 13:00:44 +00:00
|
|
|
|
2014-07-02 09:56:21 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
2018-08-12 14:03:07 +00:00
|
|
|
if (holder.getTransform().isIdentity() && editSession.getSourceMask() == null) {
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start - use place
|
2020-04-23 16:01:17 +00:00
|
|
|
place(actor, world, session, editSession, ignoreAirBlocks, atOrigin, selectPasted,
|
2021-07-24 15:34:05 +00:00
|
|
|
pasteEntities, pasteBiomes
|
|
|
|
);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2018-08-12 14:03:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-07-02 09:56:21 +00:00
|
|
|
Clipboard clipboard = holder.getClipboard();
|
|
|
|
Region region = clipboard.getRegion();
|
2019-10-13 11:47:26 +00:00
|
|
|
List<Component> messages = Lists.newArrayList();
|
2019-06-25 13:00:44 +00:00
|
|
|
|
2019-10-09 20:15:26 +00:00
|
|
|
BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(actor);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start
|
2019-10-09 20:15:26 +00:00
|
|
|
checkPaste(actor, editSession, to, holder, clipboard);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2019-11-11 22:34:33 +00:00
|
|
|
|
2019-11-21 07:57:32 +00:00
|
|
|
if (!onlySelect) {
|
2020-10-05 17:41:41 +00:00
|
|
|
Operation operation = holder
|
|
|
|
.createPaste(editSession)
|
|
|
|
.to(to)
|
|
|
|
.ignoreAirBlocks(ignoreAirBlocks)
|
|
|
|
.copyBiomes(pasteBiomes)
|
|
|
|
.copyEntities(pasteEntities)
|
|
|
|
.maskSource(sourceMask)
|
2019-11-21 07:57:32 +00:00
|
|
|
.build();
|
|
|
|
Operations.completeLegacy(operation);
|
2020-04-23 16:01:17 +00:00
|
|
|
messages.addAll(Lists.newArrayList(operation.getStatusMessages()));
|
2019-11-21 07:57:32 +00:00
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2019-11-09 16:41:18 +00:00
|
|
|
if (selectPasted || onlySelect) {
|
2020-04-12 02:38:46 +00:00
|
|
|
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
|
|
|
Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3()));
|
2021-07-24 15:34:05 +00:00
|
|
|
Vector3 max = realTo.add(holder
|
|
|
|
.getTransform()
|
|
|
|
.apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()));
|
2020-04-12 02:38:46 +00:00
|
|
|
RegionSelector selector = new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
|
2019-10-09 20:15:26 +00:00
|
|
|
session.setRegionSelector(world, selector);
|
2014-06-30 00:47:08 +00:00
|
|
|
selector.learnChanges();
|
2019-10-09 20:15:26 +00:00
|
|
|
selector.explainRegionAdjust(actor, session);
|
2019-11-21 13:50:05 +00:00
|
|
|
}
|
2020-04-12 02:38:46 +00:00
|
|
|
|
2020-04-23 16:01:17 +00:00
|
|
|
if (onlySelect) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.paste.selected"));
|
2019-11-09 16:41:18 +00:00
|
|
|
} else {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.paste.pasted", TextComponent.of(to.toString())));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
2020-04-23 16:01:17 +00:00
|
|
|
messages.forEach(actor::print);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start
|
2019-10-09 20:15:26 +00:00
|
|
|
private void checkPaste(Actor player, EditSession editSession, BlockVector3 to, ClipboardHolder holder, Clipboard clipboard) {
|
2018-08-12 14:03:07 +00:00
|
|
|
URI uri = null;
|
2019-07-06 00:46:48 +00:00
|
|
|
if (holder instanceof URIClipboardHolder) {
|
|
|
|
uri = ((URIClipboardHolder) holder).getURI(clipboard);
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
PasteEvent event = new PasteEvent(player, clipboard, uri, editSession, to);
|
2019-11-20 00:11:54 +00:00
|
|
|
WorldEdit.getInstance().getEventBus().post(event);
|
2019-07-06 00:46:48 +00:00
|
|
|
if (event.isCancelled()) {
|
2021-09-01 14:36:03 +00:00
|
|
|
throw FaweCache.MANUAL;
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2014-07-02 09:56:21 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/rotate",
|
|
|
|
desc = "Rotate the contents of the clipboard",
|
|
|
|
descFooter = "Non-destructively rotate the contents of the clipboard.\n"
|
|
|
|
+ "Angles are provided in degrees and a positive angle will result in a clockwise rotation. "
|
|
|
|
+ "Multiple rotations can be stacked. Interpolation is not performed so angles should be a multiple of 90 degrees.\n"
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.rotate")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void rotate(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "Amount to rotate on the y-axis")
|
|
|
|
double rotateY,
|
|
|
|
@Arg(desc = "Amount to rotate on the x-axis", def = "0")
|
|
|
|
double rotateX,
|
|
|
|
@Arg(desc = "Amount to rotate on the z-axis", def = "0")
|
|
|
|
double rotateZ
|
|
|
|
) throws WorldEditException {
|
2014-07-02 09:56:21 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
AffineTransform transform = new AffineTransform();
|
2020-10-05 17:41:41 +00:00
|
|
|
transform = transform.rotateY(-rotateY);
|
|
|
|
transform = transform.rotateX(-rotateX);
|
|
|
|
transform = transform.rotateZ(-rotateZ);
|
2021-01-11 13:18:24 +00:00
|
|
|
holder.setTransform(transform.combine(holder.getTransform()));
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.rotate.rotated"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/flip",
|
|
|
|
desc = "Flip the contents of the clipboard across the origin"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.flip")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void flip(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The direction to flip, defaults to look direction.", def = Direction.AIM)
|
|
|
|
@Direction BlockVector3 direction
|
|
|
|
) throws WorldEditException {
|
2014-07-02 09:56:21 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
AffineTransform transform = new AffineTransform();
|
2019-01-09 07:13:44 +00:00
|
|
|
transform = transform.scale(direction.abs().multiply(-2).add(1, 1, 1).toVector3());
|
2021-01-11 13:18:24 +00:00
|
|
|
holder.setTransform(transform.combine(holder.getTransform()));
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.flip.flipped"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "clearclipboard",
|
|
|
|
aliases = {"/clearclipboard", "/cc", "/clearclip"},
|
|
|
|
desc = "Clear your clipboard"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.clear")
|
2019-10-09 20:15:26 +00:00
|
|
|
public void clearClipboard(Actor actor, LocalSession session) throws WorldEditException {
|
2021-09-27 13:39:21 +00:00
|
|
|
//FAWE start - delete DOC
|
|
|
|
ClipboardHolder holder = session.getExistingClipboard();
|
|
|
|
if (holder == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (Clipboard clipboard : holder.getClipboards()) {
|
|
|
|
DiskOptimizedClipboard doc;
|
|
|
|
if (clipboard instanceof DiskOptimizedClipboard) {
|
|
|
|
doc = (DiskOptimizedClipboard) clipboard;
|
|
|
|
} else if (clipboard instanceof BlockArrayClipboard && ((BlockArrayClipboard) clipboard).getParent() instanceof DiskOptimizedClipboard) {
|
|
|
|
doc = (DiskOptimizedClipboard) ((BlockArrayClipboard) clipboard).getParent();
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
doc.close(); // Ensure closed before deletion
|
|
|
|
doc.getFile().delete();
|
|
|
|
}
|
|
|
|
//FAWE end
|
2014-07-09 21:14:17 +00:00
|
|
|
session.setClipboard(null);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.clearclipboard.cleared"));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|