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;
|
|
|
|
|
2019-04-05 23:40:25 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2018-07-22 05:36:50 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-04-18 19:34:57 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
2019-04-17 06:02:23 +00:00
|
|
|
import com.sk89q.worldedit.command.util.Logging;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
|
|
|
import com.sk89q.worldedit.function.block.BlockReplace;
|
2014-07-02 19:55:18 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
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-10 15:54:22 +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-10-14 10:40:53 +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;
|
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-04-18 19:34:57 +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;
|
|
|
|
|
2019-04-05 23:40:25 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-04-18 19:34:57 +00:00
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
|
2014-04-05 09:59:38 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
/**
|
|
|
|
* Clipboard commands.
|
|
|
|
*/
|
2019-04-18 19:34:57 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
2014-04-03 02:08:50 +00:00
|
|
|
public class ClipboardCommands {
|
|
|
|
|
|
|
|
@Command(
|
2019-04-18 19:34:57 +00:00
|
|
|
name = "/copy",
|
|
|
|
desc = "Copy the selection to the clipboard"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.copy")
|
2014-06-30 00:47:08 +00:00
|
|
|
public void copy(Player player, LocalSession session, EditSession editSession,
|
2019-04-18 19:34:57 +00:00
|
|
|
@Selection Region region,
|
|
|
|
@Switch(name = 'e', desc = "Also copy entities")
|
|
|
|
boolean copyEntities,
|
2019-04-26 08:25:42 +00:00
|
|
|
@Switch(name = 'b', desc = "Also copy biomes")
|
|
|
|
boolean copyBiomes,
|
2019-05-09 20:59:06 +00:00
|
|
|
@ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air", def = "")
|
2019-04-18 19:34:57 +00:00
|
|
|
Mask mask) throws WorldEditException {
|
2014-06-30 00:47:08 +00:00
|
|
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
2014-07-02 09:56:21 +00:00
|
|
|
clipboard.setOrigin(session.getPlacementPosition(player));
|
2014-06-30 00:47:08 +00:00
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
2017-03-19 15:56:04 +00:00
|
|
|
copy.setCopyingEntities(copyEntities);
|
2019-04-04 00:57:51 +00:00
|
|
|
copy.setCopyingBiomes(copyBiomes);
|
2014-07-02 19:55:18 +00:00
|
|
|
if (mask != null) {
|
|
|
|
copy.setSourceMask(mask);
|
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
Operations.completeLegacy(copy);
|
2018-06-19 00:53:15 +00:00
|
|
|
session.setClipboard(new ClipboardHolder(clipboard));
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-04-05 23:40:25 +00:00
|
|
|
List<String> messages = Lists.newArrayList();
|
|
|
|
copy.addStatusMessages(messages);
|
|
|
|
messages.forEach(player::print);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-18 19:34:57 +00:00
|
|
|
name = "/cut",
|
2019-07-03 17:01:59 +00:00
|
|
|
desc = "Cut the selection to the clipboard"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.cut")
|
|
|
|
@Logging(REGION)
|
2014-06-30 00:47:08 +00:00
|
|
|
public void cut(Player player, LocalSession session, EditSession editSession,
|
2019-04-18 19:34:57 +00:00
|
|
|
@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,
|
2019-04-26 08:25:42 +00:00
|
|
|
@Switch(name = 'b', desc = "Also copy biomes, source biomes are unaffected")
|
|
|
|
boolean copyBiomes,
|
2019-07-03 17:01:59 +00:00
|
|
|
@ArgFlag(name = 'm', desc = "Set the exclude mask, non-matching blocks become air", def = "")
|
2019-04-18 19:34:57 +00:00
|
|
|
Mask mask) throws WorldEditException {
|
2014-06-30 00:47:08 +00:00
|
|
|
|
|
|
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
2014-07-02 09:56:21 +00:00
|
|
|
clipboard.setOrigin(session.getPlacementPosition(player));
|
2014-06-30 00:47:08 +00:00
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
|
|
|
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
|
2017-03-19 15:56:04 +00:00
|
|
|
copy.setCopyingEntities(copyEntities);
|
|
|
|
copy.setRemovingEntities(true);
|
2019-04-05 23:40:25 +00:00
|
|
|
copy.setCopyingBiomes(copyBiomes);
|
2014-07-02 19:55:18 +00:00
|
|
|
if (mask != null) {
|
|
|
|
copy.setSourceMask(mask);
|
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
Operations.completeLegacy(copy);
|
2018-06-19 00:53:15 +00:00
|
|
|
session.setClipboard(new ClipboardHolder(clipboard));
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-04-05 23:40:25 +00:00
|
|
|
List<String> messages = Lists.newArrayList();
|
|
|
|
copy.addStatusMessages(messages);
|
|
|
|
messages.forEach(player::print);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-18 19:34:57 +00:00
|
|
|
name = "/paste",
|
|
|
|
desc = "Paste the clipboard's contents"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.paste")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-30 00:47:08 +00:00
|
|
|
public void paste(Player player, LocalSession session, EditSession editSession,
|
2019-04-18 19:34:57 +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")
|
2019-04-26 08:25:42 +00:00
|
|
|
boolean selectPasted,
|
|
|
|
@Switch(name = 'e', desc = "Paste entities if available")
|
|
|
|
boolean pasteEntities,
|
|
|
|
@Switch(name = 'b', desc = "Paste biomes if available")
|
|
|
|
boolean pasteBiomes,
|
2019-05-13 21:40:43 +00:00
|
|
|
@ArgFlag(name = 'm', desc = "Only paste blocks matching this mask", def = "")
|
2019-08-10 15:54:22 +00:00
|
|
|
@ClipboardMask
|
2019-04-26 08:25:42 +00:00
|
|
|
Mask sourceMask) throws WorldEditException {
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2014-07-02 09:56:21 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
Clipboard clipboard = holder.getClipboard();
|
|
|
|
Region region = clipboard.getRegion();
|
|
|
|
|
2018-10-14 10:40:53 +00:00
|
|
|
BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player);
|
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-04-04 00:57:51 +00:00
|
|
|
.copyBiomes(pasteBiomes)
|
2019-04-26 00:48:15 +00:00
|
|
|
.copyEntities(pasteEntities)
|
|
|
|
.maskSource(sourceMask)
|
|
|
|
.build();
|
2014-07-09 21:14:17 +00:00
|
|
|
Operations.completeLegacy(operation);
|
2014-06-30 00:47:08 +00:00
|
|
|
|
|
|
|
if (selectPasted) {
|
2018-10-14 10:40:53 +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()));
|
|
|
|
RegionSelector selector = new CuboidRegionSelector(player.getWorld(), realTo.toBlockPoint(), max.toBlockPoint());
|
2014-06-30 00:47:08 +00:00
|
|
|
session.setRegionSelector(player.getWorld(), selector);
|
|
|
|
selector.learnChanges();
|
|
|
|
selector.explainRegionAdjust(player, session);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2014-07-09 21:14:17 +00:00
|
|
|
player.print("The clipboard has been pasted at " + to);
|
2019-04-05 23:40:25 +00:00
|
|
|
List<String> messages = Lists.newArrayList();
|
|
|
|
operation.addStatusMessages(messages);
|
|
|
|
messages.forEach(player::print);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-18 19:34:57 +00:00
|
|
|
name = "/rotate",
|
2014-04-03 02:08:50 +00:00
|
|
|
desc = "Rotate the contents of the clipboard",
|
2019-04-18 19:34:57 +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"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.rotate")
|
2019-04-18 19:34:57 +00:00
|
|
|
public void rotate(Player player, LocalSession session,
|
|
|
|
@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 {
|
|
|
|
if (Math.abs(yRotate % 90) > 0.001 ||
|
|
|
|
Math.abs(xRotate % 90) > 0.001 ||
|
|
|
|
Math.abs(zRotate % 90) > 0.001) {
|
2014-07-02 09:56:21 +00:00
|
|
|
player.printDebug("Note: Interpolation is not yet supported, so angles that are multiples of 90 is recommended.");
|
|
|
|
}
|
|
|
|
|
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
AffineTransform transform = new AffineTransform();
|
2019-04-18 19:34:57 +00:00
|
|
|
transform = transform.rotateY(-yRotate);
|
|
|
|
transform = transform.rotateX(-xRotate);
|
|
|
|
transform = transform.rotateZ(-zRotate);
|
2014-07-02 09:56:21 +00:00
|
|
|
holder.setTransform(holder.getTransform().combine(transform));
|
|
|
|
player.print("The clipboard copy has been rotated.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-18 19:34:57 +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-03-16 23:04:24 +00:00
|
|
|
public void flip(Player player, LocalSession session,
|
2019-04-18 19:34:57 +00:00
|
|
|
@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();
|
2018-10-14 10:40:53 +00:00
|
|
|
transform = transform.scale(direction.abs().multiply(-2).add(1, 1, 1).toVector3());
|
2014-07-02 09:56:21 +00:00
|
|
|
holder.setTransform(holder.getTransform().combine(transform));
|
|
|
|
player.print("The clipboard copy has been flipped.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-18 19:34:57 +00:00
|
|
|
name = "clearclipboard",
|
|
|
|
desc = "Clear your clipboard"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.clear")
|
2019-03-16 23:04:24 +00:00
|
|
|
public void clearClipboard(Player player, LocalSession session) throws WorldEditException {
|
2014-07-09 21:14:17 +00:00
|
|
|
session.setClipboard(null);
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("Clipboard cleared.");
|
|
|
|
}
|
|
|
|
}
|