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;
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.Vector;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
|
|
|
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;
|
|
|
|
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;
|
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;
|
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;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.util.command.binding.Switch;
|
|
|
|
import com.sk89q.worldedit.util.command.parametric.Optional;
|
2014-04-05 09:59:38 +00:00
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2014-04-05 09:59:38 +00:00
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
|
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clipboard commands.
|
|
|
|
*/
|
|
|
|
public class ClipboardCommands {
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
private final WorldEdit worldEdit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public ClipboardCommands(WorldEdit worldEdit) {
|
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/copy" },
|
2014-07-02 19:55:18 +00:00
|
|
|
flags = "em",
|
2014-04-03 02:08:50 +00:00
|
|
|
desc = "Copy the selection to the clipboard",
|
|
|
|
help = "Copy the selection to the clipboard\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -e controls whether entities are copied\n" +
|
2014-07-02 19:55:18 +00:00
|
|
|
" -m sets a source mask so that excluded blocks become air\n" +
|
2014-04-03 02:08:50 +00:00
|
|
|
"WARNING: Pasting entities cannot yet be undone!",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.copy")
|
2014-06-30 00:47:08 +00:00
|
|
|
public void copy(Player player, LocalSession session, EditSession editSession,
|
2014-07-02 19:55:18 +00:00
|
|
|
@Selection Region region, @Switch('e') boolean copyEntities,
|
|
|
|
@Switch('m') Mask mask) throws WorldEditException {
|
2014-06-28 08:01:49 +00:00
|
|
|
|
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());
|
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);
|
2014-07-09 21:14:17 +00:00
|
|
|
session.setClipboard(new ClipboardHolder(clipboard, editSession.getWorld().getWorldData()));
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
player.print(region.getArea() + " block(s) were copied.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/cut" },
|
2014-07-02 19:55:18 +00:00
|
|
|
flags = "em",
|
2014-04-03 02:08:50 +00:00
|
|
|
usage = "[leave-id]",
|
|
|
|
desc = "Cut the selection to the clipboard",
|
|
|
|
help = "Copy the selection to the clipboard\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -e controls whether entities are copied\n" +
|
2014-07-02 19:55:18 +00:00
|
|
|
" -m sets a source mask so that excluded blocks become air\n" +
|
2014-04-03 02:08:50 +00:00
|
|
|
"WARNING: Cutting and pasting entities cannot yet be undone!",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.cut")
|
|
|
|
@Logging(REGION)
|
2014-06-30 00:47:08 +00:00
|
|
|
public void cut(Player player, LocalSession session, EditSession editSession,
|
2014-07-02 19:55:18 +00:00
|
|
|
@Selection Region region, @Optional("air") Pattern leavePattern, @Switch('e') boolean copyEntities,
|
|
|
|
@Switch('m') 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));
|
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);
|
2014-07-09 21:14:17 +00:00
|
|
|
session.setClipboard(new ClipboardHolder(clipboard, editSession.getWorld().getWorldData()));
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
player.print(region.getArea() + " block(s) were copied.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/paste" },
|
|
|
|
usage = "",
|
|
|
|
flags = "sao",
|
|
|
|
desc = "Paste the clipboard's contents",
|
|
|
|
help =
|
|
|
|
"Pastes the clipboard's contents.\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -a skips air blocks\n" +
|
|
|
|
" -o pastes at the original position\n" +
|
|
|
|
" -s selects the region after pasting",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.paste")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-30 00:47:08 +00:00
|
|
|
public void paste(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Switch('a') boolean ignoreAirBlocks, @Switch('o') boolean atOrigin,
|
|
|
|
@Switch('s') boolean selectPasted) throws WorldEditException {
|
|
|
|
|
2014-07-02 09:56:21 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
Clipboard clipboard = holder.getClipboard();
|
|
|
|
Region region = clipboard.getRegion();
|
|
|
|
|
|
|
|
Vector to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player);
|
2014-07-09 21:14:17 +00:00
|
|
|
Operation operation = holder
|
|
|
|
.createPaste(editSession, editSession.getWorld().getWorldData())
|
|
|
|
.to(to)
|
|
|
|
.ignoreAirBlocks(ignoreAirBlocks)
|
|
|
|
.build();
|
|
|
|
Operations.completeLegacy(operation);
|
2014-06-30 00:47:08 +00:00
|
|
|
|
|
|
|
if (selectPasted) {
|
|
|
|
Vector max = to.add(region.getMaximumPoint().subtract(region.getMinimumPoint()));
|
|
|
|
RegionSelector selector = new CuboidRegionSelector(player.getWorld(), to, max);
|
|
|
|
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);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/rotate" },
|
2014-07-02 09:56:21 +00:00
|
|
|
usage = "<y-axis> [<x-axis>] [<z-axis>]",
|
2014-04-03 02:08:50 +00:00
|
|
|
desc = "Rotate the contents of the clipboard",
|
2014-07-02 09:56:21 +00:00
|
|
|
help = "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")
|
2014-07-02 09:56:21 +00:00
|
|
|
public void rotate(Player player, LocalSession session, Double yRotate, @Optional Double xRotate, @Optional Double zRotate) throws WorldEditException {
|
|
|
|
if ((yRotate != null && Math.abs(yRotate % 90) > 0.001) ||
|
|
|
|
xRotate != null && Math.abs(xRotate % 90) > 0.001 ||
|
|
|
|
zRotate != null && Math.abs(zRotate % 90) > 0.001) {
|
|
|
|
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();
|
|
|
|
transform = transform.rotateY(Math.toRadians(yRotate != null ? yRotate : 0));
|
|
|
|
transform = transform.rotateX(Math.toRadians(xRotate != null ? xRotate : 0));
|
|
|
|
transform = transform.rotateZ(Math.toRadians(zRotate != null ? zRotate : 0));
|
|
|
|
holder.setTransform(holder.getTransform().combine(transform));
|
|
|
|
player.print("The clipboard copy has been rotated.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/flip" },
|
2014-07-02 09:56:21 +00:00
|
|
|
usage = "[<direction>]",
|
|
|
|
desc = "Flip the contents of the clipboard",
|
2014-04-03 02:08:50 +00:00
|
|
|
help =
|
2014-07-02 09:56:21 +00:00
|
|
|
"Flips the contents of the clipboard across the point from which the copy was made.\n",
|
2014-04-03 02:08:50 +00:00
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.flip")
|
2014-07-02 09:56:21 +00:00
|
|
|
public void flip(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Optional(Direction.AIM) @Direction Vector direction) throws WorldEditException {
|
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
Clipboard clipboard = holder.getClipboard();
|
|
|
|
AffineTransform transform = new AffineTransform();
|
|
|
|
transform = transform.scale(direction.positive().multiply(-2).add(1, 1, 1));
|
|
|
|
holder.setTransform(holder.getTransform().combine(transform));
|
|
|
|
player.print("The clipboard copy has been flipped.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/load" },
|
|
|
|
usage = "<filename>",
|
|
|
|
desc = "Load a schematic into your clipboard",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@Deprecated
|
|
|
|
@CommandPermissions("worldedit.clipboard.load")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void load(Actor actor) {
|
|
|
|
actor.printError("This command is no longer used. See //schematic load.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/save" },
|
|
|
|
usage = "<filename>",
|
|
|
|
desc = "Save a schematic into your clipboard",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@Deprecated
|
|
|
|
@CommandPermissions("worldedit.clipboard.save")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void save(Actor actor) {
|
|
|
|
actor.printError("This command is no longer used. See //schematic save.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "clearclipboard" },
|
|
|
|
usage = "",
|
|
|
|
desc = "Clear your clipboard",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.clipboard.clear")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void clearClipboard(Player player, LocalSession session, EditSession editSession) 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.");
|
|
|
|
}
|
|
|
|
}
|