Skip to content

Conversation

@stumper66
Copy link

Added a new option: allowAnyValue
This allows me to use ListArgumentBuilder for complex tab suggestions and simply passing all input so I can do my own validation.

This allowed me to create this command: https://youtu.be/q03_paw9Vzk

stumper66 and others added 7 commits June 26, 2024 15:42
Added a new option: allowAnyValue
Co-authored-by: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com>
Co-authored-by: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com>
Updated to add exception if non-string mappers are used
@stumper66 stumper66 changed the title Dev/dev Add allowAnyValue Jul 12, 2024
* @return this list argument builder
*/
public ListArgumentBuilderFinished withMapper(Function<T, String> mapper) {
if (allowAnyValue && !(mapper instanceof StringTooltip)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This instanceof check is not necessary as it will always evaluate to true.

*/
public ListArgumentBuilderFinished withMapper(Function<T, String> mapper) {
if (allowAnyValue && !(mapper instanceof StringTooltip)){
throw new IllegalArgumentException("allowAnyValue cannot be used with non-string mappers");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this should be something like:
allowAnyValue can only be set to true if a String mapper is used.

However, I do not know if that even is better so maybe we could wait for other opinions too.

Comment on lines +147 to +148
// should only be used with string mappers so we can ignore the cast warning
list.add((T) str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// should only be used with string mappers so we can ignore the cast warning
list.add((T) str);
list.add(values.get(str));

As we have the map, I think we should use it instead of resorting to generic casts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DerEchtePilz when I use the mapper it will give me a list of nulls. The only way I've found that works is to directly cast the string to T.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that sounds like a bug to me that should get fixed. I am currently not available to test anything related to the ListArgument but using the mapper should most definitely not result in null values.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's a bug but maybe just a design flaw. The mapper value only works if the input is in the suggestions list.
That part might not be compatible with what we're trying to accomplish so that's why we made allowAnyValue only valid with strings since we need to cast the string input to T.

// should only be used with string mappers so we can ignore the cast warning
list.add((T) str);
}
else{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else{
else {

$$\downarrow$$
> ### Allowing any value (Optional)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this section I think we should mention that the allowAnyValue option only works for Strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants