Add number TabCompleting
Dieser Commit ist enthalten in:
Ursprung
b6e4147af4
Commit
b3fffe398a
@ -71,8 +71,12 @@ public class Argument<T> {
|
|||||||
|
|
||||||
public Optional<List<String>> tabCompleteSupplier(String s) {
|
public Optional<List<String>> tabCompleteSupplier(String s) {
|
||||||
try {
|
try {
|
||||||
|
if (!s.isEmpty()) {
|
||||||
// Check if mappable
|
// Check if mappable
|
||||||
if (!s.isEmpty()) argumentType.mapper.apply(s);
|
T argumentMapped = argumentType.mapper.apply(s);
|
||||||
|
// Check number constraints if needed
|
||||||
|
if (argumentType.number && !constraint.test(argumentMapped)) return Optional.empty();
|
||||||
|
}
|
||||||
List<String> strings = Arrays.stream(tabCompletes).filter(t -> t.startsWith(s)).collect(Collectors.toList());
|
List<String> strings = Arrays.stream(tabCompletes).filter(t -> t.startsWith(s)).collect(Collectors.toList());
|
||||||
if (strings.isEmpty()) strings.add(s);
|
if (strings.isEmpty()) strings.add(s);
|
||||||
return Optional.of(strings);
|
return Optional.of(strings);
|
||||||
|
@ -25,16 +25,18 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class ArgumentType<T> {
|
public class ArgumentType<T> {
|
||||||
|
|
||||||
public static final ArgumentType<Integer> INT = new ArgumentType<>(Integer::parseInt);
|
public static final ArgumentType<Integer> INT = new ArgumentType<>(Integer::parseInt, true);
|
||||||
public static final ArgumentType<Long> LONG = new ArgumentType<>(Long::parseLong);
|
public static final ArgumentType<Long> LONG = new ArgumentType<>(Long::parseLong, true);
|
||||||
public static final ArgumentType<Float> FLOAT = new ArgumentType<>(Float::parseFloat);
|
public static final ArgumentType<Float> FLOAT = new ArgumentType<>(Float::parseFloat, true);
|
||||||
public static final ArgumentType<Double> DOUBLE = new ArgumentType<>(Double::parseDouble);
|
public static final ArgumentType<Double> DOUBLE = new ArgumentType<>(Double::parseDouble, true);
|
||||||
public static final ArgumentType<String> STRING = new ArgumentType<>((s) -> s);
|
public static final ArgumentType<String> STRING = new ArgumentType<>((s) -> s, false);
|
||||||
|
|
||||||
Function<String, T> mapper;
|
Function<String, T> mapper;
|
||||||
|
boolean number;
|
||||||
|
|
||||||
private ArgumentType(Function<String, T> mapper) {
|
private ArgumentType(Function<String, T> mapper, boolean number) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
|
this.number = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class SWCommandBundle {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SWCommandBundle add(SWCommandBundle swCommandBundle) {
|
public SWCommandBundle addAll(SWCommandBundle swCommandBundle) {
|
||||||
if (swCommandBundle == null) return this;
|
if (swCommandBundle == null) return this;
|
||||||
swCommandList.addAll(swCommandBundle.swCommandList);
|
swCommandList.addAll(swCommandBundle.swCommandList);
|
||||||
return this;
|
return this;
|
||||||
@ -51,4 +51,13 @@ public class SWCommandBundle {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> tabComplete(String[] args) {
|
||||||
|
List<String> strings = new ArrayList<>();
|
||||||
|
for (SWCommand swCommand : swCommandList) {
|
||||||
|
Optional<List<String>> tabCompletes = swCommand.tabComplete(args);
|
||||||
|
if (tabCompletes.isPresent()) strings.addAll(tabCompletes.get());
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren