Question Correct Way To Do Async Brigadier

StudentALleg

New member
Feb 18, 2025
1
0
1
Hello,
I am working on porting our Command system over to Brigadier, and have run into a snag.
You cannot throw `CommandSyntaxException`s from a CompletableFuture or Consumer.

My understanding is that `CommandSyntaxException`s are how you communicate that a command has an improper input. I assume this is also how arguments know to check the next argument type.

We store information about players that have connected to our server in an Object called the client (this would be name, id, rank). When trying to get an offline player, we goto a DB to get this information. Since brigadier commands are run on the main thread, we use a CompletableFuture to retrieve an Optional<Client> (this query could take a long time). My assumption is that I should be throwing a CommandSyntaxException if such a Client does not exist (i.e. a misspelled name), but am unable to do so (Compiler flags the unhandled exception and transforms it to a runtime exception, which does not trigger what a CommandSyntaxException would).

So my question is, what is the proper way to do async with brigadier commands? Is it using CompletableFutures without throwing a CommandSyntaxException and manually informing the player? Or is there a more correct way?
 
Version Output
This server is running Paper version 1.21.1-132-ver/1.21.1@b48403b (2024-11-21T10:14:27Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.1-116-e7e1ab5 (MC: 1.21.1)