2011-01-29 10:05:22 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
2011-02-19 05:24:12 +00:00
|
|
|
import java.util.logging.Logger;
|
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-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
|
|
|
import com.sk89q.worldedit.data.ChunkStore;
|
2011-02-20 01:44:39 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
2011-12-12 04:12:24 +00:00
|
|
|
import com.sk89q.worldedit.regions.ExtendingCuboidRegionSelector;
|
2011-02-20 01:44:39 +00:00
|
|
|
import com.sk89q.worldedit.regions.Polygonal2DRegionSelector;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2011-02-20 01:44:39 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionOperationException;
|
2011-12-12 04:12:24 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionSelector;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.blocks.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selection commands.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class SelectionCommands {
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/pos1" },
|
2011-08-10 20:56:45 +00:00
|
|
|
usage = "[coordinates]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Set position 1",
|
|
|
|
min = 0,
|
2011-08-10 20:56:45 +00:00
|
|
|
max = 1
|
2011-01-29 10:05:22 +00:00
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.pos")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void pos1(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
2011-08-10 21:02:56 +00:00
|
|
|
|
|
|
|
Vector pos;
|
|
|
|
|
|
|
|
if (args.argsLength() == 1) {
|
|
|
|
if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) {
|
|
|
|
String[] coords = args.getString(0).split(",");
|
|
|
|
pos = new Vector(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2]));
|
|
|
|
} else {
|
|
|
|
player.printError("Invalid coordinates " + args.getString(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pos = player.getBlockIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos)) {
|
2011-02-20 01:44:39 +00:00
|
|
|
player.printError("Position already set.");
|
|
|
|
return;
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-02-20 01:44:39 +00:00
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld())
|
2011-08-10 20:56:45 +00:00
|
|
|
.explainPrimarySelection(player, session, pos);
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/pos2" },
|
2011-08-10 20:56:45 +00:00
|
|
|
usage = "[coordinates]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Set position 2",
|
|
|
|
min = 0,
|
2011-08-22 21:05:31 +00:00
|
|
|
max = 1
|
2011-01-29 10:05:22 +00:00
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.pos")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void pos2(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
2011-02-20 01:44:39 +00:00
|
|
|
|
2011-08-10 21:02:56 +00:00
|
|
|
Vector pos;
|
2011-11-23 01:29:48 +00:00
|
|
|
if (args.argsLength() == 1) {
|
|
|
|
if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) {
|
2011-08-10 21:02:56 +00:00
|
|
|
String[] coords = args.getString(0).split(",");
|
2011-11-23 01:29:48 +00:00
|
|
|
pos = new Vector(Integer.parseInt(coords[0]),
|
|
|
|
Integer.parseInt(coords[1]),
|
2011-08-10 21:02:56 +00:00
|
|
|
Integer.parseInt(coords[2]));
|
|
|
|
} else {
|
|
|
|
player.printError("Invalid coordinates " + args.getString(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pos = player.getBlockIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos)) {
|
2011-02-20 01:44:39 +00:00
|
|
|
player.printError("Position already set.");
|
|
|
|
return;
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-02-20 01:44:39 +00:00
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld())
|
2011-08-10 20:56:45 +00:00
|
|
|
.explainSecondarySelection(player, session, pos);
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/hpos1" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Set position 1 to targeted block",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.hpos")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void hpos1(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
Vector pos = player.getBlockTrace(300);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
if (pos != null) {
|
2011-02-20 01:44:39 +00:00
|
|
|
if (!session.getRegionSelector(player.getWorld())
|
|
|
|
.selectPrimary(pos)) {
|
|
|
|
player.printError("Position already set.");
|
|
|
|
return;
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-02-20 01:44:39 +00:00
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld())
|
2011-03-12 06:43:02 +00:00
|
|
|
.explainPrimarySelection(player, session, pos);
|
2011-01-29 10:05:22 +00:00
|
|
|
} else {
|
|
|
|
player.printError("No block in sight!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/hpos2" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Set position 2 to targeted block",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.hpos")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void hpos2(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
Vector pos = player.getBlockTrace(300);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
if (pos != null) {
|
2011-02-20 01:44:39 +00:00
|
|
|
if (!session.getRegionSelector(player.getWorld())
|
|
|
|
.selectSecondary(pos)) {
|
|
|
|
player.printError("Position already set.");
|
|
|
|
return;
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-02-20 01:44:39 +00:00
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld())
|
2011-03-12 06:43:02 +00:00
|
|
|
.explainSecondarySelection(player, session, pos);
|
2011-01-29 10:05:22 +00:00
|
|
|
} else {
|
|
|
|
player.printError("No block in sight!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/chunk" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
2011-08-16 08:10:23 +00:00
|
|
|
flags = "s",
|
2011-09-17 22:57:34 +00:00
|
|
|
desc = "Set the selection to your current chunk.",
|
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 =
|
|
|
|
"Set the selection to the chunk you are currently in.\n" +
|
|
|
|
"With the -s flag, your current selection is expanded\n" +
|
|
|
|
"to encompass all chunks that are part of it.",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.chunk")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void chunk(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
2011-08-16 08:10:23 +00:00
|
|
|
final Vector min;
|
|
|
|
final Vector max;
|
|
|
|
if (args.hasFlag('s')) {
|
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
|
|
|
|
final Vector2D min2D = ChunkStore.toChunk(region.getMinimumPoint());
|
|
|
|
final Vector2D max2D = ChunkStore.toChunk(region.getMaximumPoint());
|
|
|
|
|
|
|
|
min = new Vector(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
|
2011-12-13 03:20:31 +00:00
|
|
|
max = new Vector(max2D.getBlockX() * 16 + 15, player.getWorld().getMaxY(), max2D.getBlockZ() * 16 + 15);
|
2011-08-16 08:10:23 +00:00
|
|
|
|
|
|
|
player.print("Chunks selected: ("
|
|
|
|
+ min2D.getBlockX() + ", " + min2D.getBlockZ() + ") - ("
|
|
|
|
+ max2D.getBlockX() + ", " + max2D.getBlockZ() + ")");
|
2011-10-26 20:50:46 +00:00
|
|
|
} else {
|
2011-08-16 08:10:23 +00:00
|
|
|
final Vector2D min2D = ChunkStore.toChunk(player.getBlockIn());
|
|
|
|
|
|
|
|
min = new Vector(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
|
2011-12-13 03:20:31 +00:00
|
|
|
max = min.add(15, player.getWorld().getMaxY(), 15);
|
2011-08-16 08:10:23 +00:00
|
|
|
|
|
|
|
player.print("Chunk selected: "
|
|
|
|
+ min2D.getBlockX() + ", " + min2D.getBlockZ());
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
CuboidRegionSelector selector = new CuboidRegionSelector(player.getWorld());
|
2011-02-20 01:44:39 +00:00
|
|
|
selector.selectPrimary(min);
|
|
|
|
selector.selectSecondary(max);
|
|
|
|
session.setRegionSelector(player.getWorld(), selector);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-03-12 10:27:43 +00:00
|
|
|
session.dispatchCUISelection(player);
|
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 = { "/wand" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Get the wand object",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.wand")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void wand(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
player.giveItem(we.getConfiguration().wandItem, 1);
|
|
|
|
player.print("Left click: select pos #1; Right click: select pos #2");
|
|
|
|
}
|
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 = { "toggleeditwand" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Toggle functionality of the edit wand",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.wand.toggle")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void toggleWand(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
session.setToolControl(!session.isToolControlEnabled());
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
if (session.isToolControlEnabled()) {
|
|
|
|
player.print("Edit wand enabled.");
|
|
|
|
} else {
|
|
|
|
player.print("Edit wand disabled.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/expand" },
|
2011-01-29 17:31:48 +00:00
|
|
|
usage = "<amount> [reverse-amount] <direction>",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Expand the selection area",
|
|
|
|
min = 1,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.expand")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void expand(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
Vector dir;
|
|
|
|
|
|
|
|
// Special syntax (//expand vert) to expand the selection between
|
|
|
|
// sky and bedrock.
|
2011-01-29 17:31:48 +00:00
|
|
|
if (args.getString(0).equalsIgnoreCase("vert")
|
|
|
|
|| args.getString(0).equalsIgnoreCase("vertical")) {
|
2011-02-20 01:44:39 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
try {
|
|
|
|
int oldSize = region.getArea();
|
2011-12-13 03:20:31 +00:00
|
|
|
region.expand(new Vector(0, (player.getWorld().getMaxY() + 1), 0));
|
|
|
|
region.expand(new Vector(0, -(player.getWorld().getMaxY() + 1), 0));
|
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
2011-02-20 01:44:39 +00:00
|
|
|
int newSize = region.getArea();
|
2011-12-13 03:20:31 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
2011-02-20 01:44:39 +00:00
|
|
|
player.print("Region expanded " + (newSize - oldSize)
|
|
|
|
+ " blocks [top-to-bottom].");
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-01-29 17:31:48 +00:00
|
|
|
|
|
|
|
int change = args.getInteger(0);
|
|
|
|
int reverseChange = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-09-19 05:14:43 +00:00
|
|
|
switch (args.argsLength()) {
|
|
|
|
case 2:
|
|
|
|
// Either a reverse amount or a direction
|
2011-01-29 10:05:22 +00:00
|
|
|
try {
|
|
|
|
reverseChange = args.getInteger(1) * -1;
|
|
|
|
dir = we.getDirection(player, "me");
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
dir = we.getDirection(player,
|
|
|
|
args.getString(1).toLowerCase());
|
|
|
|
}
|
2011-09-19 05:14:43 +00:00
|
|
|
break;
|
|
|
|
|
2011-11-23 01:29:48 +00:00
|
|
|
case 3:
|
2011-09-19 05:14:43 +00:00
|
|
|
// Both reverse amount and direction
|
2011-01-29 10:05:22 +00:00
|
|
|
reverseChange = args.getInteger(1) * -1;
|
|
|
|
dir = we.getDirection(player,
|
|
|
|
args.getString(2).toLowerCase());
|
2011-09-19 05:14:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-01-29 10:05:22 +00:00
|
|
|
dir = we.getDirection(player, "me");
|
|
|
|
}
|
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
int oldSize = region.getArea();
|
2011-01-29 10:05:22 +00:00
|
|
|
region.expand(dir.multiply(change));
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
if (reverseChange != 0) {
|
|
|
|
region.expand(dir.multiply(reverseChange));
|
|
|
|
}
|
2011-02-20 01:44:39 +00:00
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
2011-02-20 01:44:39 +00:00
|
|
|
int newSize = region.getArea();
|
2011-12-13 03:20:31 +00:00
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print("Region expanded " + (newSize - oldSize) + " blocks.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/contract" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<amount> [reverse-amount] [direction]",
|
|
|
|
desc = "Contract the selection area",
|
|
|
|
min = 1,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.contract")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void contract(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
Vector dir;
|
|
|
|
int change = args.getInteger(0);
|
|
|
|
int reverseChange = 0;
|
|
|
|
|
2011-09-19 05:14:43 +00:00
|
|
|
switch (args.argsLength()) {
|
|
|
|
case 2:
|
|
|
|
// Either a reverse amount or a direction
|
2011-01-29 10:05:22 +00:00
|
|
|
try {
|
|
|
|
reverseChange = args.getInteger(1) * -1;
|
|
|
|
dir = we.getDirection(player, "me");
|
|
|
|
} catch (NumberFormatException e) {
|
2011-09-24 19:24:10 +00:00
|
|
|
dir = we.getDirection(player, args.getString(1).toLowerCase());
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-09-19 05:14:43 +00:00
|
|
|
break;
|
|
|
|
|
2011-11-23 01:29:48 +00:00
|
|
|
case 3:
|
2011-09-19 05:14:43 +00:00
|
|
|
// Both reverse amount and direction
|
2011-01-29 10:05:22 +00:00
|
|
|
reverseChange = args.getInteger(1) * -1;
|
2011-09-24 19:24:10 +00:00
|
|
|
dir = we.getDirection(player, args.getString(2).toLowerCase());
|
2011-09-19 05:14:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-01-29 10:05:22 +00:00
|
|
|
dir = we.getDirection(player, "me");
|
|
|
|
}
|
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
try {
|
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
int oldSize = region.getArea();
|
|
|
|
region.contract(dir.multiply(change));
|
|
|
|
if (reverseChange != 0) {
|
|
|
|
region.contract(dir.multiply(reverseChange));
|
|
|
|
}
|
2011-12-13 03:20:31 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
2011-02-20 01:44:39 +00:00
|
|
|
int newSize = region.getArea();
|
2011-12-13 03:20:31 +00:00
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
player.print("Region contracted " + (oldSize - newSize) + " blocks.");
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/shift" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<amount> [direction]",
|
|
|
|
desc = "Shift the selection area",
|
|
|
|
min = 1,
|
2011-02-19 05:32:28 +00:00
|
|
|
max = 2
|
2011-01-29 10:05:22 +00:00
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.shift")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void shift(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
Vector dir;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
int change = args.getInteger(0);
|
|
|
|
if (args.argsLength() == 2) {
|
2011-09-24 19:24:10 +00:00
|
|
|
dir = we.getDirection(player, args.getString(1).toLowerCase());
|
2011-01-29 10:05:22 +00:00
|
|
|
} else {
|
|
|
|
dir = we.getDirection(player, "me");
|
|
|
|
}
|
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
try {
|
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
region.expand(dir.multiply(change));
|
|
|
|
region.contract(dir.multiply(change));
|
2011-12-13 03:20:31 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
player.print("Region shifted.");
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 05:32:28 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/outset" },
|
2011-02-19 05:32:28 +00:00
|
|
|
usage = "<amount>",
|
|
|
|
desc = "Outset the selection area",
|
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 =
|
|
|
|
"Expands the selection by the given amount in all directions.\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -h only expand horizontally\n" +
|
|
|
|
" -v only expand vertically\n",
|
2011-02-19 05:32:28 +00:00
|
|
|
flags = "hv",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.outset")
|
2011-02-19 05:32:28 +00:00
|
|
|
public static void outset(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
int change = args.getInteger(0);
|
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
try {
|
|
|
|
if (!args.hasFlag('h')) {
|
|
|
|
region.expand((new Vector(0, 1, 0)).multiply(change));
|
|
|
|
region.expand((new Vector(0, -1, 0)).multiply(change));
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
if (!args.hasFlag('v')) {
|
|
|
|
region.expand((new Vector(1, 0, 0)).multiply(change));
|
|
|
|
region.expand((new Vector(-1, 0, 0)).multiply(change));
|
|
|
|
region.expand((new Vector(0, 0, 1)).multiply(change));
|
|
|
|
region.expand((new Vector(0, 0, -1)).multiply(change));
|
|
|
|
}
|
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
player.print("Region outset.");
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
2011-02-19 05:32:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/inset" },
|
2011-02-19 05:32:28 +00:00
|
|
|
usage = "<amount>",
|
|
|
|
desc = "Inset the selection area",
|
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 =
|
|
|
|
"Contracts the selection by the given amount in all directions.\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -h only contract horizontally\n" +
|
|
|
|
" -v only contract vertically\n",
|
2011-02-19 05:32:28 +00:00
|
|
|
flags = "hv",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.inset")
|
2011-02-19 05:32:28 +00:00
|
|
|
public static void inset(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
int change = args.getInteger(0);
|
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:32:28 +00:00
|
|
|
if (!args.hasFlag('h')) {
|
|
|
|
region.contract((new Vector(0, 1, 0)).multiply(change));
|
|
|
|
region.contract((new Vector(0, -1, 0)).multiply(change));
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:32:28 +00:00
|
|
|
if (!args.hasFlag('v')) {
|
|
|
|
region.contract((new Vector(1, 0, 0)).multiply(change));
|
|
|
|
region.contract((new Vector(-1, 0, 0)).multiply(change));
|
|
|
|
region.contract((new Vector(0, 0, 1)).multiply(change));
|
|
|
|
region.contract((new Vector(0, 0, -1)).multiply(change));
|
|
|
|
}
|
2011-02-20 01:44:39 +00:00
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:32:28 +00:00
|
|
|
player.print("Region inset.");
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/size" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Get information about the selection",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.selection.size")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void size(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
2011-02-20 01:44:39 +00:00
|
|
|
|
|
|
|
Region region = session.getSelection(player.getWorld());
|
2011-01-29 10:05:22 +00:00
|
|
|
Vector size = region.getMaximumPoint()
|
|
|
|
.subtract(region.getMinimumPoint())
|
|
|
|
.add(1, 1, 1);
|
2011-02-20 01:44:39 +00:00
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
player.print("Type: " + session.getRegionSelector(player.getWorld()).getTypeName());
|
|
|
|
|
|
|
|
for (String line : session.getRegionSelector(player.getWorld()).getInformationLines()) {
|
2011-02-20 01:44:39 +00:00
|
|
|
player.print(line);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print("Size: " + size);
|
2011-02-20 01:44:39 +00:00
|
|
|
player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint()));
|
|
|
|
player.print("# of blocks: " + region.getArea());
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/count" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<block>",
|
|
|
|
desc = "Counts the number of a certain type of block",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.analysis.count")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void count(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
Set<Integer> searchIDs = we.getBlockIDs(player,
|
2011-01-29 17:31:48 +00:00
|
|
|
args.getString(0), true);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print("Counted: " +
|
2011-02-20 01:44:39 +00:00
|
|
|
editSession.countBlocks(session.getSelection(player.getWorld()), searchIDs));
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/distr" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Get the distribution of blocks in the selection",
|
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 =
|
|
|
|
"Gets the distribution of blocks in the selection.\n" +
|
|
|
|
"The -c flag makes it print to the console as well.",
|
2011-02-19 05:24:12 +00:00
|
|
|
flags = "c",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.analysis.distr")
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void distr(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
List<Countable<Integer>> distribution =
|
2011-11-23 01:29:48 +00:00
|
|
|
editSession.getBlockDistribution(session.getSelection(player.getWorld()));
|
|
|
|
|
2011-02-19 05:24:12 +00:00
|
|
|
Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
if (distribution.size() > 0) { // *Should* always be true
|
2011-02-20 01:44:39 +00:00
|
|
|
int size = session.getSelection(player.getWorld()).getArea();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print("# total blocks: " + size);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:24:12 +00:00
|
|
|
if (args.hasFlag('c')) {
|
|
|
|
logger.info("Block distribution (req. by " + player.getName() + "):");
|
|
|
|
logger.info("# total blocks: " + size);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
for (Countable<Integer> c : distribution) {
|
2011-11-03 05:49:56 +00:00
|
|
|
BlockType block = BlockType.fromID(c.getID());
|
2011-02-19 05:24:12 +00:00
|
|
|
String str = String.format("%-7s (%.3f%%) %s #%d",
|
2011-01-29 10:05:22 +00:00
|
|
|
String.valueOf(c.getAmount()),
|
2011-11-23 01:29:48 +00:00
|
|
|
c.getAmount() / (double) size * 100,
|
2011-11-03 05:49:56 +00:00
|
|
|
block == null ? "Unknown" : block.getName(), c.getID());
|
2011-02-19 05:24:12 +00:00
|
|
|
player.print(str);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:24:12 +00:00
|
|
|
if (args.hasFlag('c')) {
|
|
|
|
logger.info(str);
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
player.printError("No blocks counted.");
|
|
|
|
}
|
|
|
|
}
|
2011-02-20 01:44:39 +00:00
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/sel", ";" },
|
2011-12-12 04:12:24 +00:00
|
|
|
usage = "[cuboid|extend|poly]",
|
2011-02-20 01:44:39 +00:00
|
|
|
desc = "Choose a region selector",
|
2011-09-17 22:57:34 +00:00
|
|
|
min = 0,
|
2011-02-20 01:44:39 +00:00
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
public static void select(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
2011-12-12 04:12:24 +00:00
|
|
|
final LocalWorld world = player.getWorld();
|
2011-09-18 22:51:03 +00:00
|
|
|
if (args.argsLength() == 0) {
|
2011-12-12 04:12:24 +00:00
|
|
|
session.getRegionSelector(world).clear();
|
2011-09-18 22:51:03 +00:00
|
|
|
return;
|
2011-09-17 22:57:34 +00:00
|
|
|
}
|
2011-12-12 04:12:24 +00:00
|
|
|
|
|
|
|
final String typeName = args.getString(0);
|
|
|
|
final RegionSelector oldSelector = session.getRegionSelector(world);
|
|
|
|
|
|
|
|
final RegionSelector selector;
|
2011-02-20 01:44:39 +00:00
|
|
|
if (typeName.equalsIgnoreCase("cuboid")) {
|
2011-12-12 04:12:24 +00:00
|
|
|
selector = new CuboidRegionSelector(oldSelector);
|
2011-02-20 01:44:39 +00:00
|
|
|
player.print("Cuboid: left click for point 1, right click for point 2");
|
2011-12-12 04:12:24 +00:00
|
|
|
} else if (typeName.equalsIgnoreCase("extend")) {
|
|
|
|
selector = new ExtendingCuboidRegionSelector(oldSelector);
|
|
|
|
player.print("Cuboid: left click for a starting point, right click to extend");
|
2011-02-20 01:44:39 +00:00
|
|
|
} else if (typeName.equalsIgnoreCase("poly")) {
|
2011-12-13 03:20:31 +00:00
|
|
|
selector = new Polygonal2DRegionSelector(world);
|
2011-02-20 01:44:39 +00:00
|
|
|
player.print("2D polygon selector: Left/right click to add a point.");
|
|
|
|
} else {
|
2011-12-12 04:12:24 +00:00
|
|
|
player.printError("Only 'cuboid', 'extend' and 'poly' are accepted.");
|
|
|
|
return;
|
2011-02-20 01:44:39 +00:00
|
|
|
}
|
2011-12-12 04:12:24 +00:00
|
|
|
session.setRegionSelector(world, selector);
|
|
|
|
session.dispatchCUISelection(player);
|
2011-02-20 01:44:39 +00:00
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|