3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 18:40:05 +01:00

Fix tab completion when *not* using %.

- Also allow tab-completion of % pattern when it's the first/only pattern being used
 - Also don't error when attempting to tab complete an invalid percent value
Dieser Commit ist enthalten in:
dordsor21 2021-11-18 18:42:19 +00:00
Ursprung 5604000ae2
Commit ef61ecccaa
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
2 geänderte Dateien mit 21 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -32,6 +32,8 @@ import java.util.stream.Stream;
public class RichPatternParser extends FaweParser<Pattern> {
private static final java.util.regex.Pattern percentPatternRegex = java.util.regex.Pattern.compile("[0-9]+(\\.[0-9]*)?%.*");
/**
* Create a new rich pattern-parser.
*
@ -110,7 +112,7 @@ public class RichPatternParser extends FaweParser<Pattern> {
pattern = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
} else {
int percentIndex = command.indexOf('%');
if (percentIndex != -1) { // Legacy percent pattern
if (percentIndex != -1 && percentPatternRegex.matcher(command).matches()) { // Legacy percent pattern
chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
String value = command.substring(percentIndex + 1);
if (!entry.getValue().isEmpty()) {

Datei anzeigen

@ -15,6 +15,8 @@ import java.util.stream.Stream;
public class RandomPatternParser extends InputParser<Pattern> {
private static final java.util.regex.Pattern regex = java.util.regex.Pattern.compile("[0-9]+(\\.[0-9]*)?%.*");
/**
* Create a new input parser.
*
@ -28,26 +30,35 @@ public class RandomPatternParser extends InputParser<Pattern> {
public Stream<String> getSuggestions(String input) {
//FAWE start
List<String> patterns = StringUtil.split(input, ',', '[', ']');
if (patterns.size() == 1) {
if (patterns.size() == 0) {
return Stream.empty();
}
// get suggestions for the last token only
String token = patterns.get(patterns.size() - 1);
String randString = "";
String previous = String.join(",", patterns.subList(0, patterns.size() - 1));
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
String percent;
String previous;
if (patterns.size() != 1) {
previous = String.join(",", patterns.subList(0, patterns.size() - 1));
percent = ",";
} else {
previous = "";
percent = "";
}
if (regex.matcher(token).matches()) {
String[] p = token.split("%");
if (p.length < 2) {
return Stream.empty();
} else {
randString = p[0];
percent += p[0] + "%";
token = p[1];
}
} else {
return Stream.empty();
}
final List<String> innerSuggestions = worldEdit.getPatternFactory().getSuggestions(token);
String prev = previous + "," + randString + "%";
return innerSuggestions.stream().map(s -> prev + s);
String prefix = previous + percent;
//FAWE end
return innerSuggestions.stream().map(s -> prefix + s);
}
@Override