Question How to add else part to BrigadierCommand

CripeHD

New member
Jun 17, 2022
2
0
1
Hey, I'm trying to create a command with BrigadierCommand.

Command:
/Server <Server>

If the player execute this command he send to the <server>. My problem is that I want to send the player a usage message if he only use "/Server", "/Server something something" so for all other cases where the argument length is not one. Here is my code:

Java:
  LiteralCommandNode<CommandSource> cmd = LiteralArgumentBuilder
                .<CommandSource>literal("server")
                .then(RequiredArgumentBuilder.<CommandSource, String>argument("argument", StringArgumentType.word())
                        .executes(context -> {
                            // send player to the server
                            return 1;
                        })
                        .build()
                )
                // else part ???
                .build();
 
Version Output
Velocity 3.1.2-SNAPSHOT (git-74edac96-b153)

electronicboy

Administrator
Staff member
Dec 11, 2021
216
10
34
28
You'd need to make the argument not required, and then handle cases where you have that arg, and cases where you don't have that arg; ofc, directly working with brigadier is somewhat niche still within the wider community, and there are many dozen command frameworks people work with instead