mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-16 03:14:04 +00:00
Reimplement l2d, l3d, existing and buffer pattern (#684)
* Reimplement l2d, l3d, existing and buffer pattern Also smaller translation improvements and cleanup * Allow aliases in RichParser
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.command.util;
|
||||
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.worldedit.registry.Keyed;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.registry.Registry;
|
||||
@@ -35,6 +36,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.enginehub.piston.converter.SuggestionHelper.byPrefix;
|
||||
@@ -173,4 +175,57 @@ public final class SuggestionHelper {
|
||||
Predicate<String> search = byPrefix(input.toLowerCase(Locale.ROOT));
|
||||
return registry.keySet().stream().filter(search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of suggestions for positive doubles.
|
||||
*
|
||||
* @param argumentInput the given input to filter with.
|
||||
* @return a stream of suggestions.
|
||||
*/
|
||||
public static Stream<String> suggestPositiveDoubles(String argumentInput) {
|
||||
if (argumentInput.isEmpty()) {
|
||||
return Stream.of("1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
}
|
||||
// if already a valid number, suggest more digits
|
||||
if (isDouble(argumentInput)) {
|
||||
Stream<String> numbers = Stream.of("", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
if (argumentInput.indexOf('.') == -1) {
|
||||
numbers = Stream.concat(numbers, Stream.of("."));
|
||||
}
|
||||
return numbers.map(s -> argumentInput + s);
|
||||
}
|
||||
// no valid input anymore
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of suggestions for positive integers.
|
||||
*
|
||||
* @param argumentInput the given input to filter with.
|
||||
* @return a stream of suggestions.
|
||||
*/
|
||||
public static Stream<String> suggestPositiveIntegers(String argumentInput) {
|
||||
if (argumentInput.isEmpty()) {
|
||||
return IntStream.rangeClosed(1, 9).mapToObj(Integer::toString);
|
||||
}
|
||||
if (MathMan.isInteger(argumentInput)) {
|
||||
return IntStream.rangeClosed(0, 9).mapToObj(Integer::toString).map(s -> argumentInput + s);
|
||||
}
|
||||
// no valid input anymore
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
private static boolean isDouble(String input) {
|
||||
boolean point = false;
|
||||
for (char c : input.toCharArray()) {
|
||||
if (!Character.isDigit(c)) {
|
||||
if (c == '.' && !point) {
|
||||
point = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user