fCraft  0.636
Custom Minecraft Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events
Public Member Functions | Public Attributes | Properties | List of all members
fCraft.CommandReader Class Reference

A text scanner that aids parsing chat commands and their arguments. Breaks up a message into tokens at spaces. Treats quoted strings as whole tokens. More...

Inheritance diagram for fCraft.CommandReader:
Inheritance graph
[legend]
Collaboration diagram for fCraft.CommandReader:
Collaboration graph
[legend]

Public Member Functions

 CommandReader ([NotNull] CommandReader other)
 Creates a copy of an existing command.
 
 CommandReader ([NotNull] string rawMessage)
 Creates a command from a raw message.
 
object Clone ()
 Creates a copy of this command. Use the copy constructor instead of this, if possible.
 
string Next ()
 Returns the next command argument. A single "argument" is either a word that ends with whitespace, or several words in double quotes ("").
 
bool NextInt (out int number)
 Returns the next command argument, parsed as an integer.
 
string NextAll ()
 Returns the rest of command's text, from current offset to the end of string. If there is nothing to return (i.e. if string ends at the current offset), returns empty string.
 
void Rewind ()
 Resets the argument offset. After calling Rewind, arguments can be read from the beginning again.
 
bool NextBlock ([CanBeNull] Player player, bool allowNoneBlock, out Block block)
 Parses next parameter as a Minecraft block name. Messages warnings directly to the player in case of problems.
 
bool NextBlockWithParam ([CanBeNull] Player player, bool allowNoneBlock, out Block block, out int param)
 Parses next parameter as a Minecraft block name. Allows an optional integer parameter to follow the block name after a slash, e.g. "BlockName/#" Messages warnings directly to the player in case of problems.
 
override string ToString ()
 

Public Attributes

readonly string RawMessage
 Raw message that is being parsed, including the slash and the command name.
 

Properties

CommandDescriptor Descriptor [get, set]
 Command descriptor associated with this command. May be null of command was not recognized by name.
 
int Offset [get, set]
 Gets or sets current offset, in characters, from the beginning of the raw message.
 
string Name [get, set]
 Name (lowercase) of the command.
 
bool IsConfirmed [get, set]
 Whether this command has been confirmed by the user (with /ok)
 
bool HasNext [get]
 Checks whether there is another argument available. Does not modify the offset.
 
bool HasInt [get]
 Checks whether there there is an int argument available. Does not modify the offset.
 
int CountRemaining [get]
 Counts the number of arguments left in this command. Does not modify the offset.
 
int Count [get]
 Counts the total number of arguments. Does not modify the offset.
 

Detailed Description

A text scanner that aids parsing chat commands and their arguments. Breaks up a message into tokens at spaces. Treats quoted strings as whole tokens.

Constructor & Destructor Documentation

fCraft.CommandReader.CommandReader ( [NotNull] CommandReader  other)

Creates a copy of an existing command.

fCraft.CommandReader.CommandReader ( [NotNull] string  rawMessage)

Creates a command from a raw message.

Member Function Documentation

object fCraft.CommandReader.Clone ( )

Creates a copy of this command. Use the copy constructor instead of this, if possible.

string fCraft.CommandReader.Next ( )

Returns the next command argument. A single "argument" is either a word that ends with whitespace, or several words in double quotes ("").

Returns
Next argument (string), or null if there are no more arguments.
string fCraft.CommandReader.NextAll ( )

Returns the rest of command's text, from current offset to the end of string. If there is nothing to return (i.e. if string ends at the current offset), returns empty string.

Returns
The rest of the command, or an empty string.
bool fCraft.CommandReader.NextBlock ( [CanBeNull] Player  player,
bool  allowNoneBlock,
out Block  block 
)

Parses next parameter as a Minecraft block name. Messages warnings directly to the player in case of problems.

Parameters
playerPlayer to send warnings to (if any come up).
allowNoneBlockWhether "none"/"skip" blocktype is allowed.
blockOn success, this is set to the given block type. On failure, this is set to Block.None
Returns
True on success. False if no more parameters were given; if next parameter could not be parsed as a block name; or if "none" blocktype was given and allowNoneBlock is false.
bool fCraft.CommandReader.NextBlockWithParam ( [CanBeNull] Player  player,
bool  allowNoneBlock,
out Block  block,
out int  param 
)

Parses next parameter as a Minecraft block name. Allows an optional integer parameter to follow the block name after a slash, e.g. "BlockName/#" Messages warnings directly to the player in case of problems.

Parameters
playerPlayer to send warnings to (if any come up).
allowNoneBlockWhether "none"/"skip" blocktype is allowed.
blockOn success, this is set to the given block type. On failure, this is set to Block.None
paramOptional integer parameter. Set to 1 if not given.
Returns
True on success. False if no more parameters were given; if next parameter could not be parsed as a block name; if optional parameter was given but was not an integer; or if "none" blocktype was given and allowNoneBlock is false.
bool fCraft.CommandReader.NextInt ( out int  number)

Returns the next command argument, parsed as an integer.

Parameters
numberSet to the argument's value if parsing succeeded, or zero if parsing failed or if there are no more arguments.
Returns
Returns true if parsing succeeded, and false if parsing failed or if there are no more arguments.
void fCraft.CommandReader.Rewind ( )

Resets the argument offset. After calling Rewind, arguments can be read from the beginning again.

override string fCraft.CommandReader.ToString ( )

Member Data Documentation

readonly string fCraft.CommandReader.RawMessage

Raw message that is being parsed, including the slash and the command name.

Property Documentation

int fCraft.CommandReader.Count
get

Counts the total number of arguments. Does not modify the offset.

int fCraft.CommandReader.CountRemaining
get

Counts the number of arguments left in this command. Does not modify the offset.

CommandDescriptor fCraft.CommandReader.Descriptor
getset

Command descriptor associated with this command. May be null of command was not recognized by name.

bool fCraft.CommandReader.HasInt
get

Checks whether there there is an int argument available. Does not modify the offset.

bool fCraft.CommandReader.HasNext
get

Checks whether there is another argument available. Does not modify the offset.

bool fCraft.CommandReader.IsConfirmed
getset

Whether this command has been confirmed by the user (with /ok)

string fCraft.CommandReader.Name
getset

Name (lowercase) of the command.

int fCraft.CommandReader.Offset
getset

Gets or sets current offset, in characters, from the beginning of the raw message.


The documentation for this class was generated from the following file: