Delegate
  • Delegate Framework
    • Framework Overview
    • Feature Overview
  • Commands
    • First Command
    • Command Attributes
      • Arguments
      • Actions
      • Properties & Definitions
  • Tutorials / Examples
    • Getting Started
    • 👋Hello, World!
Powered by GitBook
On this page
  • Built-In Arguments
  • Platform-Specific Arguments
  • Using Arguments
  • Methods For Providing Arguments
  1. Commands
  2. Command Attributes

Arguments

This page describes the concept of Command Arguments

Perhaps the most important part of any command framework is the ability to handle sub commands and command arguments. In this section we'll cover the latter.

Built-In Arguments

For ease of use, there are various built-in arguments for all platforms. Some arguments are also available for certain platforms. Currently, Delegate supports 4 basic arguments out of the box:

  • Float Argument (FloatArgument)

  • Double Argument (DoubleArgument)

  • Integer Argument (IntArgument)

  • String Argument (StringArgument)

These arguments will try and process a given input String to a new type. For example, the FloatArgument will try to process the input to a floating point number.

Platform-Specific Arguments

As said earlier, there are various platform specific arguments. Currently, the following arguments are supported:

Argument
Description

PlayerArgument

WorldArgument

Currently no Velocity-specific arguments are implemented.

Currently no Sponge-specific arguments are implemented.

Using Arguments

The actual functionality of arguments is the most important part of this section. As explained in the previous section, command attributes can be added to a command by chaining them. Since arguments are command attributes, they must be chained to this builder. To build up the example, we will need one String argument and two Float arguments. We can add them to the command as follows:

Delegate.getFactory().create("math", "Implementation of a arithmetic operations such as addition and  subtraction.")
                .withString("operation", "The operation to perform.")  // String Arg
                .withFloat("a", "The first number to add.")            // Float Arg 
                .withFloat("b", "The second number to add.")           // Float Arg

Methods For Providing Arguments

When executing a command, the following formats are supported:

/math + 1 2

/math operation="+" a="1" b="2"

While the first method is very concise, it does not allow for arbitrary arguments to be ommited. By using the second method, arguments will automatically be linked together through the identifier that has been specified.

PreviousCommand AttributesNextActions

Last updated 2 years ago

Parses an input to a object

Parses an input to a object

This will add three arguments to the command with identifiers operation, a and b. Please note that these arguments do not have any functionality on their own. How the parsed values of the arguments can be used will be explained in the next section. By default, the command will expect these attributes to be present when executed. This means that an error message will be send back to the command sender when one or multiple attributes are missing. can be used to mitigate this.

Properties
Player
World