Skip to content

Add an adjacent option for the offset mark parser #2749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public OffsetMaskParser(WorldEdit worldEdit) {
@Override
public Stream<String> getSuggestions(String input, ParserContext context) {
if (input.isEmpty()) {
return Stream.of(">", "<");
return Stream.of(">", "<", "~");
}
final char firstChar = input.charAt(0);
if (firstChar != '>' && firstChar != '<') {
if (firstChar != '>' && firstChar != '<' && firstChar != '~') {
return Stream.empty();
}
return worldEdit.getMaskFactory().getSuggestions(input.substring(1), context).stream().map(s -> firstChar + s);
Expand All @@ -51,7 +51,7 @@ public Stream<String> getSuggestions(String input, ParserContext context) {
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
final char firstChar = input.charAt(0);
if (firstChar != '>' && firstChar != '<') {
if (firstChar != '>' && firstChar != '<' && firstChar != '~') {
return null;
}

Expand All @@ -61,6 +61,10 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars
} else {
submask = new ExistingBlockMask(context.requireExtent());
}
return OffsetsMask.single(submask, BlockVector3.at(0, firstChar == '>' ? -1 : 1, 0));
if (firstChar == '~') {
return OffsetsMask.adjacent(submask);
} else {
return OffsetsMask.single(submask, BlockVector3.at(0, firstChar == '>' ? -1 : 1, 0));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public static OffsetsMask single(Mask mask, BlockVector3 offset) {
return builder(mask).maxMatches(1).offsets(ImmutableList.of(offset)).build();
}

/**
* Create an offsets mask for any adjacent offset.
*
* @param mask the mask to use
* @return the new offsets mask
*/
public static OffsetsMask adjacent(Mask mask) {
return builder(mask).minMatches(1).offsets(OFFSET_LIST).build();
}

/**
* Create a new builder, using the given mask.
* @param mask the mask to use
Expand Down Expand Up @@ -157,7 +167,7 @@ private OffsetsMask(Mask mask, boolean excludeSelf, int minMatches, int maxMatch
checkArgument(minMatches <= maxMatches, "minMatches must be less than or equal to maxMatches");
checkArgument(minMatches >= 0, "minMatches must be greater than or equal to 0");
checkArgument(minMatches <= offsets.size(), "minMatches must be less than or equal to the number of offsets");
checkArgument(offsets.size() > 0, "offsets must have at least one element");
checkArgument(!offsets.isEmpty(), "offsets must have at least one element");

this.mask = mask;
this.excludeSelf = excludeSelf;
Expand Down
Loading