Skip to content

Instantly share code, notes, and snippets.

@fr34kyn01535
Last active April 13, 2017 17:10
Show Gist options
  • Save fr34kyn01535/177c8402ba09697a15849a0a624bce48 to your computer and use it in GitHub Desktop.
Save fr34kyn01535/177c8402ba09697a15849a0a624bce48 to your computer and use it in GitHub Desktop.
Rocket Command Argument Syntax
Rocket Command Argument Syntax Defintion --- Draft ---
Rocket commands are called with a variety of possible arguments.
Instead of parsing them individually the idea is to define a syntax to define arguments, and let rocket parse and validate.
1) Syntax definition
<> required argument
[] optional argument
2) Defining name and type
NAME:TYPE
2.1) The NAME attribute
The name should be only used once and consist of alphanumeric letters
2.2) The TYPE attribute
Types are registered as providers. This makes the system extensible from plugins. The type name is case insensitive.
Possible built-in types:
Color (Parsing yellow and also #eee or #FFFFFF)
Player (Validating against online players, both id or name work)
Text (string)
Int (int32)
Float (float)
Bool (true,false,0,1)
{example1,example2} (A list of possible string values)
3.3) Special case "params" implementation
Simmilar to the params keyword in C# the following syntax could allow for multi value arguments
<<>> required arguments (One or many arguments)
[[]] optional arguments (Zero or many arguments)
Note that "params" can only be used as last occurency in a string
Simple example case:
/selloffer "Machine Gun" "fr34kyn01535" 32.5 "Here, take this gun for a nice price"
Syntax: <item:Text> <player:Player> <amount:Float> [[message:Text]]
Code example:
public void Execute(IRocketPlayer caller, CommandArgumentList args)
{
string item = args.Get<string>("item");
IRocketPlayer player = args.Get<IRocketPlayer>("player");
float amount = args.Get<float>("amount");
string message = String.Join(" ",args.Get<string[]>("message"));
...
Caveats:
Optional arguments may be null, nullable types have to be choosen when allowing optional arguments.
The command won't be executed if a pre-validation failed, instead the player is presented a detailed error message on what he did wrong.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment