Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The ListArgumentBuilder should be able to accept a list that uses Suggestion Info, not just a CommandSender #431

Closed
JorelAli opened this issue Apr 18, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request implemented for next release This has been implemented in the current dev build for the next public release
Milestone

Comments

@JorelAli
Copy link
Owner

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.

@JorelAli JorelAli added enhancement New feature or request scheduled for next release This will be implemented for the next public release labels Apr 18, 2023
@JorelAli JorelAli added this to the 9.0.0 milestone Apr 18, 2023
@JorelAli JorelAli self-assigned this Apr 18, 2023
@JorelAli JorelAli added implemented for next release This has been implemented in the current dev build for the next public release and removed scheduled for next release This will be implemented for the next public release labels Apr 18, 2023
@JorelAli
Copy link
Owner Author

Implemented in 9.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request implemented for next release This has been implemented in the current dev build for the next public release
Projects
Archived in project
Development

No branches or pull requests

1 participant