Package ch.njol.skript.classes
Class Parser<T>
java.lang.Object
ch.njol.skript.classes.Parser<T>
- Type Parameters:
T
- the type of this parser
A parser used to parse data from a string or turn data into a string.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canParse(ParseContext context)
getDebugMessage(T o)
Returns a string representation of the given object to be used for debugging.
The Parser of 'Block' for example returns the block's type in toString, while this method also returns the coordinates of the block.
The default implementation of this method returnstoString
(o, 0).@Nullable T
parse(String s, ParseContext context)
Parses the input.toCommandString(T o)
abstract String
Returns a string representation of the given object to be used in messages.toString(T o, StringMode mode)
Gets a string representation of this object for the given modeabstract String
Returns an object's string representation in a variable name.
-
Constructor Details
-
Parser
public Parser()
-
-
Method Details
-
parse
Parses the input. This method may print an error prior to returning null if the input couldn't be parsed.Remember to override
canParse(ParseContext)
if this parser doesn't parse at all (i.e. you only use it's toString methods) or only parses for certain contexts.Note that this method will be called very frequently during script parsing, so try to avoid computationally expensive operations in this method when possible.
- Parameters:
s
- The String to parse. This string is already trim()med.context
- Context of parsing, may not be null- Returns:
- The parsed input or null if the input is invalid for this parser.
-
canParse
- Returns:
- Whether
parse(String, ParseContext)
can actually return something other that null for the given context
-
toString
Returns a string representation of the given object to be used in messages.- Parameters:
o
- The object. This will never benull
.- Returns:
- The String representation of the object.
- See Also:
getDebugMessage(Object)
-
toString
Gets a string representation of this object for the given mode- Parameters:
o
-mode
-- Returns:
- A string representation of the given object.
-
toCommandString
-
toVariableNameString
Returns an object's string representation in a variable name.- Parameters:
o
-- Returns:
- The given object's representation in a variable name.
-
getDebugMessage
Returns a string representation of the given object to be used for debugging.
The Parser of 'Block' for example returns the block's type in toString, while this method also returns the coordinates of the block.
The default implementation of this method returnstoString
(o, 0).- Parameters:
o
-- Returns:
- A message containing debug information about the given object
-