Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-05 02:50:05 +01:00
Port selection commands
Dieser Commit ist enthalten in:
Ursprung
c95fc06b82
Commit
e07e0d10b0
@ -19,18 +19,15 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.command;
|
package com.sk89q.worldedit.command;
|
||||||
|
|
||||||
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
|
|
||||||
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
|
|
||||||
|
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
|
||||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
||||||
import com.sk89q.minecraft.util.commands.CommandException;
|
|
||||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
|
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;
|
||||||
import com.sk89q.worldedit.command.util.Logging;
|
import com.sk89q.worldedit.command.util.Logging;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||||
@ -39,6 +36,8 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
|||||||
import com.sk89q.worldedit.function.block.BlockDistributionCounter;
|
import com.sk89q.worldedit.function.block.BlockDistributionCounter;
|
||||||
import com.sk89q.worldedit.function.operation.Operations;
|
import com.sk89q.worldedit.function.operation.Operations;
|
||||||
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
||||||
|
import com.sk89q.worldedit.internal.annotation.Direction;
|
||||||
|
import com.sk89q.worldedit.internal.annotation.MultiDirection;
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
@ -64,15 +63,23 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
|||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||||
import com.sk89q.worldedit.world.storage.ChunkStore;
|
import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||||
|
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;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selection commands.
|
* Selection commands.
|
||||||
*/
|
*/
|
||||||
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
||||||
public class SelectionCommands {
|
public class SelectionCommands {
|
||||||
|
|
||||||
private final WorldEdit we;
|
private final WorldEdit we;
|
||||||
@ -82,26 +89,17 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/pos1" },
|
name = "/pos1",
|
||||||
usage = "[coordinates]",
|
desc = "Set position 1"
|
||||||
desc = "Set position 1",
|
|
||||||
min = 0,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@Logging(POSITION)
|
@Logging(POSITION)
|
||||||
@CommandPermissions("worldedit.selection.pos")
|
@CommandPermissions("worldedit.selection.pos")
|
||||||
public void pos1(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void pos1(Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Coordinates to set position 1 to", def = "")
|
||||||
|
BlockVector3 coordinates) throws WorldEditException {
|
||||||
Location pos;
|
Location pos;
|
||||||
|
if (coordinates != null) {
|
||||||
if (args.argsLength() == 1) {
|
pos = new Location(player.getWorld(), coordinates.toVector3());
|
||||||
if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) {
|
|
||||||
String[] coords = args.getString(0).split(",");
|
|
||||||
pos = new Location(player.getWorld(), Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2]));
|
|
||||||
} else {
|
|
||||||
player.printError("Invalid coordinates " + args.getString(0));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pos = player.getBlockIn();
|
pos = player.getBlockIn();
|
||||||
}
|
}
|
||||||
@ -116,27 +114,17 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/pos2" },
|
name = "/pos2",
|
||||||
usage = "[coordinates]",
|
desc = "Set position 2"
|
||||||
desc = "Set position 2",
|
|
||||||
min = 0,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@Logging(POSITION)
|
@Logging(POSITION)
|
||||||
@CommandPermissions("worldedit.selection.pos")
|
@CommandPermissions("worldedit.selection.pos")
|
||||||
public void pos2(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void pos2(Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Coordinates to set position 2 to", def = "")
|
||||||
|
BlockVector3 coordinates) throws WorldEditException {
|
||||||
Location pos;
|
Location pos;
|
||||||
if (args.argsLength() == 1) {
|
if (coordinates != null) {
|
||||||
if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) {
|
pos = new Location(player.getWorld(), coordinates.toVector3());
|
||||||
String[] coords = args.getString(0).split(",");
|
|
||||||
pos = new Location(player.getWorld(), Integer.parseInt(coords[0]),
|
|
||||||
Integer.parseInt(coords[1]),
|
|
||||||
Integer.parseInt(coords[2]));
|
|
||||||
} else {
|
|
||||||
player.printError("Invalid coordinates " + args.getString(0));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pos = player.getBlockIn();
|
pos = player.getBlockIn();
|
||||||
}
|
}
|
||||||
@ -151,11 +139,8 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/hpos1" },
|
name = "/hpos1",
|
||||||
usage = "",
|
desc = "Set position 1 to targeted block"
|
||||||
desc = "Set position 1 to targeted block",
|
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.selection.hpos")
|
@CommandPermissions("worldedit.selection.hpos")
|
||||||
public void hpos1(Player player, LocalSession session) throws WorldEditException {
|
public void hpos1(Player player, LocalSession session) throws WorldEditException {
|
||||||
@ -176,11 +161,8 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/hpos2" },
|
name = "/hpos2",
|
||||||
usage = "",
|
desc = "Set position 2 to targeted block"
|
||||||
desc = "Set position 2 to targeted block",
|
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.selection.hpos")
|
@CommandPermissions("worldedit.selection.hpos")
|
||||||
public void hpos2(Player player, LocalSession session) throws WorldEditException {
|
public void hpos2(Player player, LocalSession session) throws WorldEditException {
|
||||||
@ -201,28 +183,22 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/chunk" },
|
name = "/chunk",
|
||||||
usage = "[x,z coordinates]",
|
desc = "Set the selection to your current chunk."
|
||||||
flags = "sc",
|
|
||||||
desc = "Set the selection to your current chunk.",
|
|
||||||
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.\n\n" +
|
|
||||||
"Specifying coordinates will use those instead of your\n"+
|
|
||||||
"current position. Use -c to specify chunk coordinates,\n" +
|
|
||||||
"otherwise full coordinates will be implied.\n" +
|
|
||||||
"(for example, the coordinates 5,5 are the same as -c 0,0)",
|
|
||||||
min = 0,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@Logging(POSITION)
|
@Logging(POSITION)
|
||||||
@CommandPermissions("worldedit.selection.chunk")
|
@CommandPermissions("worldedit.selection.chunk")
|
||||||
public void chunk(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
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 {
|
||||||
final BlockVector3 min;
|
final BlockVector3 min;
|
||||||
final BlockVector3 max;
|
final BlockVector3 max;
|
||||||
final World world = player.getWorld();
|
final World world = player.getWorld();
|
||||||
if (args.hasFlag('s')) {
|
if (expandSelection) {
|
||||||
Region region = session.getSelection(world);
|
Region region = session.getSelection(world);
|
||||||
|
|
||||||
final BlockVector2 min2D = ChunkStore.toChunk(region.getMinimumPoint());
|
final BlockVector2 min2D = ChunkStore.toChunk(region.getMinimumPoint());
|
||||||
@ -236,16 +212,11 @@ public class SelectionCommands {
|
|||||||
+ max2D.getBlockX() + ", " + max2D.getBlockZ() + ")");
|
+ max2D.getBlockX() + ", " + max2D.getBlockZ() + ")");
|
||||||
} else {
|
} else {
|
||||||
final BlockVector2 min2D;
|
final BlockVector2 min2D;
|
||||||
if (args.argsLength() == 1) {
|
if (coordinates != null) {
|
||||||
// coords specified
|
// coords specified
|
||||||
String[] coords = args.getString(0).split(",");
|
min2D = useChunkCoordinates
|
||||||
if (coords.length != 2) {
|
? coordinates
|
||||||
throw new InsufficientArgumentsException("Invalid coordinates specified.");
|
: ChunkStore.toChunk(coordinates.toBlockVector3());
|
||||||
}
|
|
||||||
int x = Integer.parseInt(coords[0]);
|
|
||||||
int z = Integer.parseInt(coords[1]);
|
|
||||||
BlockVector2 pos = BlockVector2.at(x, z);
|
|
||||||
min2D = (args.hasFlag('c')) ? pos : ChunkStore.toChunk(pos.toBlockVector3());
|
|
||||||
} else {
|
} else {
|
||||||
// use player loc
|
// use player loc
|
||||||
min2D = ChunkStore.toChunk(player.getBlockIn().toVector().toBlockPoint());
|
min2D = ChunkStore.toChunk(player.getBlockIn().toVector().toBlockPoint());
|
||||||
@ -273,29 +244,21 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/wand" },
|
name = "/wand",
|
||||||
usage = "",
|
desc = "Get the wand object"
|
||||||
desc = "Get the wand object",
|
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.wand")
|
@CommandPermissions("worldedit.wand")
|
||||||
public void wand(Player player) throws WorldEditException {
|
public void wand(Player player) throws WorldEditException {
|
||||||
|
|
||||||
player.giveItem(new BaseItemStack(ItemTypes.get(we.getConfiguration().wandItem), 1));
|
player.giveItem(new BaseItemStack(ItemTypes.get(we.getConfiguration().wandItem), 1));
|
||||||
player.print("Left click: select pos #1; Right click: select pos #2");
|
player.print("Left click: select pos #1; Right click: select pos #2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "toggleeditwand" },
|
name = "toggleeditwand",
|
||||||
usage = "",
|
desc = "Toggle functionality of the edit wand"
|
||||||
desc = "Toggle functionality of the edit wand",
|
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.wand.toggle")
|
@CommandPermissions("worldedit.wand.toggle")
|
||||||
public void toggleWand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void toggleWand(Player player, LocalSession session) throws WorldEditException {
|
||||||
|
|
||||||
session.setToolControl(!session.isToolControlEnabled());
|
session.setToolControl(!session.isToolControlEnabled());
|
||||||
|
|
||||||
if (session.isToolControlEnabled()) {
|
if (session.isToolControlEnabled()) {
|
||||||
@ -306,20 +269,23 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/expand" },
|
name = "/expand",
|
||||||
usage = "<amount> [reverse-amount] <direction>",
|
desc = "Expand the selection area"
|
||||||
desc = "Expand the selection area",
|
|
||||||
min = 1,
|
|
||||||
max = 3
|
|
||||||
)
|
)
|
||||||
@Logging(REGION)
|
@Logging(REGION)
|
||||||
@CommandPermissions("worldedit.selection.expand")
|
@CommandPermissions("worldedit.selection.expand")
|
||||||
public void expand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
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 {
|
||||||
|
|
||||||
// Special syntax (//expand vert) to expand the selection between
|
// Special syntax (//expand vert) to expand the selection between
|
||||||
// sky and bedrock.
|
// sky and bedrock.
|
||||||
if (args.getString(0).equalsIgnoreCase("vert")
|
if (amount.isVert()) {
|
||||||
|| args.getString(0).equalsIgnoreCase("vertical")) {
|
|
||||||
Region region = session.getSelection(player.getWorld());
|
Region region = session.getSelection(player.getWorld());
|
||||||
try {
|
try {
|
||||||
int oldSize = region.getArea();
|
int oldSize = region.getArea();
|
||||||
@ -338,57 +304,16 @@ public class SelectionCommands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BlockVector3> dirs = new ArrayList<>();
|
|
||||||
int change = args.getInteger(0);
|
|
||||||
int reverseChange = 0;
|
|
||||||
|
|
||||||
switch (args.argsLength()) {
|
|
||||||
case 2:
|
|
||||||
// Either a reverse amount or a direction
|
|
||||||
try {
|
|
||||||
reverseChange = args.getInteger(1);
|
|
||||||
dirs.add(we.getDirection(player, "me"));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
if (args.getString(1).contains(",")) {
|
|
||||||
String[] split = args.getString(1).split(",");
|
|
||||||
for (String s : split) {
|
|
||||||
dirs.add(we.getDirection(player, s.toLowerCase()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dirs.add(we.getDirection(player, args.getString(1).toLowerCase()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
// Both reverse amount and direction
|
|
||||||
reverseChange = args.getInteger(1);
|
|
||||||
if (args.getString(2).contains(",")) {
|
|
||||||
String[] split = args.getString(2).split(",");
|
|
||||||
for (String s : split) {
|
|
||||||
dirs.add(we.getDirection(player, s.toLowerCase()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dirs.add(we.getDirection(player, args.getString(2).toLowerCase()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dirs.add(we.getDirection(player, "me"));
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Region region = session.getSelection(player.getWorld());
|
Region region = session.getSelection(player.getWorld());
|
||||||
int oldSize = region.getArea();
|
int oldSize = region.getArea();
|
||||||
|
|
||||||
if (reverseChange == 0) {
|
if (reverseAmount == 0) {
|
||||||
for (BlockVector3 dir : dirs) {
|
for (BlockVector3 dir : direction) {
|
||||||
region.expand(dir.multiply(change));
|
region.expand(dir.multiply(amount.getAmount()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (BlockVector3 dir : dirs) {
|
for (BlockVector3 dir : direction) {
|
||||||
region.expand(dir.multiply(change), dir.multiply(-reverseChange));
|
region.expand(dir.multiply(amount.getAmount()), dir.multiply(-reverseAmount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,70 +322,33 @@ public class SelectionCommands {
|
|||||||
|
|
||||||
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
||||||
|
|
||||||
player.print("Region expanded " + (newSize - oldSize) + " blocks.");
|
player.print("Region expanded " + (newSize - oldSize) + " block(s).");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/contract" },
|
name = "/contract",
|
||||||
usage = "<amount> [reverse-amount] [direction]",
|
desc = "Contract the selection area"
|
||||||
desc = "Contract the selection area",
|
|
||||||
min = 1,
|
|
||||||
max = 3
|
|
||||||
)
|
)
|
||||||
@Logging(REGION)
|
@Logging(REGION)
|
||||||
@CommandPermissions("worldedit.selection.contract")
|
@CommandPermissions("worldedit.selection.contract")
|
||||||
public void contract(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void contract(Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Amount to contract the selection by")
|
||||||
List<BlockVector3> dirs = new ArrayList<>();
|
int amount,
|
||||||
int change = args.getInteger(0);
|
@Arg(desc = "Amount to contract the selection by in the other direction", def = "0")
|
||||||
int reverseChange = 0;
|
int reverseAmount,
|
||||||
|
@Arg(desc = "Direction to contract", def = Direction.AIM)
|
||||||
switch (args.argsLength()) {
|
@MultiDirection
|
||||||
case 2:
|
List<BlockVector3> direction) throws WorldEditException {
|
||||||
// Either a reverse amount or a direction
|
|
||||||
try {
|
|
||||||
reverseChange = args.getInteger(1);
|
|
||||||
dirs.add(we.getDirection(player, "me"));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
if (args.getString(1).contains(",")) {
|
|
||||||
String[] split = args.getString(1).split(",");
|
|
||||||
for (String s : split) {
|
|
||||||
dirs.add(we.getDirection(player, s.toLowerCase()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dirs.add(we.getDirection(player, args.getString(1).toLowerCase()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
// Both reverse amount and direction
|
|
||||||
reverseChange = args.getInteger(1);
|
|
||||||
if (args.getString(2).contains(",")) {
|
|
||||||
String[] split = args.getString(2).split(",");
|
|
||||||
for (String s : split) {
|
|
||||||
dirs.add(we.getDirection(player, s.toLowerCase()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dirs.add(we.getDirection(player, args.getString(2).toLowerCase()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
dirs.add(we.getDirection(player, "me"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Region region = session.getSelection(player.getWorld());
|
Region region = session.getSelection(player.getWorld());
|
||||||
int oldSize = region.getArea();
|
int oldSize = region.getArea();
|
||||||
if (reverseChange == 0) {
|
if (reverseAmount == 0) {
|
||||||
for (BlockVector3 dir : dirs) {
|
for (BlockVector3 dir : direction) {
|
||||||
region.contract(dir.multiply(change));
|
region.contract(dir.multiply(amount));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (BlockVector3 dir : dirs) {
|
for (BlockVector3 dir : direction) {
|
||||||
region.contract(dir.multiply(change), dir.multiply(-reverseChange));
|
region.contract(dir.multiply(amount), dir.multiply(-reverseAmount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
session.getRegionSelector(player.getWorld()).learnChanges();
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
||||||
@ -476,35 +364,22 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/shift" },
|
name = "/shift",
|
||||||
usage = "<amount> [direction]",
|
desc = "Shift the selection area"
|
||||||
desc = "Shift the selection area",
|
|
||||||
min = 1,
|
|
||||||
max = 2
|
|
||||||
)
|
)
|
||||||
@Logging(REGION)
|
@Logging(REGION)
|
||||||
@CommandPermissions("worldedit.selection.shift")
|
@CommandPermissions("worldedit.selection.shift")
|
||||||
public void shift(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void shift(Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Amount to shift the selection by")
|
||||||
List<BlockVector3> dirs = new ArrayList<>();
|
int amount,
|
||||||
int change = args.getInteger(0);
|
@Arg(desc = "Direction to contract", def = Direction.AIM)
|
||||||
if (args.argsLength() == 2) {
|
@MultiDirection
|
||||||
if (args.getString(1).contains(",")) {
|
List<BlockVector3> direction) throws WorldEditException {
|
||||||
for (String s : args.getString(1).split(",")) {
|
|
||||||
dirs.add(we.getDirection(player, s.toLowerCase()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dirs.add(we.getDirection(player, args.getString(1).toLowerCase()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dirs.add(we.getDirection(player, "me"));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Region region = session.getSelection(player.getWorld());
|
Region region = session.getSelection(player.getWorld());
|
||||||
|
|
||||||
for (BlockVector3 dir : dirs) {
|
for (BlockVector3 dir : direction) {
|
||||||
region.shift(dir.multiply(change));
|
region.shift(dir.multiply(amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getRegionSelector(player.getWorld()).learnChanges();
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
||||||
@ -518,81 +393,72 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/outset" },
|
name = "/outset",
|
||||||
usage = "<amount>",
|
desc = "Outset the selection area"
|
||||||
desc = "Outset the selection area",
|
|
||||||
help =
|
|
||||||
"Expands the selection by the given amount in all directions.\n" +
|
|
||||||
"Flags:\n" +
|
|
||||||
" -h only expand horizontally\n" +
|
|
||||||
" -v only expand vertically\n",
|
|
||||||
flags = "hv",
|
|
||||||
min = 1,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@Logging(REGION)
|
@Logging(REGION)
|
||||||
@CommandPermissions("worldedit.selection.outset")
|
@CommandPermissions("worldedit.selection.outset")
|
||||||
public void outset(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
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 {
|
||||||
Region region = session.getSelection(player.getWorld());
|
Region region = session.getSelection(player.getWorld());
|
||||||
region.expand(getChangesForEachDir(args));
|
region.expand(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
|
||||||
session.getRegionSelector(player.getWorld()).learnChanges();
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
||||||
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
||||||
player.print("Region outset.");
|
player.print("Region outset.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/inset" },
|
name = "/inset",
|
||||||
usage = "<amount>",
|
desc = "Inset the selection area"
|
||||||
desc = "Inset the selection area",
|
|
||||||
help =
|
|
||||||
"Contracts the selection by the given amount in all directions.\n" +
|
|
||||||
"Flags:\n" +
|
|
||||||
" -h only contract horizontally\n" +
|
|
||||||
" -v only contract vertically\n",
|
|
||||||
flags = "hv",
|
|
||||||
min = 1,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@Logging(REGION)
|
@Logging(REGION)
|
||||||
@CommandPermissions("worldedit.selection.inset")
|
@CommandPermissions("worldedit.selection.inset")
|
||||||
public void inset(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
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 {
|
||||||
Region region = session.getSelection(player.getWorld());
|
Region region = session.getSelection(player.getWorld());
|
||||||
region.contract(getChangesForEachDir(args));
|
region.contract(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
|
||||||
session.getRegionSelector(player.getWorld()).learnChanges();
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
||||||
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
||||||
player.print("Region inset.");
|
player.print("Region inset.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockVector3[] getChangesForEachDir(CommandContext args) {
|
private BlockVector3[] getChangesForEachDir(int amount, boolean onlyHorizontal, boolean onlyVertical) {
|
||||||
List<BlockVector3> changes = new ArrayList<>(6);
|
Stream.Builder<BlockVector3> changes = Stream.builder();
|
||||||
int change = args.getInteger(0);
|
|
||||||
|
|
||||||
if (!args.hasFlag('h')) {
|
if (!onlyHorizontal) {
|
||||||
changes.add((BlockVector3.UNIT_Y).multiply(change));
|
changes.add(BlockVector3.UNIT_Y);
|
||||||
changes.add((BlockVector3.UNIT_MINUS_Y).multiply(change));
|
changes.add(BlockVector3.UNIT_MINUS_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args.hasFlag('v')) {
|
if (!onlyVertical) {
|
||||||
changes.add((BlockVector3.UNIT_X).multiply(change));
|
changes.add(BlockVector3.UNIT_X);
|
||||||
changes.add((BlockVector3.UNIT_MINUS_X).multiply(change));
|
changes.add(BlockVector3.UNIT_MINUS_X);
|
||||||
changes.add((BlockVector3.UNIT_Z).multiply(change));
|
changes.add(BlockVector3.UNIT_Z);
|
||||||
changes.add((BlockVector3.UNIT_MINUS_Z).multiply(change));
|
changes.add(BlockVector3.UNIT_MINUS_Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
return changes.toArray(new BlockVector3[0]);
|
return changes.build().map(v -> v.multiply(amount)).toArray(BlockVector3[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/size" },
|
name = "/size",
|
||||||
flags = "c",
|
desc = "Get information about the selection"
|
||||||
usage = "",
|
|
||||||
desc = "Get information about the selection",
|
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.selection.size")
|
@CommandPermissions("worldedit.selection.size")
|
||||||
public void size(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void size(Player player, LocalSession session,
|
||||||
if (args.hasFlag('c')) {
|
@Switch(name = 'c', desc = "Get clipboard info instead")
|
||||||
|
boolean clipboardInfo) throws WorldEditException {
|
||||||
|
if (clipboardInfo) {
|
||||||
ClipboardHolder holder = session.getClipboard();
|
ClipboardHolder holder = session.getClipboard();
|
||||||
Clipboard clipboard = holder.getClipboard();
|
Clipboard clipboard = holder.getClipboard();
|
||||||
Region region = clipboard.getRegion();
|
Region region = clipboard.getRegion();
|
||||||
@ -602,7 +468,7 @@ public class SelectionCommands {
|
|||||||
player.print("Cuboid dimensions (max - min): " + size);
|
player.print("Cuboid dimensions (max - min): " + size);
|
||||||
player.print("Offset: " + origin);
|
player.print("Offset: " + origin);
|
||||||
player.print("Cuboid distance: " + size.distance(BlockVector3.ONE));
|
player.print("Cuboid distance: " + size.distance(BlockVector3.ONE));
|
||||||
player.print("# of blocks: " + (int) (size.getX() * size.getY() * size.getZ()));
|
player.print("# of blocks: " + (size.getX() * size.getY() * size.getZ()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,48 +492,41 @@ public class SelectionCommands {
|
|||||||
|
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/count" },
|
name = "/count",
|
||||||
usage = "<block>",
|
desc = "Counts the number of a certain type of block"
|
||||||
flags = "f",
|
|
||||||
desc = "Counts the number of a certain type of block",
|
|
||||||
min = 1,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.analysis.count")
|
@CommandPermissions("worldedit.analysis.count")
|
||||||
public void count(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
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 {
|
||||||
ParserContext context = new ParserContext();
|
ParserContext context = new ParserContext();
|
||||||
context.setActor(player);
|
context.setActor(player);
|
||||||
context.setExtent(player.getExtent());
|
context.setExtent(player.getExtent());
|
||||||
context.setWorld(player.getWorld());
|
context.setWorld(player.getWorld());
|
||||||
context.setSession(session);
|
context.setSession(session);
|
||||||
context.setRestricted(false);
|
context.setRestricted(false);
|
||||||
context.setPreferringWildcard(args.hasFlag('f'));
|
context.setPreferringWildcard(fuzzy);
|
||||||
|
|
||||||
Set<BaseBlock> searchBlocks = we.getBlockFactory().parseFromListInput(args.getString(0), context);
|
Set<BaseBlock> searchBlocks = we.getBlockFactory().parseFromListInput(blocks, context);
|
||||||
int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks);
|
int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks);
|
||||||
player.print("Counted: " + count);
|
player.print("Counted: " + count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/distr" },
|
name = "/distr",
|
||||||
usage = "",
|
desc = "Get the distribution of blocks in the selection"
|
||||||
desc = "Get the distribution of blocks in the selection",
|
|
||||||
help =
|
|
||||||
"Gets the distribution of blocks in the selection.\n" +
|
|
||||||
"The -c flag gets the distribution of your clipboard.\n" +
|
|
||||||
"The -d flag separates blocks by state",
|
|
||||||
flags = "cd",
|
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.analysis.distr")
|
@CommandPermissions("worldedit.analysis.distr")
|
||||||
public void distr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException, CommandException {
|
public void distr(Player player, LocalSession session, EditSession editSession,
|
||||||
|
@Switch(name = 'c', desc = "Get the distribution of the clipboard instead")
|
||||||
boolean separateStates = args.hasFlag('d');
|
boolean clipboardDistr,
|
||||||
|
@Switch(name = 'd', desc = "Separate blocks by state")
|
||||||
|
boolean separateStates) throws WorldEditException {
|
||||||
List<Countable<BlockState>> distribution;
|
List<Countable<BlockState>> distribution;
|
||||||
|
|
||||||
if (args.hasFlag('c')) {
|
if (clipboardDistr) {
|
||||||
Clipboard clipboard = session.getClipboard().getClipboard(); // throws if missing
|
Clipboard clipboard = session.getClipboard().getClipboard(); // throws if missing
|
||||||
BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates);
|
BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates);
|
||||||
RegionVisitor visitor = new RegionVisitor(clipboard.getRegion(), count);
|
RegionVisitor visitor = new RegionVisitor(clipboard.getRegion(), count);
|
||||||
@ -707,52 +566,65 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/sel", ";", "/desel", "/deselect" },
|
name = "/sel",
|
||||||
flags = "d",
|
aliases = { ";", "/desel", "/deselect" },
|
||||||
usage = "[cuboid|extend|poly|ellipsoid|sphere|cyl|convex]",
|
desc = "Choose a region selector"
|
||||||
desc = "Choose a region selector",
|
|
||||||
min = 0,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
public void select(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
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 {
|
||||||
final World world = player.getWorld();
|
final World world = player.getWorld();
|
||||||
if (args.argsLength() == 0) {
|
if (selector == null) {
|
||||||
session.getRegionSelector(world).clear();
|
session.getRegionSelector(world).clear();
|
||||||
session.dispatchCUISelection(player);
|
session.dispatchCUISelection(player);
|
||||||
player.print("Selection cleared.");
|
player.print("Selection cleared.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String typeName = args.getString(0);
|
|
||||||
final RegionSelector oldSelector = session.getRegionSelector(world);
|
final RegionSelector oldSelector = session.getRegionSelector(world);
|
||||||
|
|
||||||
final RegionSelector selector;
|
final RegionSelector newSelector;
|
||||||
if (typeName.equalsIgnoreCase("cuboid")) {
|
switch (selector) {
|
||||||
selector = new CuboidRegionSelector(oldSelector);
|
case CUBOID:
|
||||||
|
newSelector = new CuboidRegionSelector(oldSelector);
|
||||||
player.print("Cuboid: left click for point 1, right click for point 2");
|
player.print("Cuboid: left click for point 1, right click for point 2");
|
||||||
} else if (typeName.equalsIgnoreCase("extend")) {
|
break;
|
||||||
selector = new ExtendingCuboidRegionSelector(oldSelector);
|
case EXTEND:
|
||||||
|
newSelector = new ExtendingCuboidRegionSelector(oldSelector);
|
||||||
player.print("Cuboid: left click for a starting point, right click to extend");
|
player.print("Cuboid: left click for a starting point, right click to extend");
|
||||||
} else if (typeName.equalsIgnoreCase("poly")) {
|
break;
|
||||||
selector = new Polygonal2DRegionSelector(oldSelector);
|
case POLY: {
|
||||||
|
newSelector = new Polygonal2DRegionSelector(oldSelector);
|
||||||
player.print("2D polygon selector: Left/right click to add a point.");
|
player.print("2D polygon selector: Left/right click to add a point.");
|
||||||
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolygonVertexLimit();
|
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolygonVertexLimit();
|
||||||
limit.ifPresent(integer -> player.print(integer + " points maximum."));
|
limit.ifPresent(integer -> player.print(integer + " points maximum."));
|
||||||
} else if (typeName.equalsIgnoreCase("ellipsoid")) {
|
break;
|
||||||
selector = new EllipsoidRegionSelector(oldSelector);
|
}
|
||||||
|
case ELLIPSOID:
|
||||||
|
newSelector = new EllipsoidRegionSelector(oldSelector);
|
||||||
player.print("Ellipsoid selector: left click=center, right click to extend");
|
player.print("Ellipsoid selector: left click=center, right click to extend");
|
||||||
} else if (typeName.equalsIgnoreCase("sphere")) {
|
break;
|
||||||
selector = new SphereRegionSelector(oldSelector);
|
case SPHERE:
|
||||||
|
newSelector = new SphereRegionSelector(oldSelector);
|
||||||
player.print("Sphere selector: left click=center, right click to set radius");
|
player.print("Sphere selector: left click=center, right click to set radius");
|
||||||
} else if (typeName.equalsIgnoreCase("cyl")) {
|
break;
|
||||||
selector = new CylinderRegionSelector(oldSelector);
|
case CYL:
|
||||||
|
newSelector = new CylinderRegionSelector(oldSelector);
|
||||||
player.print("Cylindrical selector: Left click=center, right click to extend.");
|
player.print("Cylindrical selector: Left click=center, right click to extend.");
|
||||||
} else if (typeName.equalsIgnoreCase("convex") || typeName.equalsIgnoreCase("hull") || typeName.equalsIgnoreCase("polyhedron")) {
|
break;
|
||||||
selector = new ConvexPolyhedralRegionSelector(oldSelector);
|
case CONVEX:
|
||||||
|
case HULL:
|
||||||
|
case POLYHEDRON: {
|
||||||
|
newSelector = new ConvexPolyhedralRegionSelector(oldSelector);
|
||||||
player.print("Convex polyhedral selector: Left click=First vertex, right click to add more.");
|
player.print("Convex polyhedral selector: Left click=First vertex, right click to add more.");
|
||||||
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit();
|
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit();
|
||||||
limit.ifPresent(integer -> player.print(integer + " points maximum."));
|
limit.ifPresent(integer -> player.print(integer + " points maximum."));
|
||||||
} else {
|
break;
|
||||||
|
}
|
||||||
|
case UNKNOWN:
|
||||||
|
default:
|
||||||
CommandListBox box = new CommandListBox("Selection modes");
|
CommandListBox box = new CommandListBox("Selection modes");
|
||||||
StyledFragment contents = box.getContents();
|
StyledFragment contents = box.getContents();
|
||||||
StyledFragment tip = contents.createFragment(Style.RED);
|
StyledFragment tip = contents.createFragment(Style.RED);
|
||||||
@ -770,10 +642,10 @@ public class SelectionCommands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.hasFlag('d')) {
|
if (setDefaultSelector) {
|
||||||
RegionSelectorType found = null;
|
RegionSelectorType found = null;
|
||||||
for (RegionSelectorType type : RegionSelectorType.values()) {
|
for (RegionSelectorType type : RegionSelectorType.values()) {
|
||||||
if (type.getSelectorClass() == selector.getClass()) {
|
if (type.getSelectorClass() == newSelector.getClass()) {
|
||||||
found = type;
|
found = type;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -787,7 +659,7 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session.setRegionSelector(world, selector);
|
session.setRegionSelector(world, newSelector);
|
||||||
session.dispatchCUISelection(player);
|
session.dispatchCUISelection(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +59,8 @@ public class CommaSeparatedValuesConverter<T> implements ArgumentConverter<T> {
|
|||||||
if (maximum > -1) {
|
if (maximum > -1) {
|
||||||
result.append("up to ").append(maximum).append(' ');
|
result.append("up to ").append(maximum).append(' ');
|
||||||
}
|
}
|
||||||
result.append("comma separated values of ")
|
result.append("comma separated values of: ")
|
||||||
.append(delegate.describeAcceptableArguments());
|
.append(delegate.describeAcceptableArguments());
|
||||||
result.setCharAt(0, Character.toUpperCase(result.charAt(0)));
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.UnknownDirectionException;
|
|||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.internal.annotation.Direction;
|
import com.sk89q.worldedit.internal.annotation.Direction;
|
||||||
|
import com.sk89q.worldedit.internal.annotation.MultiDirection;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import org.enginehub.piston.CommandManager;
|
import org.enginehub.piston.CommandManager;
|
||||||
import org.enginehub.piston.converter.ArgumentConverter;
|
import org.enginehub.piston.converter.ArgumentConverter;
|
||||||
@ -46,16 +47,24 @@ public class DirectionConverter implements ArgumentConverter<BlockVector3> {
|
|||||||
return new AutoAnnotation_DirectionConverter_direction(includeDiagonals);
|
return new AutoAnnotation_DirectionConverter_direction(includeDiagonals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AutoAnnotation
|
||||||
|
private static MultiDirection multiDirection(boolean includeDiagonals) {
|
||||||
|
return new AutoAnnotation_DirectionConverter_multiDirection(includeDiagonals);
|
||||||
|
}
|
||||||
|
|
||||||
public static void register(WorldEdit worldEdit, CommandManager commandManager) {
|
public static void register(WorldEdit worldEdit, CommandManager commandManager) {
|
||||||
|
for (boolean includeDiagonals : new boolean[] { false, true }) {
|
||||||
|
DirectionConverter directionConverter = new DirectionConverter(worldEdit, includeDiagonals);
|
||||||
commandManager.registerConverter(
|
commandManager.registerConverter(
|
||||||
Key.of(BlockVector3.class, direction(false)),
|
Key.of(BlockVector3.class, direction(includeDiagonals)),
|
||||||
new DirectionConverter(worldEdit, false)
|
directionConverter
|
||||||
);
|
);
|
||||||
commandManager.registerConverter(
|
commandManager.registerConverter(
|
||||||
Key.of(BlockVector3.class, direction(true)),
|
Key.of(BlockVector3.class, multiDirection(includeDiagonals)),
|
||||||
new DirectionConverter(worldEdit, true)
|
CommaSeparatedValuesConverter.wrap(directionConverter)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final ImmutableSet<String> NON_DIAGONALS = ImmutableSet.of(
|
private static final ImmutableSet<String> NON_DIAGONALS = ImmutableSet.of(
|
||||||
"north", "south", "east", "west", "up", "down"
|
"north", "south", "east", "west", "up", "down"
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.sk89q.worldedit.command.argument;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
|
import org.enginehub.piston.CommandManager;
|
||||||
|
import org.enginehub.piston.converter.ArgumentConverter;
|
||||||
|
import org.enginehub.piston.converter.ConversionResult;
|
||||||
|
import org.enginehub.piston.converter.FailedConversion;
|
||||||
|
import org.enginehub.piston.converter.SuccessfulConversion;
|
||||||
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||||
|
import org.enginehub.piston.inject.Key;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public class EnumConverter<E extends Enum<E>> implements ArgumentConverter<E> {
|
||||||
|
|
||||||
|
public static void register(CommandManager commandManager) {
|
||||||
|
commandManager.registerConverter(Key.of(SelectorChoice.class),
|
||||||
|
new EnumConverter<>(SelectorChoice.class, SelectorChoice.UNKNOWN));
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ImmutableMap<String, E> map;
|
||||||
|
@Nullable
|
||||||
|
private final E unknownValue;
|
||||||
|
|
||||||
|
private EnumConverter(Class<E> enumClass, @Nullable E unknownValue) {
|
||||||
|
ImmutableSortedMap.Builder<String, E> map = ImmutableSortedMap.orderedBy(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
EnumSet<E> validValues = EnumSet.allOf(enumClass);
|
||||||
|
if (unknownValue != null) {
|
||||||
|
validValues.remove(unknownValue);
|
||||||
|
}
|
||||||
|
for (E e : validValues) {
|
||||||
|
map.put(e.name(), e);
|
||||||
|
}
|
||||||
|
this.map = map.build();
|
||||||
|
this.unknownValue = unknownValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeAcceptableArguments() {
|
||||||
|
return String.join("|", map.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConversionResult<E> convert(String argument, InjectedValueAccess context) {
|
||||||
|
E result = map.getOrDefault(argument, unknownValue);
|
||||||
|
return result == null
|
||||||
|
? FailedConversion.from(new IllegalArgumentException("Not a valid choice: " + argument))
|
||||||
|
: SuccessfulConversion.fromSingle(result);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.sk89q.worldedit.command.argument;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
public final class ExpandAmount {
|
||||||
|
|
||||||
|
public static ExpandAmount vert() {
|
||||||
|
return new ExpandAmount(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExpandAmount from(int amount) {
|
||||||
|
return new ExpandAmount(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private final Integer amount;
|
||||||
|
|
||||||
|
private ExpandAmount(@Nullable Integer amount) {
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVert() {
|
||||||
|
return amount == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmount() {
|
||||||
|
return checkNotNull(amount, "This amount is vertical, i.e. undefined");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.sk89q.worldedit.command.argument;
|
||||||
|
|
||||||
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import org.enginehub.piston.CommandManager;
|
||||||
|
import org.enginehub.piston.converter.ArgumentConverter;
|
||||||
|
import org.enginehub.piston.converter.ArgumentConverters;
|
||||||
|
import org.enginehub.piston.converter.ConversionResult;
|
||||||
|
import org.enginehub.piston.converter.SuccessfulConversion;
|
||||||
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||||
|
import org.enginehub.piston.inject.Key;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class ExpandAmountConverter implements ArgumentConverter<ExpandAmount> {
|
||||||
|
|
||||||
|
public static void register(CommandManager commandManager) {
|
||||||
|
commandManager.registerConverter(Key.of(ExpandAmount.class), new ExpandAmountConverter());
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ArgumentConverter<Integer> integerConverter =
|
||||||
|
ArgumentConverters.get(TypeToken.of(int.class));
|
||||||
|
|
||||||
|
private ExpandAmountConverter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeAcceptableArguments() {
|
||||||
|
return "`vert` or " + integerConverter.describeAcceptableArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getSuggestions(String input) {
|
||||||
|
return Stream.concat(Stream.of("vert"), integerConverter.getSuggestions(input).stream())
|
||||||
|
.filter(x -> x.startsWith(input))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConversionResult<ExpandAmount> convert(String argument, InjectedValueAccess context) {
|
||||||
|
if (argument.equalsIgnoreCase("vert")
|
||||||
|
|| argument.equalsIgnoreCase("vertical")) {
|
||||||
|
return SuccessfulConversion.fromSingle(ExpandAmount.vert());
|
||||||
|
}
|
||||||
|
return integerConverter.convert(argument, context).mapSingle(ExpandAmount::from);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.sk89q.worldedit.command.argument;
|
||||||
|
|
||||||
|
public enum SelectorChoice {
|
||||||
|
CUBOID,
|
||||||
|
EXTEND,
|
||||||
|
POLY,
|
||||||
|
ELLIPSOID,
|
||||||
|
SPHERE,
|
||||||
|
CYL,
|
||||||
|
CONVEX,
|
||||||
|
HULL,
|
||||||
|
POLYHEDRON,
|
||||||
|
UNKNOWN
|
||||||
|
}
|
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (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 Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.command.argument;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.math.Vector2;
|
||||||
|
import com.sk89q.worldedit.math.Vector3;
|
||||||
|
import org.enginehub.piston.CommandManager;
|
||||||
|
import org.enginehub.piston.converter.ArgumentConverter;
|
||||||
|
import org.enginehub.piston.converter.ArgumentConverters;
|
||||||
|
import org.enginehub.piston.converter.ConversionResult;
|
||||||
|
import org.enginehub.piston.converter.FailedConversion;
|
||||||
|
import org.enginehub.piston.converter.SimpleArgumentConverter;
|
||||||
|
import org.enginehub.piston.converter.SuccessfulConversion;
|
||||||
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||||
|
import org.enginehub.piston.inject.Key;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class VectorConverter<C, T> implements ArgumentConverter<T> {
|
||||||
|
public static void register(CommandManager commandManager) {
|
||||||
|
CommaSeparatedValuesConverter<Integer> intConverter = CommaSeparatedValuesConverter.wrap(ArgumentConverters.get(TypeToken.of(int.class)));
|
||||||
|
CommaSeparatedValuesConverter<Double> doubleConverter = CommaSeparatedValuesConverter.wrap(ArgumentConverters.get(TypeToken.of(double.class)));
|
||||||
|
commandManager.registerConverter(Key.of(BlockVector2.class),
|
||||||
|
new VectorConverter<>(
|
||||||
|
intConverter,
|
||||||
|
2,
|
||||||
|
cmps -> BlockVector2.at(cmps.get(0), cmps.get(1)),
|
||||||
|
"block vector with x and z"
|
||||||
|
));
|
||||||
|
commandManager.registerConverter(Key.of(Vector2.class),
|
||||||
|
new VectorConverter<>(
|
||||||
|
doubleConverter,
|
||||||
|
3,
|
||||||
|
cmps -> Vector2.at(cmps.get(0), cmps.get(1)),
|
||||||
|
"vector with x and z"
|
||||||
|
));
|
||||||
|
commandManager.registerConverter(Key.of(BlockVector3.class),
|
||||||
|
new VectorConverter<>(
|
||||||
|
intConverter,
|
||||||
|
2,
|
||||||
|
cmps -> BlockVector3.at(cmps.get(0), cmps.get(1), cmps.get(2)),
|
||||||
|
"block vector with x, y, and z"
|
||||||
|
));
|
||||||
|
commandManager.registerConverter(Key.of(Vector3.class),
|
||||||
|
new VectorConverter<>(
|
||||||
|
doubleConverter,
|
||||||
|
3,
|
||||||
|
cmps -> Vector3.at(cmps.get(0), cmps.get(1), cmps.get(2)),
|
||||||
|
"vector with x, y, and z"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ArgumentConverter<C> componentConverter;
|
||||||
|
private final int componentCount;
|
||||||
|
private final Function<List<C>, T> vectorConstructor;
|
||||||
|
private final String acceptableArguments;
|
||||||
|
|
||||||
|
|
||||||
|
private VectorConverter(ArgumentConverter<C> componentConverter,
|
||||||
|
int componentCount,
|
||||||
|
Function<List<C>, T> vectorConstructor,
|
||||||
|
String acceptableArguments) {
|
||||||
|
this.componentConverter = componentConverter;
|
||||||
|
this.componentCount = componentCount;
|
||||||
|
this.vectorConstructor = vectorConstructor;
|
||||||
|
this.acceptableArguments = acceptableArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeAcceptableArguments() {
|
||||||
|
return "any " + acceptableArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConversionResult<T> convert(String argument, InjectedValueAccess context) {
|
||||||
|
ConversionResult<C> components = componentConverter.convert(argument, context);
|
||||||
|
if (!components.isSuccessful()) {
|
||||||
|
return components.failureAsAny();
|
||||||
|
}
|
||||||
|
if (components.get().size() != componentCount) {
|
||||||
|
return FailedConversion.from(new IllegalArgumentException(
|
||||||
|
"Must have exactly " + componentCount + " vector components"));
|
||||||
|
}
|
||||||
|
T vector = vectorConstructor.apply(ImmutableList.copyOf(components.get()));
|
||||||
|
return SuccessfulConversion.fromSingle(vector);
|
||||||
|
}
|
||||||
|
}
|
@ -48,11 +48,16 @@ import com.sk89q.worldedit.command.SchematicCommands;
|
|||||||
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.ScriptingCommands;
|
import com.sk89q.worldedit.command.ScriptingCommands;
|
||||||
import com.sk89q.worldedit.command.ScriptingCommandsRegistration;
|
import com.sk89q.worldedit.command.ScriptingCommandsRegistration;
|
||||||
|
import com.sk89q.worldedit.command.SelectionCommands;
|
||||||
|
import com.sk89q.worldedit.command.SelectionCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.argument.Arguments;
|
import com.sk89q.worldedit.command.argument.Arguments;
|
||||||
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
|
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
|
||||||
import com.sk89q.worldedit.command.argument.DirectionConverter;
|
import com.sk89q.worldedit.command.argument.DirectionConverter;
|
||||||
|
import com.sk89q.worldedit.command.argument.EnumConverter;
|
||||||
|
import com.sk89q.worldedit.command.argument.ExpandAmountConverter;
|
||||||
import com.sk89q.worldedit.command.argument.MaskConverter;
|
import com.sk89q.worldedit.command.argument.MaskConverter;
|
||||||
import com.sk89q.worldedit.command.argument.PatternConverter;
|
import com.sk89q.worldedit.command.argument.PatternConverter;
|
||||||
|
import com.sk89q.worldedit.command.argument.VectorConverter;
|
||||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||||
import com.sk89q.worldedit.command.util.PermissionCondition;
|
import com.sk89q.worldedit.command.util.PermissionCondition;
|
||||||
import com.sk89q.worldedit.entity.Entity;
|
import com.sk89q.worldedit.entity.Entity;
|
||||||
@ -193,6 +198,9 @@ public final class PlatformCommandMananger {
|
|||||||
), count)
|
), count)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
VectorConverter.register(commandManager);
|
||||||
|
EnumConverter.register(commandManager);
|
||||||
|
ExpandAmountConverter.register(commandManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerAlwaysInjectedValues() {
|
private void registerAlwaysInjectedValues() {
|
||||||
@ -305,13 +313,17 @@ public final class PlatformCommandMananger {
|
|||||||
ScriptingCommandsRegistration.builder(),
|
ScriptingCommandsRegistration.builder(),
|
||||||
new ScriptingCommands(worldEdit)
|
new ScriptingCommands(worldEdit)
|
||||||
);
|
);
|
||||||
|
register(
|
||||||
|
commandManager,
|
||||||
|
SelectionCommandsRegistration.builder(),
|
||||||
|
new SelectionCommands(worldEdit)
|
||||||
|
);
|
||||||
|
|
||||||
// Unported commands are below. Delete once they're added to the main manager above.
|
// Unported commands are below. Delete once they're added to the main manager above.
|
||||||
/*
|
/*
|
||||||
dispatcher = new CommandGraph()
|
dispatcher = new CommandGraph()
|
||||||
.builder(builder)
|
.builder(builder)
|
||||||
.commands()
|
.commands()
|
||||||
.registerMethods(new SelectionCommands(worldEdit))
|
|
||||||
.registerMethods(new SnapshotUtilCommands(worldEdit))
|
.registerMethods(new SnapshotUtilCommands(worldEdit))
|
||||||
.registerMethods(new ToolUtilCommands(worldEdit))
|
.registerMethods(new ToolUtilCommands(worldEdit))
|
||||||
.registerMethods(new ToolCommands(worldEdit))
|
.registerMethods(new ToolCommands(worldEdit))
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (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 Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.internal.annotation;
|
||||||
|
|
||||||
|
import org.enginehub.piston.inject.InjectAnnotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotates a {@code List<BlockVector3>} parameter to inject multiple direction.
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.PARAMETER)
|
||||||
|
@InjectAnnotation
|
||||||
|
public @interface MultiDirection {
|
||||||
|
boolean includeDiagonals() default false;
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren