8000 Add Option for Automatic Exception on Empty EntitySelectorArgument Lists · Issue #495 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content

Add Option for Automatic Exception on Empty EntitySelectorArgument Lists #495

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

Closed
8000
learliet opened this issue Oct 7, 2023 · 2 comments
Closed
Labels
enhancement New feature or request implemented for next release This has been implemented in the current dev build for the next public release

Comments

@learliet
Copy link
learliet commented Oct 7, 2023

Description

There should be an option available when utilizing the EntitySelectorArgument to trigger an exception automatically when the resulting list is empty. This behavior mirrors the default implementation where argument.entity.notfound.entity or argument.entity.notfound.player is respectively returned.

Expected code

val myCommand = CommandAPICommand("myCommand")
  .withArguments(EntitySelectorArgument.ManyPlayers("players", false)) // allowEmpty flag
  .executes(CommandExecutor { sender, args ->
      // automatically returns "argument.entity.notfound.player" if empty
      val players = args[0] as List<Player> 
      // [...]
  })

Extra details

No response

@learliet learliet added the enhancement New feature or request label Oct 7, 2023
@JorelAli
Copy link
Member

I like this idea, and it should be fairly trivial to implement. In our existing multiple entity selector code, we have this:

https://github.com/JorelAli/CommandAPI/blob/38a1a7682633a2095366095db183850e1a9d99eb/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java#L353-L372

In this implementation, we catch the exception when the list of entities would be empty and instead return an empty array. Adding a parameter to allow this exception to bubble up should be available as an option.

It would be nice to get this implemented for our next release given how simple this is to implement.

@JorelAli JorelAli added the scheduled for next release This will be implemented for the next public release label Oct 19, 2023
JorelAli added a commit that referenced this issue Dec 11, 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 Dec 11, 2023
JorelAli added a commit that referenced this issue Dec 11, 2023
DerEchtePilz added a commit that referenced this issue Dec 12, 2023
@JorelAli
Copy link
Member

Implemented in version 9.4.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
None yet
Development

No branches or pull requests

2 participants
0