How to add optional command flags?

I would like this to work like:

/sethome [-force] [name] 

Both the flag “force” and string parameter “name” are optional arguments. Can someone point me in the right direction?

CommandSpec

CommandSpec setHomeCommand = CommandSpec.builder()
	.setDescription(Texts.of("Set location as home"))
	.setExtendedDescription(Texts.of("Set this location as a home. Optional: /sethome [name]"))
	.setExecutor(new SetHomeCommand(this))
	.setArguments(GenericArguments.optional(
		GenericArguments.string(Texts.of("name"))))
	.build();

Maybe try adding a second optional string argument to handle flags ?

1 Like

There is something called:

GenericArguments.flags()

It returns a builder(), but I am not sure if this is what I need or not, nor do I know how to use it. :confused:

However, your idea would definitely work! I may just do that in the mean time.

Oh Indeed I hadn’t noticed SpongeAPI had options for flags :open_mouth:. If you look in the test classes on github you can see an example how to use it.

2 Likes