Closed
Description
Description
We can currently create dynamic lists for the ListArgument
using the supplier method:
public ListArgumentBuilder withList(Supplier<Collection<T>> list);
as well as using this function method that accepts a CommandSender
:
public ListArgumentBuilder withList(Function<CommandSender, Collection<T>> list);
However, these two methods don't let you specify lists based on the current input. Since the list declarations are used directly by suggestions, there's no reason why the CommandAPI should be hiding this functionality away.
Expected code
In ListArgumentCommon
, we'd have to change the supplier to use SuggestionInfo
, and ensure this is applied:
private void applySuggestions() {
this.replaceSuggestions((info, builder) -> {
String currentArg = info.currentArg();
if(text && currentArg.startsWith("\"")) {
// Ignore initial " when suggesting for TextArgument
currentArg = currentArg.substring(1);
builder = builder.createOffset(builder.getStart() + 1);
}
// This need not be a sorted map because entries in suggestions are
// automatically sorted anyway
Set<IStringTooltip> values = new HashSet<>();
- for (T object : supplier.apply(info.sender())) {
+ for (T object : supplier.apply(info)) {
values.add(mapper.apply(object));
}
Extra details
For 9.0.0, I think it's safe to hard-replace withList(Function<CommandSender, ...>)
with withList(Function<SuggestionInfo, ...>)
. We'll include it in the upgrading guide with the relevant instructions for upgrading.