Skip to content
Andre_601 edited this page Mar 8, 2021 · 8 revisions

Work in Progress

This Wiki Page is still Work in Progress and misses a lot of the features provided by Commodore and the Brigadier library.
If you want to help, feel free to add missing information or correct wrong ones.

Commodore allows you to define different Types for the arguments that change how command and argument suggestions are displayed and handled.

Depending on whether you use the .commodore file format or the LiteralArgumentBuilder to create LiteralCommandNode<?>s will the syntax look different.

General format

The .commodore and LiteralArgumentBuilder offer both a specific syntax that should be followed.

.commodore file

The .commodore file's follows a syntax similar to JSON with some differences to it.
It may look like this:

<command> {
  <literal>;
  <literal> {
    <argument> brigadier:<type>;
  }
  <literal> {
    <literal>;
    <argument> brigadier:<type> <option>;
  }
}

The first argument (<command>) always has to be the command to apply the suggestions towards.
It cannot have any of the different options applied.

Any arguments afterwards can be either a <literal> String or <argument> String.

  • <literal> is, as the name suggests, a literal string that would show up in the argument list of the tab-completion.
    This means that whatever you set for this String would be selectable from the tab-completion menu. Adding any options to it turns it into an <argument>.
  • <argument>s are placeholder text used for where you would insert custom input. They are set by adding any brigadier: option to the String itself.

Code

You use the LiteralArgumentBuilder from the Brigadier Library to set the different arguments.
The same structure from the .commodore file example would look like this in Java:

LiteralCommandNode<?> command = LiteralArgumentBuilder.literal("<command>")
        .then(LiteralArgumentBuilder.literal("<literal>"))
        .then(LiteralArgumentBuilder.literal("<literal>")
            .then(RequiredArgumentBuilder.argument("<argument>", ArgumentType<?>))
        )
        .then(LiteralArgumentBuilder.literal("<literal>")
            .then(LiteralArgumentBuilder.literal("<literal>"))
            .then(RequiredArgumentBuilder.argument("<argument>", ArgumentType<?>))
        )
        .build();

Limitations

There are certain limitations when using the Commodore Library, which mostly come from the Brigadier library:

  • You can only have one <argument> per level. It is not possible to define multiple arguments on the same level. Once you set an argument can only extra <literals> be defined and used.

Argument Types

Brigadier offers different ArgumentTypes to use for the arguments.
This allows you to define what type of input is acceptable for the specific argument.

String

Any text provided would be treated as a String.

.commodore file example:

teleport {
  player brigadier:string single_word;
}

Code example:

LiteralCommandNode<?> command = LiteralArgumentBuilder.literal("teleport")
        .then(RequiredArgumentBuilder.argument("player", StringArgumentType.word())
        .build();

The String option accepts three different types:

  • single_word / StringArgumentType.word() accepts a single word.
  • quotable_phrase / StringArgumentType.string() accepts either a single word or multiple enclosed in ' or ".
  • greedy_phrase / StringArgumentType.greedyString() accepts any amount of words and can therefore only be used as last option.

Integer

Any text provided would be treated as an Integer number.

.commodore file example:

number {
  number brigadier:integer;
  random {
    min brigadier:integer min:1 { // TODO: Find out if Commodore file has Min number option
      max brigadier:integer max:100; // TODO: Find out if Commodore file has Max number option
    }
  }
}

Code example:

LiteralCommandNode<?> command = LiteralArgumentBuilder.literal("number")
        .then(RequiredArgumentBuilder.argument("number", IntegerArgumentType.integer())
        .then(LiteralArgumentBuilder.literal("random")
            .then(RequiredArgumentBuilder.argument("min", IntegerArgumentType.integer(1))
                .then(RequiredArgumentBuilder.argument("max", IntegerArgumentType.integer(Integer.MIN_VALUE, 100)))
            )
        )
        .build();

The Integer option accepts two different options:

  • IntegerArgumentType.integer(<min>) defines the minimal number required for this argument.
  • IntegerArgumentType.integer(<min>, <max>) defines the minimal and maximal numbers allowed for this argument.
    If you want to only set the max value of the integer can you use Integer.MIN_VALUE for the minimal value. You can't just set the max value alone.
Clone this wiki locally