How to get arguments in command code?

I have this code:

I need to get arguments in command implementation.
More simple: I wanna get firstArg and it’s valArg from command format /cmd firstArg valArg. How to do that? My brain have started boiling.

It seems like your trying to use the newer command API in the older way. From what it looks like, a good read of the docs would do you some good. Heres a link of the docs on commands.

https://docs.spongepowered.org/stable/en/plugin/commands/index.html

With the newer command API (which is what your using), it is designed so you treat each child argument on its own. Lets take your example as the example.

The way your currently registering the command is that all arguments can only be strings and that there is only a single pathway of arguments with the following usage.

/command <create> <invite> <kick> <destruct> <name> <nickname>

my guess based on your titles is your want the first 4 to be interchangeable with “name” and “nickname” being interchangable too only as the second command, so the usage is this.

/command <"create" / "invite" / "kick" / "destruct"> <name / nickname>

This is where the newer command API comes in so helpful as you can register the command with the latter usage like so

public static CommandSpec buildCommand(){
    CommandSpec createCommand = CommandSpec.builder()
            .arguments(GenericArguments.string(NAME))
            .executor(new CreateCommand())
            .build();
    //BUILD OTHER ARGUMENTS
    return CommandSpec.builder()
            .child(createCommand, "create", "c")
            //register other commands
            .build();
}

Some developers prefer to use the Flag argument instead of the child function, the only difference is using the child function your able to seperate out the arguments.

Now in the executor all you need to do is the following to gain that name

String name = args.<String>getOne(NAME).get();

Note how the NAME is a field, this is because the registered argument and this need to the same and thats personally why I use fields.

I cannot seperate out the name and nickname as they both were strings, however you are able to create your own “CommandElement” by extending the class and then registering that as the argument, if you create one that finds the object with the same name as what is provided you could then register the arguments like the following

GenericArguments.firstParsing(new ByName(NAME), new ByNickname(NICKNAME))

From there you could get the object like so

YourObject thing = args.getOne(NAME).orElse(args.getOne(NICKNAME));

which im sure you will agree is more usful then just the nickname/name of the thing.

Hope that helps