10000 The ListArgumentBuilder should be able to accept a list that uses Suggestion Info, not just a CommandSender · Issue #431 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content
The ListArgumentBuilder should be able to accept a list that uses Suggestion Info, not just a CommandSender #431
Closed
@JorelAli

Description

@JorelAli

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.

Metada 47A2 ta

Metadata

Assignees

Labels

enhancementNew feature or requestimplemented for next releaseThis has been implemented in the current dev build for the next public release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0