Skip to content

Commit 961ff9d

Browse files
committed
Add an adjacent option for the offset mark parser
1 parent 2b54302 commit 961ff9d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/OffsetMaskParser.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public OffsetMaskParser(WorldEdit worldEdit) {
3939
@Override
4040
public Stream<String> getSuggestions(String input, ParserContext context) {
4141
if (input.isEmpty()) {
42-
return Stream.of(">", "<");
42+
return Stream.of(">", "<", "~");
4343
}
4444
final char firstChar = input.charAt(0);
45-
if (firstChar != '>' && firstChar != '<') {
45+
if (firstChar != '>' && firstChar != '<' && firstChar != '~') {
4646
return Stream.empty();
4747
}
4848
return worldEdit.getMaskFactory().getSuggestions(input.substring(1), context).stream().map(s -> firstChar + s);
@@ -51,7 +51,7 @@ public Stream<String> getSuggestions(String input, ParserContext context) {
5151
@Override
5252
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
5353
final char firstChar = input.charAt(0);
54-
if (firstChar != '>' && firstChar != '<') {
54+
if (firstChar != '>' && firstChar != '<' && firstChar != '~') {
5555
return null;
5656
}
5757

@@ -61,6 +61,10 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars
6161
} else {
6262
submask = new ExistingBlockMask(context.requireExtent());
6363
}
64-
return OffsetsMask.single(submask, BlockVector3.at(0, firstChar == '>' ? -1 : 1, 0));
64+
if (firstChar == '~') {
65+
return OffsetsMask.adjacent(submask);
66+
} else {
67+
return OffsetsMask.single(submask, BlockVector3.at(0, firstChar == '>' ? -1 : 1, 0));
68+
}
6569
}
6670
}

worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetsMask.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ public static OffsetsMask single(Mask mask, BlockVector3 offset) {
5353
return builder(mask).maxMatches(1).offsets(ImmutableList.of(offset)).build();
5454
}
5555

56+
/**
57+
* Create an offsets mask for any adjacent offset.
58+
*
59+
* @param mask the mask to use
60+
* @return the new offsets mask
61+
*/
62+
public static OffsetsMask adjacent(Mask mask) {
63+
return builder(mask).minMatches(1).offsets(OFFSET_LIST).build();
64+
}
65+
5666
/**
5767
* Create a new builder, using the given mask.
5868
* @param mask the mask to use
@@ -157,7 +167,7 @@ private OffsetsMask(Mask mask, boolean excludeSelf, int minMatches, int maxMatch
157167
checkArgument(minMatches <= maxMatches, "minMatches must be less than or equal to maxMatches");
158168
checkArgument(minMatches >= 0, "minMatches must be greater than or equal to 0");
159169
checkArgument(minMatches <= offsets.size(), "minMatches must be less than or equal to the number of offsets");
160-
checkArgument(offsets.size() > 0, "offsets must have at least one element");
170+
checkArgument(!offsets.isEmpty(), "offsets must have at least one element");
161171

162172
this.mask = mask;
163173
this.excludeSelf = excludeSelf;

0 commit comments

Comments
 (0)