🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21.4
Arguments are used in most of the commands. Sometimes they can be optional, which means if you do not provide that argument, the command will also run. One node may have multiple argument types, but be aware that there is a possibility of ambiguity, which should be avoided.
CommandBuilder commandWithArg = commandHandler.CreateCommand("command_with_arg")
.Executes(ExecuteCommandWithArg)
.AddArgument("value", "integer");
await commandHandler.RegisterCommandAsync(commandWithArg);not yet implementedprivate static async Task ExecuteCommandWithArg(CommandContext context)
{
// It can be safely assumed that this is a integer, otherwise minecraft wouldn't execute it.
string value = context.Payload["value"];
await context.SendFeedback($"Called /command_with_arg with value = {value}.");
}not yet implementedAvailable type strings (This will be converted into enums down the road):
Fallback: type of StringArgumentType.word()
In this case, after the command text /command_with_arg, you should type an integer. For example, if you run /command_with_arg 3, you will get the feedback message:
Called /command_with_arg with value = 3
If you type /command_with_arg without arguments, the command cannot be correctly parsed.
Then we add an optional second argument:
CommandBuilder commandWithTwoArgs = commandHandler.CreateCommand("command_with_two_args")
.Executes(ExecuteCommandWithArg)
.AddArgument("value_one", "integer")
.AddArgument("value_two", "integer", optional: true);
await commandHandler.RegisterCommandAsync(commandWithTwoArgs);not yet implementedprivate static async Task ExecuteCommandWithMultipleArgs(CommandContext context)
{
if (context.Payload.Count == 1)
{
// We can safely assume this exists, because it is not optional.
string valueOne = context.Payload["value_one"];
await context.SendFeedback($"Called /command_with_two_args with value one = {valueOne}.");
}
else
{
string valueOne = context.Payload["value_one"];
string valueTwo = context.Payload["value_two"];
await context.SendFeedback($"Called /command_with_two_args with value one = {valueOne} and value two = {valueTwo}.");
}
}not yet implementedNow you can type one or two integers. If you give one integer, a feedback text with a single value is printed. If you provide two integers, a feedback text with two values will be printed.
Custom argument types are not yet available in the JavaBridge.