FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add allowAnyValue by stumper66 · Pull Request #576 · CommandAPI/CommandAPI · GitHub

Add allowAnyValue - #576

Open
stumper66 wants to merge 7 commits into
CommandAPI:dev/devfrom
stumper66:dev/dev
Open

Add allowAnyValue#576
stumper66 wants to merge 7 commits into
CommandAPI:dev/devfrom
stumper66:dev/dev

Conversation

Copy link
Copy Markdown

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 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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
else{
else {


$$\downarrow$$

> ### Allowing any value (Optional)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL