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;
|
|
|
|
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2018-06-18 07:53:33 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
2019-04-24 05:58:30 +00:00
|
|
|
import com.sk89q.worldedit.command.argument.ExpandAmount;
|
|
|
|
import com.sk89q.worldedit.command.argument.SelectorChoice;
|
|
|
|
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-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2018-06-17 05:42:47 +00:00
|
|
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
2014-07-29 02:50:01 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
2019-03-26 02:38:51 +00:00
|
|
|
import com.sk89q.worldedit.function.block.BlockDistributionCounter;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
|
|
|
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
2019-04-24 05:58:30 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.Direction;
|
|
|
|
import com.sk89q.worldedit.internal.annotation.MultiDirection;
|
2018-10-14 10:40:53 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
import com.sk89q.worldedit.regions.RegionOperationException;
|
|
|
|
import com.sk89q.worldedit.regions.RegionSelector;
|
2014-04-04 01:32:51 +00:00
|
|
|
import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector;
|
|
|
|
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
|
|
|
import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
|
|
|
|
import com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector;
|
|
|
|
import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector;
|
|
|
|
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
2014-07-29 03:53:17 +00:00
|
|
|
import com.sk89q.worldedit.regions.selector.RegionSelectorType;
|
2014-04-04 01:32:51 +00:00
|
|
|
import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
|
2014-07-02 09:56:21 +00:00
|
|
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.util.Countable;
|
2018-06-16 05:29:48 +00:00
|
|
|
import com.sk89q.worldedit.util.Location;
|
2014-07-29 02:56:04 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
|
2019-04-25 09:11:58 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
|
2019-04-22 12:05:20 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2018-12-27 00:39:10 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.world.storage.ChunkStore;
|
2019-04-24 05:58:30 +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.Switch;
|
2014-06-30 00:47:08 +00:00
|
|
|
|
|
|
|
import java.util.List;
|
2018-06-16 06:36:55 +00:00
|
|
|
import java.util.Optional;
|
2014-06-30 00:47:08 +00:00
|
|
|
import java.util.Set;
|
2019-04-24 05:58:30 +00:00
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
/**
|
|
|
|
* Selection commands.
|
|
|
|
*/
|
2019-04-24 05:58:30 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
2014-04-03 02:08:50 +00:00
|
|
|
public class SelectionCommands {
|
2014-07-29 18:04:04 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
private final WorldEdit we;
|
2019-04-24 05:58:30 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
public SelectionCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/pos1",
|
|
|
|
desc = "Set position 1"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(POSITION)
|
|
|
|
@CommandPermissions("worldedit.selection.pos")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void pos1(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Coordinates to set position 1 to", def = "")
|
|
|
|
BlockVector3 coordinates) throws WorldEditException {
|
2018-06-16 05:29:48 +00:00
|
|
|
Location pos;
|
2019-04-24 05:58:30 +00:00
|
|
|
if (coordinates != null) {
|
|
|
|
pos = new Location(player.getWorld(), coordinates.toVector3());
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
pos = player.getBlockIn();
|
|
|
|
}
|
|
|
|
|
2018-10-14 10:40:53 +00:00
|
|
|
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) {
|
2014-04-03 02:08:50 +00:00
|
|
|
player.printError("Position already set.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld())
|
2018-10-14 10:40:53 +00:00
|
|
|
.explainPrimarySelection(player, session, pos.toVector().toBlockPoint());
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/pos2",
|
|
|
|
desc = "Set position 2"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(POSITION)
|
|
|
|
@CommandPermissions("worldedit.selection.pos")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void pos2(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Coordinates to set position 2 to", def = "")
|
|
|
|
BlockVector3 coordinates) throws WorldEditException {
|
2018-06-16 05:29:48 +00:00
|
|
|
Location pos;
|
2019-04-24 05:58:30 +00:00
|
|
|
if (coordinates != null) {
|
|
|
|
pos = new Location(player.getWorld(), coordinates.toVector3());
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
pos = player.getBlockIn();
|
|
|
|
}
|
|
|
|
|
2018-10-14 10:40:53 +00:00
|
|
|
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) {
|
2014-04-03 02:08:50 +00:00
|
|
|
player.printError("Position already set.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld())
|
2018-10-14 10:40:53 +00:00
|
|
|
.explainSecondarySelection(player, session, pos.toVector().toBlockPoint());
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/hpos1",
|
|
|
|
desc = "Set position 1 to targeted block"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.selection.hpos")
|
2019-03-16 23:04:24 +00:00
|
|
|
public void hpos1(Player player, LocalSession session) throws WorldEditException {
|
2018-06-16 05:29:48 +00:00
|
|
|
|
|
|
|
Location pos = player.getBlockTrace(300);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
if (pos != null) {
|
2018-10-14 10:40:53 +00:00
|
|
|
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) {
|
2014-04-03 02:08:50 +00:00
|
|
|
player.printError("Position already set.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld())
|
2018-10-14 10:40:53 +00:00
|
|
|
.explainPrimarySelection(player, session, pos.toVector().toBlockPoint());
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
player.printError("No block in sight!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/hpos2",
|
|
|
|
desc = "Set position 2 to targeted block"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.selection.hpos")
|
2019-03-16 23:04:24 +00:00
|
|
|
public void hpos2(Player player, LocalSession session) throws WorldEditException {
|
2018-06-16 05:29:48 +00:00
|
|
|
|
|
|
|
Location pos = player.getBlockTrace(300);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
if (pos != null) {
|
2018-10-14 10:40:53 +00:00
|
|
|
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) {
|
2014-04-03 02:08:50 +00:00
|
|
|
player.printError("Position already set.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld())
|
2018-10-14 10:40:53 +00:00
|
|
|
.explainSecondarySelection(player, session, pos.toVector().toBlockPoint());
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
player.printError("No block in sight!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/chunk",
|
|
|
|
desc = "Set the selection to your current chunk."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(POSITION)
|
|
|
|
@CommandPermissions("worldedit.selection.chunk")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void chunk(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "The chunk to select", def = "")
|
|
|
|
BlockVector2 coordinates,
|
|
|
|
@Switch(name = 's', desc = "Expand your selection to encompass all chunks that are part of it")
|
|
|
|
boolean expandSelection,
|
|
|
|
@Switch(name = 'c', desc = "Use chunk coordinates instead of block coordinates")
|
|
|
|
boolean useChunkCoordinates) throws WorldEditException {
|
2018-10-14 10:40:53 +00:00
|
|
|
final BlockVector3 min;
|
|
|
|
final BlockVector3 max;
|
2014-04-05 09:59:38 +00:00
|
|
|
final World world = player.getWorld();
|
2019-04-24 05:58:30 +00:00
|
|
|
if (expandSelection) {
|
2014-04-03 02:08:50 +00:00
|
|
|
Region region = session.getSelection(world);
|
|
|
|
|
2018-10-14 10:40:53 +00:00
|
|
|
final BlockVector2 min2D = ChunkStore.toChunk(region.getMinimumPoint());
|
|
|
|
final BlockVector2 max2D = ChunkStore.toChunk(region.getMaximumPoint());
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-10-19 20:13:32 +00:00
|
|
|
min = BlockVector3.at(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
|
|
|
|
max = BlockVector3.at(max2D.getBlockX() * 16 + 15, world.getMaxY(), max2D.getBlockZ() * 16 + 15);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
player.print("Chunks selected: ("
|
|
|
|
+ min2D.getBlockX() + ", " + min2D.getBlockZ() + ") - ("
|
|
|
|
+ max2D.getBlockX() + ", " + max2D.getBlockZ() + ")");
|
|
|
|
} else {
|
2018-10-14 10:40:53 +00:00
|
|
|
final BlockVector2 min2D;
|
2019-04-24 05:58:30 +00:00
|
|
|
if (coordinates != null) {
|
2014-04-03 02:08:50 +00:00
|
|
|
// coords specified
|
2019-04-24 05:58:30 +00:00
|
|
|
min2D = useChunkCoordinates
|
|
|
|
? coordinates
|
|
|
|
: ChunkStore.toChunk(coordinates.toBlockVector3());
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
// use player loc
|
2018-10-14 10:40:53 +00:00
|
|
|
min2D = ChunkStore.toChunk(player.getBlockIn().toVector().toBlockPoint());
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 20:13:32 +00:00
|
|
|
min = BlockVector3.at(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
|
2014-04-03 02:08:50 +00:00
|
|
|
max = min.add(15, world.getMaxY(), 15);
|
|
|
|
|
|
|
|
player.print("Chunk selected: "
|
|
|
|
+ min2D.getBlockX() + ", " + min2D.getBlockZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
final CuboidRegionSelector selector;
|
|
|
|
if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) {
|
|
|
|
selector = new ExtendingCuboidRegionSelector(world);
|
|
|
|
} else {
|
|
|
|
selector = new CuboidRegionSelector(world);
|
|
|
|
}
|
2014-07-29 02:50:01 +00:00
|
|
|
selector.selectPrimary(min, ActorSelectorLimits.forActor(player));
|
|
|
|
selector.selectSecondary(max, ActorSelectorLimits.forActor(player));
|
2014-04-03 02:08:50 +00:00
|
|
|
session.setRegionSelector(world, selector);
|
|
|
|
|
|
|
|
session.dispatchCUISelection(player);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/wand",
|
|
|
|
desc = "Get the wand object"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.wand")
|
2019-03-16 23:04:24 +00:00
|
|
|
public void wand(Player player) throws WorldEditException {
|
2018-07-05 08:48:37 +00:00
|
|
|
player.giveItem(new BaseItemStack(ItemTypes.get(we.getConfiguration().wandItem), 1));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("Left click: select pos #1; Right click: select pos #2");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "toggleeditwand",
|
|
|
|
desc = "Toggle functionality of the edit wand"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.wand.toggle")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void toggleWand(Player player, LocalSession session) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
session.setToolControl(!session.isToolControlEnabled());
|
|
|
|
|
|
|
|
if (session.isToolControlEnabled()) {
|
|
|
|
player.print("Edit wand enabled.");
|
|
|
|
} else {
|
|
|
|
player.print("Edit wand disabled.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/expand",
|
|
|
|
desc = "Expand the selection area"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(REGION)
|
|
|
|
@CommandPermissions("worldedit.selection.expand")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void expand(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Amount to expand the selection by, can be `vert` to expand to the whole vertical column")
|
|
|
|
ExpandAmount amount,
|
|
|
|
@Arg(desc = "Amount to expand the selection by in the other direction", def = "0")
|
|
|
|
int reverseAmount,
|
|
|
|
@Arg(desc = "Direction to expand", def = Direction.AIM)
|
|
|
|
@MultiDirection
|
|
|
|
List<BlockVector3> direction) throws WorldEditException {
|
2017-06-09 16:44:54 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
// Special syntax (//expand vert) to expand the selection between
|
|
|
|
// sky and bedrock.
|
2019-04-24 05:58:30 +00:00
|
|
|
if (amount.isVert()) {
|
2014-04-03 02:08:50 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
try {
|
|
|
|
int oldSize = region.getArea();
|
|
|
|
region.expand(
|
2018-10-19 20:13:32 +00:00
|
|
|
BlockVector3.at(0, (player.getWorld().getMaxY() + 1), 0),
|
|
|
|
BlockVector3.at(0, -(player.getWorld().getMaxY() + 1), 0));
|
2014-04-03 02:08:50 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
int newSize = region.getArea();
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
|
|
|
player.print("Region expanded " + (newSize - oldSize)
|
|
|
|
+ " blocks [top-to-bottom].");
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
int oldSize = region.getArea();
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
if (reverseAmount == 0) {
|
|
|
|
for (BlockVector3 dir : direction) {
|
|
|
|
region.expand(dir.multiply(amount.getAmount()));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-04-24 05:58:30 +00:00
|
|
|
for (BlockVector3 dir : direction) {
|
|
|
|
region.expand(dir.multiply(amount.getAmount()), dir.multiply(-reverseAmount));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
int newSize = region.getArea();
|
2019-04-24 05:58:30 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
player.print("Region expanded " + (newSize - oldSize) + " block(s).");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/contract",
|
|
|
|
desc = "Contract the selection area"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(REGION)
|
|
|
|
@CommandPermissions("worldedit.selection.contract")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void contract(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Amount to contract the selection by")
|
|
|
|
int amount,
|
|
|
|
@Arg(desc = "Amount to contract the selection by in the other direction", def = "0")
|
|
|
|
int reverseAmount,
|
|
|
|
@Arg(desc = "Direction to contract", def = Direction.AIM)
|
|
|
|
@MultiDirection
|
|
|
|
List<BlockVector3> direction) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
try {
|
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
int oldSize = region.getArea();
|
2019-04-24 05:58:30 +00:00
|
|
|
if (reverseAmount == 0) {
|
|
|
|
for (BlockVector3 dir : direction) {
|
|
|
|
region.contract(dir.multiply(amount));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-04-24 05:58:30 +00:00
|
|
|
for (BlockVector3 dir : direction) {
|
|
|
|
region.contract(dir.multiply(amount), dir.multiply(-reverseAmount));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
int newSize = region.getArea();
|
2019-04-24 05:58:30 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
|
|
|
|
|
|
|
|
|
|
|
player.print("Region contracted " + (oldSize - newSize) + " blocks.");
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/shift",
|
|
|
|
desc = "Shift the selection area"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(REGION)
|
|
|
|
@CommandPermissions("worldedit.selection.shift")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void shift(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Amount to shift the selection by")
|
|
|
|
int amount,
|
|
|
|
@Arg(desc = "Direction to contract", def = Direction.AIM)
|
|
|
|
@MultiDirection
|
|
|
|
List<BlockVector3> direction) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
try {
|
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
for (BlockVector3 dir : direction) {
|
|
|
|
region.shift(dir.multiply(amount));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
|
|
|
|
|
|
|
player.print("Region shifted.");
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/outset",
|
|
|
|
desc = "Outset the selection area"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(REGION)
|
|
|
|
@CommandPermissions("worldedit.selection.outset")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void outset(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Amount to expand the selection by in all directions")
|
|
|
|
int amount,
|
|
|
|
@Switch(name = 'h', desc = "Only expand horizontally")
|
|
|
|
boolean onlyHorizontal,
|
|
|
|
@Switch(name = 'v', desc = "Only expand vertically")
|
|
|
|
boolean onlyVertical) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
2019-04-24 05:58:30 +00:00
|
|
|
region.expand(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
|
2014-04-03 02:08:50 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
|
|
|
player.print("Region outset.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/inset",
|
|
|
|
desc = "Inset the selection area"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(REGION)
|
|
|
|
@CommandPermissions("worldedit.selection.inset")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void inset(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Amount to contract the selection by in all directions")
|
|
|
|
int amount,
|
|
|
|
@Switch(name = 'h', desc = "Only contract horizontally")
|
|
|
|
boolean onlyHorizontal,
|
|
|
|
@Switch(name = 'v', desc = "Only contract vertically")
|
|
|
|
boolean onlyVertical) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
2019-04-24 05:58:30 +00:00
|
|
|
region.contract(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
|
2014-04-03 02:08:50 +00:00
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
|
|
|
player.print("Region inset.");
|
|
|
|
}
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
private BlockVector3[] getChangesForEachDir(int amount, boolean onlyHorizontal, boolean onlyVertical) {
|
|
|
|
Stream.Builder<BlockVector3> changes = Stream.builder();
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
if (!onlyHorizontal) {
|
|
|
|
changes.add(BlockVector3.UNIT_Y);
|
|
|
|
changes.add(BlockVector3.UNIT_MINUS_Y);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
if (!onlyVertical) {
|
|
|
|
changes.add(BlockVector3.UNIT_X);
|
|
|
|
changes.add(BlockVector3.UNIT_MINUS_X);
|
|
|
|
changes.add(BlockVector3.UNIT_Z);
|
|
|
|
changes.add(BlockVector3.UNIT_MINUS_Z);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
return changes.build().map(v -> v.multiply(amount)).toArray(BlockVector3[]::new);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/size",
|
|
|
|
desc = "Get information about the selection"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.selection.size")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void size(Player player, LocalSession session,
|
|
|
|
@Switch(name = 'c', desc = "Get clipboard info instead")
|
|
|
|
boolean clipboardInfo) throws WorldEditException {
|
|
|
|
if (clipboardInfo) {
|
2014-07-02 09:56:21 +00:00
|
|
|
ClipboardHolder holder = session.getClipboard();
|
|
|
|
Clipboard clipboard = holder.getClipboard();
|
2014-06-30 00:47:08 +00:00
|
|
|
Region region = clipboard.getRegion();
|
2018-10-14 10:40:53 +00:00
|
|
|
BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint());
|
|
|
|
BlockVector3 origin = clipboard.getOrigin();
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
player.print("Cuboid dimensions (max - min): " + size);
|
2014-07-02 09:56:21 +00:00
|
|
|
player.print("Offset: " + origin);
|
2018-10-14 10:40:53 +00:00
|
|
|
player.print("Cuboid distance: " + size.distance(BlockVector3.ONE));
|
2019-04-24 05:58:30 +00:00
|
|
|
player.print("# of blocks: " + (size.getX() * size.getY() * size.getZ()));
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-10-14 10:40:53 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
Region region = session.getSelection(player.getWorld());
|
2018-10-14 10:40:53 +00:00
|
|
|
BlockVector3 size = region.getMaximumPoint()
|
2014-04-03 02:08:50 +00:00
|
|
|
.subtract(region.getMinimumPoint())
|
|
|
|
.add(1, 1, 1);
|
2018-10-14 10:40:53 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("Type: " + session.getRegionSelector(player.getWorld())
|
|
|
|
.getTypeName());
|
2018-10-14 10:40:53 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
for (String line : session.getRegionSelector(player.getWorld())
|
|
|
|
.getInformationLines()) {
|
|
|
|
player.print(line);
|
|
|
|
}
|
2018-10-14 10:40:53 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("Size: " + size);
|
2014-06-30 00:47:08 +00:00
|
|
|
player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint()));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("# of blocks: " + region.getArea());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/count",
|
|
|
|
desc = "Counts the number of a certain type of block"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.analysis.count")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void count(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The block type(s) to count")
|
|
|
|
String blocks,
|
|
|
|
@Switch(name = 'f', desc = "Fuzzy, match states using a wildcard")
|
|
|
|
boolean fuzzy) throws WorldEditException {
|
2018-06-17 05:42:47 +00:00
|
|
|
ParserContext context = new ParserContext();
|
|
|
|
context.setActor(player);
|
|
|
|
context.setExtent(player.getExtent());
|
|
|
|
context.setWorld(player.getWorld());
|
|
|
|
context.setSession(session);
|
|
|
|
context.setRestricted(false);
|
2019-04-24 05:58:30 +00:00
|
|
|
context.setPreferringWildcard(fuzzy);
|
2018-06-17 05:42:47 +00:00
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
Set<BaseBlock> searchBlocks = we.getBlockFactory().parseFromListInput(blocks, context);
|
2018-06-17 05:42:47 +00:00
|
|
|
int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks);
|
|
|
|
player.print("Counted: " + count);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/distr",
|
|
|
|
desc = "Get the distribution of blocks in the selection"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.analysis.distr")
|
2019-04-24 05:58:30 +00:00
|
|
|
public void distr(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Switch(name = 'c', desc = "Get the distribution of the clipboard instead")
|
|
|
|
boolean clipboardDistr,
|
|
|
|
@Switch(name = 'd', desc = "Separate blocks by state")
|
|
|
|
boolean separateStates) throws WorldEditException {
|
2018-12-27 00:39:10 +00:00
|
|
|
List<Countable<BlockState>> distribution;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
if (clipboardDistr) {
|
2019-03-26 02:38:51 +00:00
|
|
|
Clipboard clipboard = session.getClipboard().getClipboard(); // throws if missing
|
|
|
|
BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates);
|
|
|
|
RegionVisitor visitor = new RegionVisitor(clipboard.getRegion(), count);
|
|
|
|
Operations.completeBlindly(visitor);
|
|
|
|
distribution = count.getDistribution();
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-12-27 00:39:10 +00:00
|
|
|
distribution = editSession.getBlockDistribution(session.getSelection(player.getWorld()), separateStates);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 07:53:29 +00:00
|
|
|
if (distribution.isEmpty()) { // *Should* always be false
|
2014-04-03 02:08:50 +00:00
|
|
|
player.printError("No blocks counted.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-26 02:38:51 +00:00
|
|
|
// note: doing things like region.getArea is inaccurate for non-cuboids.
|
|
|
|
int size = distribution.stream().mapToInt(Countable::getAmount).sum();
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("# total blocks: " + size);
|
|
|
|
|
2018-12-27 00:39:10 +00:00
|
|
|
for (Countable<BlockState> c : distribution) {
|
2018-08-19 07:53:29 +00:00
|
|
|
String name = c.getID().getBlockType().getName();
|
|
|
|
String str;
|
2018-12-27 00:39:10 +00:00
|
|
|
if (separateStates) {
|
2019-03-26 02:38:51 +00:00
|
|
|
str = String.format("%-7s (%.3f%%) %s (%s)",
|
2018-07-30 13:26:06 +00:00
|
|
|
String.valueOf(c.getAmount()),
|
|
|
|
c.getAmount() / (double) size * 100,
|
|
|
|
name,
|
2018-08-19 07:53:29 +00:00
|
|
|
c.getID().getAsString());
|
|
|
|
} else {
|
2019-03-26 02:38:51 +00:00
|
|
|
str = String.format("%-7s (%.3f%%) %s (%s)",
|
2018-07-30 13:26:06 +00:00
|
|
|
String.valueOf(c.getAmount()),
|
|
|
|
c.getAmount() / (double) size * 100,
|
|
|
|
name,
|
2018-08-19 07:53:29 +00:00
|
|
|
c.getID().getBlockType().getId());
|
2018-07-30 13:26:06 +00:00
|
|
|
}
|
2018-08-19 07:53:29 +00:00
|
|
|
player.print(str);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 05:58:30 +00:00
|
|
|
name = "/sel",
|
|
|
|
aliases = { ";", "/desel", "/deselect" },
|
|
|
|
desc = "Choose a region selector"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2019-04-24 05:58:30 +00:00
|
|
|
public void select(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Selector to switch to", def = "")
|
|
|
|
SelectorChoice selector,
|
|
|
|
@Switch(name = 'd', desc = "Set default selector")
|
|
|
|
boolean setDefaultSelector) throws WorldEditException {
|
2014-04-05 09:59:38 +00:00
|
|
|
final World world = player.getWorld();
|
2019-04-24 05:58:30 +00:00
|
|
|
if (selector == null) {
|
2014-04-03 02:08:50 +00:00
|
|
|
session.getRegionSelector(world).clear();
|
|
|
|
session.dispatchCUISelection(player);
|
|
|
|
player.print("Selection cleared.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final RegionSelector oldSelector = session.getRegionSelector(world);
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
final RegionSelector newSelector;
|
|
|
|
switch (selector) {
|
|
|
|
case CUBOID:
|
|
|
|
newSelector = new CuboidRegionSelector(oldSelector);
|
|
|
|
player.print("Cuboid: left click for point 1, right click for point 2");
|
|
|
|
break;
|
|
|
|
case EXTEND:
|
|
|
|
newSelector = new ExtendingCuboidRegionSelector(oldSelector);
|
|
|
|
player.print("Cuboid: left click for a starting point, right click to extend");
|
|
|
|
break;
|
|
|
|
case POLY: {
|
|
|
|
newSelector = new Polygonal2DRegionSelector(oldSelector);
|
|
|
|
player.print("2D polygon selector: Left/right click to add a point.");
|
|
|
|
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolygonVertexLimit();
|
|
|
|
limit.ifPresent(integer -> player.print(integer + " points maximum."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ELLIPSOID:
|
|
|
|
newSelector = new EllipsoidRegionSelector(oldSelector);
|
|
|
|
player.print("Ellipsoid selector: left click=center, right click to extend");
|
|
|
|
break;
|
|
|
|
case SPHERE:
|
|
|
|
newSelector = new SphereRegionSelector(oldSelector);
|
|
|
|
player.print("Sphere selector: left click=center, right click to set radius");
|
|
|
|
break;
|
|
|
|
case CYL:
|
|
|
|
newSelector = new CylinderRegionSelector(oldSelector);
|
|
|
|
player.print("Cylindrical selector: Left click=center, right click to extend.");
|
|
|
|
break;
|
|
|
|
case CONVEX:
|
|
|
|
case HULL:
|
|
|
|
case POLYHEDRON: {
|
|
|
|
newSelector = new ConvexPolyhedralRegionSelector(oldSelector);
|
|
|
|
player.print("Convex polyhedral selector: Left click=First vertex, right click to add more.");
|
|
|
|
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit();
|
|
|
|
limit.ifPresent(integer -> player.print(integer + " points maximum."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UNKNOWN:
|
|
|
|
default:
|
2019-04-28 05:12:05 +00:00
|
|
|
CommandListBox box = new CommandListBox("Selection modes", null);
|
2019-04-26 05:11:46 +00:00
|
|
|
TextComponentProducer contents = box.getContents();
|
|
|
|
contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
|
|
|
|
|
|
|
|
box.appendCommand("cuboid", "Select two corners of a cuboid", "//sel cuboid");
|
|
|
|
box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend");
|
|
|
|
box.appendCommand("poly", "Select a 2D polygon with height", "//sel poly");
|
|
|
|
box.appendCommand("ellipsoid", "Select an ellipsoid", "//sel ellipsoid");
|
|
|
|
box.appendCommand("sphere", "Select a sphere", "//sel sphere");
|
|
|
|
box.appendCommand("cyl", "Select a cylinder", "//sel cyl");
|
|
|
|
box.appendCommand("convex", "Select a convex polyhedral", "//sel convex");
|
|
|
|
|
2019-04-28 05:12:05 +00:00
|
|
|
player.print(box.create(1));
|
2019-04-24 05:58:30 +00:00
|
|
|
return;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
if (setDefaultSelector) {
|
2014-07-29 03:53:17 +00:00
|
|
|
RegionSelectorType found = null;
|
|
|
|
for (RegionSelectorType type : RegionSelectorType.values()) {
|
2019-04-24 05:58:30 +00:00
|
|
|
if (type.getSelectorClass() == newSelector.getClass()) {
|
2014-07-29 03:53:17 +00:00
|
|
|
found = type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found != null) {
|
|
|
|
session.setDefaultRegionSelector(found);
|
|
|
|
player.print("Your default region selector is now " + found.name() + ".");
|
|
|
|
} else {
|
|
|
|
throw new RuntimeException("Something unexpected happened. Please report this.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 05:58:30 +00:00
|
|
|
session.setRegionSelector(world, newSelector);
|
2014-04-03 02:08:50 +00:00
|
|
|
session.dispatchCUISelection(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|