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
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser 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.
|
|
|
|
*
|
2014-04-04 22:03:18 +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 Lesser General Public License
|
|
|
|
* for more details.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://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;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.FaweAPI;
|
2019-10-23 14:35:04 +00:00
|
|
|
import com.boydti.fawe.FaweCache;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.config.BBC;
|
|
|
|
import com.boydti.fawe.config.Settings;
|
|
|
|
import com.boydti.fawe.object.FaweLimit;
|
|
|
|
import com.boydti.fawe.object.RunnableVal;
|
|
|
|
import com.boydti.fawe.object.clipboard.MultiClipboardHolder;
|
|
|
|
import com.boydti.fawe.object.clipboard.ReadOnlyClipboard;
|
|
|
|
import com.boydti.fawe.object.clipboard.URIClipboardHolder;
|
|
|
|
import com.boydti.fawe.object.clipboard.WorldCutClipboard;
|
|
|
|
import com.boydti.fawe.object.exception.FaweException;
|
|
|
|
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
|
|
|
|
import com.boydti.fawe.util.ImgurUtility;
|
|
|
|
import com.boydti.fawe.util.MainUtil;
|
|
|
|
import com.boydti.fawe.util.MaskTraverser;
|
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;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
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;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.event.extent.PasteEvent;
|
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;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Masks;
|
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;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
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-09 20:15:26 +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;
|
|
|
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
|
|
|
|
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.net.URLEncoder;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipOutputStream;
|
2019-11-02 11:13:42 +00:00
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2019-07-18 06:56:57 +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
|
|
|
|
2019-07-22 02:49:08 +00:00
|
|
|
private WorldEdit worldEdit;
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public ClipboardCommands(WorldEdit worldEdit) {
|
2019-06-25 13:00:44 +00:00
|
|
|
checkNotNull(worldEdit);
|
2019-07-22 02:49:08 +00:00
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/copy",
|
2019-10-23 04:23:52 +00:00
|
|
|
aliases = "/cp",
|
2019-07-06 00:46:48 +00:00
|
|
|
desc = "Copy the selection to the clipboard"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.copy")
|
2019-10-09 20:15:26 +00:00
|
|
|
public void copy(Actor actor, LocalSession session, EditSession editSession,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Selection Region region,
|
2019-07-17 10:50:54 +00:00
|
|
|
@Switch(name = 'e', desc = "Skip copy entities")
|
|
|
|
boolean skipEntities,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Switch(name = 'b', desc = "Also copy biomes")
|
|
|
|
boolean copyBiomes,
|
|
|
|
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
|
2019-10-09 20:15:26 +00:00
|
|
|
Mask mask, InjectedValueAccess context) 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 =
|
|
|
|
((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) {
|
2019-10-23 14:35:04 +00:00
|
|
|
throw FaweCache.MAX_CHECKS;
|
2018-09-07 15:31:30 +00:00
|
|
|
}
|
2019-10-09 20:15:26 +00:00
|
|
|
actor.checkConfirmationRegion(() -> {
|
2018-09-07 15:09:31 +00:00
|
|
|
session.setClipboard(null);
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2019-10-09 20:15:26 +00:00
|
|
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2018-09-07 15:09:31 +00:00
|
|
|
session.setClipboard(new ClipboardHolder(clipboard));
|
2014-06-28 08:01:49 +00:00
|
|
|
|
2019-10-09 20:15:26 +00:00
|
|
|
clipboard.setOrigin(session.getPlacementPosition(actor));
|
2018-09-07 15:09:31 +00:00
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
2019-07-17 10:50:54 +00:00
|
|
|
copy.setCopyingEntities(!skipEntities);
|
2019-07-06 00:46:48 +00:00
|
|
|
copy.setCopyingBiomes(copyBiomes);
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2018-09-07 15:09:31 +00:00
|
|
|
Mask sourceMask = editSession.getSourceMask();
|
|
|
|
if (sourceMask != null) {
|
|
|
|
new MaskTraverser(sourceMask).reset(editSession);
|
|
|
|
copy.setSourceMask(sourceMask);
|
|
|
|
editSession.setSourceMask(null);
|
|
|
|
}
|
2019-10-09 20:15:26 +00:00
|
|
|
if (mask != null && mask != Masks.alwaysTrue()) {
|
|
|
|
copy.setSourceMask(mask);
|
2018-09-07 15:09:31 +00:00
|
|
|
}
|
|
|
|
Operations.completeLegacy(copy);
|
2019-10-09 20:15:26 +00:00
|
|
|
BBC.COMMAND_COPY.send(actor, region.getArea());
|
|
|
|
if (!actor.hasPermission("fawe.tips")) {
|
|
|
|
BBC.TIP_PASTE.or(BBC.TIP_DOWNLOAD, BBC.TIP_ROTATE, BBC.TIP_COPYPASTE, BBC.TIP_REPLACE_MARKER, BBC.TIP_COPY_PATTERN).send(actor);
|
2018-09-07 15:09:31 +00:00
|
|
|
}
|
2019-08-06 15:29:49 +00:00
|
|
|
}, "/copy", region, context);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/lazycopy",
|
|
|
|
desc = "Lazily copy the selection to the clipboard"
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.lazycopy")
|
2019-10-09 20:15:26 +00:00
|
|
|
public void lazyCopy(Actor actor, LocalSession session, EditSession editSession,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Selection Region region,
|
2019-07-17 10:50:54 +00:00
|
|
|
@Switch(name = 'e', desc = "Skip copy entities")
|
|
|
|
boolean skipEntities,
|
2019-07-06 00:46:48 +00:00
|
|
|
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
|
2019-08-06 20:18:44 +00:00
|
|
|
Mask maskOpt,
|
2019-07-06 00:46:48 +00:00
|
|
|
@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));
|
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) {
|
|
|
|
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
|
|
|
|
}
|
|
|
|
session.setClipboard(null);
|
2019-07-17 10:50:54 +00:00
|
|
|
ReadOnlyClipboard lazyClipboard = ReadOnlyClipboard.of(editSession, region, !skipEntities, copyBiomes);
|
2019-07-06 00:46:48 +00:00
|
|
|
|
|
|
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, lazyClipboard);
|
2019-10-09 20:15:26 +00:00
|
|
|
clipboard.setOrigin(session.getPlacementPosition(actor));
|
2019-07-06 00:46:48 +00:00
|
|
|
session.setClipboard(new ClipboardHolder(clipboard));
|
2019-10-09 20:15:26 +00:00
|
|
|
BBC.COMMAND_COPY.send(actor, region.getArea());
|
|
|
|
if (!actor.hasPermission("fawe.tips")) {
|
|
|
|
BBC.TIP_PASTE.or(BBC.TIP_LAZYCOPY, BBC.TIP_DOWNLOAD, BBC.TIP_ROTATE, BBC.TIP_COPYPASTE, BBC.TIP_REPLACE_MARKER, BBC.TIP_COPY_PATTERN).send(actor);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
name = "/lazycut",
|
|
|
|
desc = "Lazily cut the selection to the clipboard"
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.lazycut")
|
2019-10-09 20:15:26 +00:00
|
|
|
public void lazyCut(Actor actor, LocalSession session, EditSession editSession,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Selection final Region region,
|
2019-07-17 10:50:54 +00:00
|
|
|
@Switch(name = 'e', desc = "Skip copy entities")
|
|
|
|
boolean skipEntities,
|
2019-07-06 00:46:48 +00:00
|
|
|
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
|
2019-08-06 20:18:44 +00:00
|
|
|
Mask maskOpt,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Switch(name = 'b', desc = "Also copy biomes")
|
|
|
|
boolean copyBiomes) throws WorldEditException {
|
|
|
|
BlockVector3 min = region.getMinimumPoint();
|
|
|
|
BlockVector3 max = region.getMaximumPoint();
|
2019-10-09 20:15:26 +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);
|
|
|
|
FaweLimit limit = actor.getLimit();
|
2018-08-12 14:03:07 +00:00
|
|
|
if (volume >= limit.MAX_CHECKS) {
|
2019-10-23 14:35:04 +00:00
|
|
|
throw FaweCache.MAX_CHECKS;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
if (volume >= limit.MAX_CHANGES) {
|
2019-10-23 14:35:04 +00:00
|
|
|
throw FaweCache.MAX_CHANGES;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
session.setClipboard(null);
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2019-07-17 10:50:54 +00:00
|
|
|
ReadOnlyClipboard lazyClipboard = new WorldCutClipboard(editSession, region, !skipEntities, copyBiomes);
|
2018-08-12 14:03:07 +00:00
|
|
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, lazyClipboard);
|
2019-10-09 20:15:26 +00:00
|
|
|
clipboard.setOrigin(session.getPlacementPosition(actor));
|
2018-08-12 14:03:07 +00:00
|
|
|
session.setClipboard(new ClipboardHolder(clipboard));
|
2019-10-09 20:15:26 +00:00
|
|
|
BBC.COMMAND_CUT_LAZY.send(actor, region.getArea());
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/cut",
|
2019-06-25 13:00:44 +00:00
|
|
|
desc = "Cut the selection to the clipboard",
|
2019-07-06 00:46:48 +00:00
|
|
|
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)
|
2019-10-09 20:15:26 +00:00
|
|
|
public void cut(Actor actor, LocalSession session, EditSession editSession,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "Pattern to leave in place of the selection", def = "air")
|
|
|
|
Pattern leavePattern,
|
2019-07-25 18:44:10 +00:00
|
|
|
@Switch(name = 'e', desc = "Skip cut entities")
|
2019-07-17 10:50:54 +00:00
|
|
|
boolean skipEntities,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Switch(name = 'b', desc = "Also copy biomes, source biomes are unaffected")
|
|
|
|
boolean copyBiomes,
|
|
|
|
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
|
2019-10-09 20:15:26 +00:00
|
|
|
Mask mask,
|
2019-07-18 20:03:27 +00:00
|
|
|
InjectedValueAccess context) 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
|
|
|
|
2018-09-07 15:31:30 +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) {
|
2019-10-23 14:35:04 +00:00
|
|
|
throw FaweCache.MAX_CHECKS;
|
2018-09-07 15:31:30 +00:00
|
|
|
}
|
|
|
|
if (volume >= limit.MAX_CHANGES) {
|
2019-10-23 14:35:04 +00:00
|
|
|
throw FaweCache.MAX_CHANGES;
|
2018-09-07 15:31:30 +00:00
|
|
|
}
|
2019-10-09 20:15:26 +00:00
|
|
|
actor.checkConfirmationRegion(() -> {
|
2018-09-07 15:09:31 +00:00
|
|
|
session.setClipboard(null);
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2019-10-09 20:15:26 +00:00
|
|
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
|
|
|
|
clipboard.setOrigin(session.getPlacementPosition(actor));
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2018-09-07 15:09:31 +00:00
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
|
|
|
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
|
2019-07-22 02:49:08 +00:00
|
|
|
copy.setCopyingEntities(!skipEntities);
|
2019-06-23 18:00:22 +00:00
|
|
|
copy.setRemovingEntities(true);
|
2019-07-06 00:46:48 +00:00
|
|
|
copy.setCopyingBiomes(copyBiomes);
|
2018-09-07 15:09:31 +00:00
|
|
|
Mask sourceMask = editSession.getSourceMask();
|
|
|
|
if (sourceMask != null) {
|
|
|
|
new MaskTraverser(sourceMask).reset(editSession);
|
|
|
|
copy.setSourceMask(sourceMask);
|
|
|
|
editSession.setSourceMask(null);
|
|
|
|
}
|
2019-10-09 20:15:26 +00:00
|
|
|
if (mask != null) {
|
|
|
|
copy.setSourceMask(mask);
|
2018-09-07 15:09:31 +00:00
|
|
|
}
|
|
|
|
Operations.completeLegacy(copy);
|
|
|
|
session.setClipboard(new ClipboardHolder(clipboard));
|
|
|
|
|
2019-10-09 20:15:26 +00:00
|
|
|
BBC.COMMAND_CUT_SLOW.send(actor, region.getArea());
|
|
|
|
if (!actor.hasPermission("fawe.tips")) {
|
|
|
|
BBC.TIP_LAZYCUT.send(actor);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
2019-08-06 15:29:49 +00:00
|
|
|
}, "cut", region, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2019-06-23 18:00:22 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "download",
|
2019-06-23 18:00:22 +00:00
|
|
|
desc = "Downloads your clipboard through the configured web interface"
|
|
|
|
)
|
2018-08-12 14:03:07 +00:00
|
|
|
@Deprecated
|
|
|
|
@CommandPermissions({"worldedit.clipboard.download"})
|
2019-07-17 06:11:55 +00:00
|
|
|
public void download(final Player player, final LocalSession session, @Arg(name = "format", desc = "String", def = "schem") 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) {
|
|
|
|
BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BBC.GENERATING_LINK.send(player, formatName);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final LocalConfiguration config = this.worldEdit.getConfiguration();
|
|
|
|
final File working = this.worldEdit.getWorkingDirectoryFile(config.saveDir).getAbsoluteFile();
|
|
|
|
|
|
|
|
url = MainUtil.upload(null, null, "zip", new RunnableVal<OutputStream>() {
|
|
|
|
@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);
|
|
|
|
target = new BlockArrayClipboard(result.getTransformedRegion(), player.getUniqueId());
|
|
|
|
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()) {
|
|
|
|
BBC.SETTING_DISABLE.send(player, "web.url");
|
|
|
|
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) {
|
2019-11-02 19:53:25 +00:00
|
|
|
player.printError(BBC.GENERATING_LINK_FAILED.s());
|
2019-10-23 14:35:04 +00:00
|
|
|
} else {
|
|
|
|
String urlText = url.toString();
|
|
|
|
if (Settings.IMP.WEB.SHORTEN_URLS) {
|
|
|
|
try {
|
|
|
|
urlText = MainUtil.getText("https://empcraft.com/s/?" + URLEncoder.encode(url.toString(), "UTF-8"));
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-23 14:35:04 +00:00
|
|
|
BBC.DOWNLOAD_LINK.send(player, urlText);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "asset",
|
2019-07-17 05:43:18 +00:00
|
|
|
desc = "Saves your clipboard to the asset web interface"
|
|
|
|
)
|
2018-08-12 14:03:07 +00:00
|
|
|
@CommandPermissions({"worldedit.clipboard.asset"})
|
2019-07-06 00:46:48 +00:00
|
|
|
public void asset(final Player player, final LocalSession session, String category) throws WorldEditException {
|
2019-01-31 15:08:58 +00:00
|
|
|
final ClipboardFormat format = BuiltInClipboardFormat.MCEDIT_SCHEMATIC;
|
2018-08-12 14:03:07 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
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);
|
|
|
|
target = new BlockArrayClipboard(result.getTransformedRegion(), player.getUniqueId());
|
|
|
|
target.setOrigin(clipboard.getOrigin());
|
|
|
|
Operations.completeLegacy(result.copyTo(target));
|
|
|
|
} else {
|
|
|
|
target = clipboard;
|
|
|
|
}
|
2019-01-31 15:08:58 +00:00
|
|
|
BBC.GENERATING_LINK.send(player, format.getName());
|
2018-08-12 14:03:07 +00:00
|
|
|
if (Settings.IMP.WEB.ASSETS.isEmpty()) {
|
|
|
|
BBC.SETTING_DISABLE.send(player, "web.assets");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
URL url = format.uploadPublic(target, category.replaceAll("[/|\\\\]", "."), player.getName());
|
|
|
|
if (url == null) {
|
2019-11-02 19:53:25 +00:00
|
|
|
player.printError(BBC.GENERATING_LINK_FAILED.s());
|
2018-08-12 14:03:07 +00:00
|
|
|
} else {
|
|
|
|
BBC.DOWNLOAD_LINK.send(player, Settings.IMP.WEB.ASSETS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/paste",
|
2019-10-23 04:23:52 +00:00
|
|
|
aliases = { "/p", "/pa" },
|
2019-07-06 00:46:48 +00:00
|
|
|
desc = "Paste the clipboard's contents"
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.paste")
|
|
|
|
@Logging(PLACEMENT)
|
2019-10-09 20:15:26 +00:00
|
|
|
public void paste(Actor actor, World world, LocalSession session, EditSession editSession,
|
2019-07-06 00:46:48 +00:00
|
|
|
@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,
|
|
|
|
@ArgFlag(name = 'm', desc = "Only paste blocks matching this mask", def = "")
|
2019-08-15 19:21:24 +00:00
|
|
|
@ClipboardMask
|
2019-07-06 00:46:48 +00:00
|
|
|
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) {
|
2019-10-09 20:15:26 +00:00
|
|
|
place(actor, world, session, editSession, ignoreAirBlocks, atOrigin, selectPasted);
|
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-06-25 13:00:44 +00:00
|
|
|
|
2019-10-09 20:15:26 +00:00
|
|
|
BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(actor);
|
|
|
|
checkPaste(actor, editSession, to, holder, clipboard);
|
2014-07-09 21:14:17 +00:00
|
|
|
Operation operation = holder
|
2018-06-19 00:53:15 +00:00
|
|
|
.createPaste(editSession)
|
2014-07-09 21:14:17 +00:00
|
|
|
.to(to)
|
|
|
|
.ignoreAirBlocks(ignoreAirBlocks)
|
2019-07-06 00:46:48 +00:00
|
|
|
.copyBiomes(pasteBiomes)
|
|
|
|
.copyEntities(pasteEntities)
|
|
|
|
.maskSource(sourceMask)
|
2014-07-09 21:14:17 +00:00
|
|
|
.build();
|
|
|
|
Operations.completeLegacy(operation);
|
2014-06-30 00:47:08 +00:00
|
|
|
|
|
|
|
if (selectPasted) {
|
2018-12-23 16:19:33 +00:00
|
|
|
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
|
|
|
Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3()));
|
|
|
|
Vector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()));
|
2019-10-09 20:15:26 +00:00
|
|
|
RegionSelector selector = new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
|
|
|
|
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);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2019-10-09 20:15:26 +00:00
|
|
|
BBC.COMMAND_PASTE.send(actor, to);
|
|
|
|
if (!actor.hasPermission("fawe.tips")) {
|
|
|
|
BBC.TIP_COPYPASTE.or(BBC.TIP_SOURCE_MASK, BBC.TIP_REPLACE_MARKER).send(actor, to);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
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);
|
|
|
|
worldEdit.getEventBus().post(event);
|
2019-07-06 00:46:48 +00:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/place",
|
2019-07-17 05:43:18 +00:00
|
|
|
desc = "Place the clipboard's contents without applying transformations (e.g. rotate)"
|
|
|
|
)
|
2019-07-18 06:56:57 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.place")
|
|
|
|
@Logging(PLACEMENT)
|
2019-10-09 20:15:26 +00:00
|
|
|
public void place(Actor actor, World world, LocalSession session, final EditSession editSession,
|
2019-07-06 00:46:48 +00:00
|
|
|
@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) throws WorldEditException {
|
2018-08-12 14:03:07 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
final Clipboard clipboard = holder.getClipboard();
|
2019-01-09 07:13:44 +00:00
|
|
|
final BlockVector3 origin = clipboard.getOrigin();
|
2019-10-09 20:15:26 +00:00
|
|
|
final BlockVector3 to = atOrigin ? origin : session.getPlacementPosition(actor);
|
|
|
|
checkPaste(actor, editSession, to, holder, clipboard);
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2019-11-02 11:13:42 +00:00
|
|
|
clipboard.paste(editSession, to, !ignoreAirBlocks);
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
Region region = clipboard.getRegion().clone();
|
|
|
|
if (selectPasted) {
|
2019-07-06 00:46:48 +00:00
|
|
|
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
|
|
|
BlockVector3 realTo = to.add(holder.getTransform().apply(clipboardOffset.toVector3()).toBlockPoint());
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()).toBlockPoint());
|
2019-10-09 20:15:26 +00:00
|
|
|
RegionSelector selector = new CuboidRegionSelector(world, realTo, max);
|
|
|
|
session.setRegionSelector(world, selector);
|
2018-08-12 14:03:07 +00:00
|
|
|
selector.learnChanges();
|
2019-10-09 20:15:26 +00:00
|
|
|
selector.explainRegionAdjust(actor, session);
|
2014-07-02 09:56:21 +00:00
|
|
|
}
|
2019-10-09 20:15:26 +00:00
|
|
|
BBC.COMMAND_PASTE.send(actor, to);
|
2019-06-23 18:00:22 +00:00
|
|
|
|
2019-10-09 20:15:26 +00:00
|
|
|
if (!actor.hasPermission("fawe.tips")) {
|
2019-10-23 16:58:36 +00:00
|
|
|
actor.print(BBC.TIP_COPYPASTE.s());
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-02 09:56:21 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/rotate",
|
2019-10-30 11:26:52 +00:00
|
|
|
aliases = {"/rt"},
|
2019-06-25 13:00:44 +00:00
|
|
|
desc = "Rotate the contents of the clipboard",
|
2019-07-06 00:46:48 +00:00
|
|
|
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")
|
2019-10-09 20:15:26 +00:00
|
|
|
public void rotate(Actor actor, LocalSession session,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Arg(desc = "Amount to rotate on the y-axis")
|
|
|
|
double yRotate,
|
|
|
|
@Arg(desc = "Amount to rotate on the x-axis", def = "0")
|
|
|
|
double xRotate,
|
|
|
|
@Arg(desc = "Amount to rotate on the z-axis", def = "0")
|
|
|
|
double zRotate) throws WorldEditException {
|
2014-07-02 09:56:21 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
AffineTransform transform = new AffineTransform();
|
2019-07-06 00:46:48 +00:00
|
|
|
transform = transform.rotateY(-yRotate);
|
|
|
|
transform = transform.rotateX(-xRotate);
|
|
|
|
transform = transform.rotateZ(-zRotate);
|
2019-06-23 18:00:22 +00:00
|
|
|
holder.setTransform(holder.getTransform().combine(transform));
|
2019-10-09 20:15:26 +00:00
|
|
|
actor.print(BBC.COMMAND_ROTATE.s());
|
|
|
|
if (!actor.hasPermission("fawe.tips")) {
|
|
|
|
BBC.TIP_FLIP.or(BBC.TIP_DEFORM, BBC.TIP_TRANSFORM).send(actor);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +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")
|
2019-10-09 20:15:26 +00:00
|
|
|
public void flip(Actor actor, LocalSession session,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Arg(desc = "The direction to flip, defaults to look direction.", def = Direction.AIM)
|
|
|
|
@Direction BlockVector3 direction) throws WorldEditException {
|
2019-07-18 06:56:57 +00:00
|
|
|
|
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());
|
2019-06-23 18:00:22 +00:00
|
|
|
holder.setTransform(holder.getTransform().combine(transform));
|
2019-10-09 20:15:26 +00:00
|
|
|
actor.print(BBC.COMMAND_FLIPPED.s());
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "clearclipboard",
|
|
|
|
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 {
|
2014-07-09 21:14:17 +00:00
|
|
|
session.setClipboard(null);
|
2019-10-09 20:15:26 +00:00
|
|
|
actor.print(BBC.CLIPBOARD_CLEARED.s());
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|