2011-01-29 10:05:22 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
2012-01-05 21:38:23 +00:00
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
|
2011-01-29 10:05:22 +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
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.commands;
|
|
|
|
|
2011-02-18 06:53:44 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
2011-08-08 12:40:02 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
|
2012-03-28 18:05:52 +00:00
|
|
|
|
|
|
|
import com.sk89q.minecraft.util.commands.NestedCommand;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2011-09-03 16:54:20 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BlockID;
|
2013-08-24 08:44:17 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2014-01-12 19:54:44 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clipboard commands.
|
2012-03-28 18:05:52 +00:00
|
|
|
*
|
2011-01-29 10:05:22 +00:00
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class ClipboardCommands {
|
2011-12-18 07:45:12 +00:00
|
|
|
private final WorldEdit we;
|
2012-03-28 18:05:52 +00:00
|
|
|
|
2011-12-18 07:45:12 +00:00
|
|
|
public ClipboardCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/copy" },
|
2012-03-30 04:16:59 +00:00
|
|
|
flags = "e",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Copy the selection to the clipboard",
|
2012-03-30 04:16:59 +00:00
|
|
|
help = "Copy the selection to the clipboard\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -e controls whether entities are copied\n" +
|
|
|
|
"WARNING: Pasting entities cannot yet be undone!",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.copy")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void copy(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2012-03-28 18:05:52 +00:00
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
2011-01-29 10:05:22 +00:00
|
|
|
Vector min = region.getMinimumPoint();
|
|
|
|
Vector max = region.getMaximumPoint();
|
2011-09-02 19:01:24 +00:00
|
|
|
Vector pos = session.getPlacementPosition(player);
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
CuboidClipboard clipboard = new CuboidClipboard(
|
2013-08-05 17:47:49 +00:00
|
|
|
max.subtract(min).add(Vector.ONE),
|
2011-01-29 10:05:22 +00:00
|
|
|
min, min.subtract(pos));
|
2013-08-24 08:44:17 +00:00
|
|
|
|
|
|
|
if (region instanceof CuboidRegion) {
|
|
|
|
clipboard.copy(editSession);
|
|
|
|
} else {
|
|
|
|
clipboard.copy(editSession, region);
|
|
|
|
}
|
|
|
|
|
2012-03-30 04:16:59 +00:00
|
|
|
if (args.hasFlag('e')) {
|
|
|
|
for (LocalEntity entity : player.getWorld().getEntities(region)) {
|
|
|
|
clipboard.storeEntity(entity);
|
|
|
|
}
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
session.setClipboard(clipboard);
|
|
|
|
|
|
|
|
player.print("Block(s) copied.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/cut" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "[leave-id]",
|
|
|
|
desc = "Cut the selection to the clipboard",
|
2012-03-30 04:16:59 +00:00
|
|
|
help = "Copy the selection to the clipboard\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -e controls whether entities are copied\n" +
|
|
|
|
"WARNING: Cutting and pasting entities cannot yet be undone!",
|
|
|
|
flags = "e",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.cut")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(REGION)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void cut(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-09-03 16:54:20 +00:00
|
|
|
BaseBlock block = new BaseBlock(BlockID.AIR);
|
2012-03-30 04:16:59 +00:00
|
|
|
LocalWorld world = player.getWorld();
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
if (args.argsLength() > 0) {
|
|
|
|
block = we.getBlock(player, args.getString(0));
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-03-30 04:16:59 +00:00
|
|
|
Region region = session.getSelection(world);
|
2011-01-29 10:05:22 +00:00
|
|
|
Vector min = region.getMinimumPoint();
|
|
|
|
Vector max = region.getMaximumPoint();
|
2011-09-02 19:01:24 +00:00
|
|
|
Vector pos = session.getPlacementPosition(player);
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
CuboidClipboard clipboard = new CuboidClipboard(
|
2013-08-05 17:47:49 +00:00
|
|
|
max.subtract(min).add(Vector.ONE),
|
2011-01-29 10:05:22 +00:00
|
|
|
min, min.subtract(pos));
|
2013-08-24 08:44:17 +00:00
|
|
|
|
|
|
|
if (region instanceof CuboidRegion) {
|
|
|
|
clipboard.copy(editSession);
|
|
|
|
} else {
|
|
|
|
clipboard.copy(editSession, region);
|
|
|
|
}
|
|
|
|
|
2012-03-30 04:16:59 +00:00
|
|
|
if (args.hasFlag('e')) {
|
|
|
|
LocalEntity[] entities = world.getEntities(region);
|
|
|
|
for (LocalEntity entity : entities) {
|
|
|
|
clipboard.storeEntity(entity);
|
|
|
|
}
|
|
|
|
world.killEntities(entities);
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
session.setClipboard(clipboard);
|
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
editSession.setBlocks(region, block);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print("Block(s) cut.");
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/paste" },
|
2011-01-29 20:01:14 +00:00
|
|
|
usage = "",
|
2014-01-12 19:54:44 +00:00
|
|
|
flags = "sao",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Paste the clipboard's contents",
|
Added help text for most commands that take flags.
//generate, //regen, //deform, //[h]cyl, //[h]sphere, //chunk, //outset, //inset, //stack, //move, //smooth, //paste, //flip, /search //distr /butcher, //brush sphere/cyl/clipboard/smooth
Only //replace and /replacenear are still missing.
2011-12-05 10:21:40 +00:00
|
|
|
help =
|
|
|
|
"Pastes the clipboard's contents.\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -a skips air blocks\n" +
|
2014-01-12 19:54:44 +00:00
|
|
|
" -o pastes at the original position\n" +
|
|
|
|
" -s selects the region after pasting",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
2011-01-29 20:01:14 +00:00
|
|
|
max = 0
|
2011-01-29 10:05:22 +00:00
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.paste")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void paste(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-01-29 20:01:14 +00:00
|
|
|
boolean atOrigin = args.hasFlag('o');
|
|
|
|
boolean pasteNoAir = args.hasFlag('a');
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2014-01-12 19:54:44 +00:00
|
|
|
CuboidClipboard clipboard = session.getClipboard();
|
|
|
|
|
|
|
|
Vector pos = atOrigin ? session.getClipboard().getOrigin()
|
|
|
|
: session.getPlacementPosition(player);
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
if (atOrigin) {
|
2014-01-12 19:54:44 +00:00
|
|
|
clipboard.place(editSession, pos, pasteNoAir);
|
|
|
|
clipboard.pasteEntities(pos);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.findFreePosition();
|
|
|
|
player.print("Pasted to copy origin. Undo with //undo");
|
|
|
|
} else {
|
2014-01-12 19:54:44 +00:00
|
|
|
clipboard.paste(editSession, pos, pasteNoAir, true);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.findFreePosition();
|
|
|
|
player.print("Pasted relative to you. Undo with //undo");
|
|
|
|
}
|
2014-01-12 19:54:44 +00:00
|
|
|
|
|
|
|
if (args.hasFlag('s')) {
|
|
|
|
LocalWorld world = player.getWorld();
|
|
|
|
Vector pos2 = pos.add(clipboard.getSize().subtract(1, 1, 1));
|
|
|
|
if (!atOrigin) {
|
|
|
|
pos2 = pos2.add(clipboard.getOffset());
|
|
|
|
pos = pos.add(clipboard.getOffset());
|
|
|
|
}
|
|
|
|
session.setRegionSelector(world, new CuboidRegionSelector(world, pos, pos2));
|
|
|
|
session.getRegionSelector(world).learnChanges();
|
|
|
|
session.getRegionSelector(world).explainRegionAdjust(player, session);
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/rotate" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<angle-in-degrees>",
|
|
|
|
desc = "Rotate the contents of the clipboard",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.rotate")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void rotate(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2012-03-28 18:05:52 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
int angle = args.getInteger(0);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
if (angle % 90 == 0) {
|
|
|
|
CuboidClipboard clipboard = session.getClipboard();
|
|
|
|
clipboard.rotate2D(angle);
|
|
|
|
player.print("Clipboard rotated by " + angle + " degrees.");
|
|
|
|
} else {
|
|
|
|
player.printError("Angles must be divisible by 90 degrees.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/flip" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "[dir]",
|
2011-08-26 02:57:05 +00:00
|
|
|
flags = "p",
|
2011-09-17 22:57:34 +00:00
|
|
|
desc = "Flip the contents of the clipboard.",
|
Added help text for most commands that take flags.
//generate, //regen, //deform, //[h]cyl, //[h]sphere, //chunk, //outset, //inset, //stack, //move, //smooth, //paste, //flip, /search //distr /butcher, //brush sphere/cyl/clipboard/smooth
Only //replace and /replacenear are still missing.
2011-12-05 10:21:40 +00:00
|
|
|
help =
|
|
|
|
"Flips the contents of the clipboard.\n" +
|
|
|
|
"The -p flag flips the selection around the player,\n" +
|
|
|
|
"instead of the selections center.",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.flip")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void flip(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
CuboidClipboard.FlipDirection dir = we.getFlipDirection(player,
|
|
|
|
args.argsLength() > 0 ? args.getString(0).toLowerCase() : "me");
|
|
|
|
|
|
|
|
CuboidClipboard clipboard = session.getClipboard();
|
2011-08-26 02:57:05 +00:00
|
|
|
clipboard.flip(dir, args.hasFlag('p'));
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print("Clipboard flipped.");
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/load" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<filename>",
|
|
|
|
desc = "Load a schematic into your clipboard",
|
2012-03-28 18:05:52 +00:00
|
|
|
min = 0,
|
2011-01-29 10:05:22 +00:00
|
|
|
max = 1
|
|
|
|
)
|
2012-03-28 18:05:52 +00:00
|
|
|
@Deprecated
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.load")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void load(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2012-03-28 18:05:52 +00:00
|
|
|
player.printError("This command is no longer used. See //schematic load.");
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/save" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<filename>",
|
|
|
|
desc = "Save a schematic into your clipboard",
|
2012-03-28 18:05:52 +00:00
|
|
|
min = 0,
|
2011-01-29 10:05:22 +00:00
|
|
|
max = 1
|
|
|
|
)
|
2012-03-28 18:05:52 +00:00
|
|
|
@Deprecated
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.save")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void save(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2012-03-28 18:05:52 +00:00
|
|
|
player.printError("This command is no longer used. See //schematic save.");
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-03-28 18:05:52 +00:00
|
|
|
@Command(
|
|
|
|
aliases = { "/schematic", "/schem"},
|
|
|
|
desc = "Schematic-related commands"
|
|
|
|
)
|
|
|
|
@NestedCommand(SchematicCommands.class)
|
|
|
|
public void schematic() {}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "clearclipboard" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Clear your clipboard",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.clipboard.clear")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void clearClipboard(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
session.setClipboard(null);
|
|
|
|
player.print("Clipboard cleared.");
|
|
|
|
}
|
|
|
|
}
|