Class Parser<T>

java.lang.Object
ch.njol.skript.classes.Parser<T>
Type Parameters:
T - the type of this parser

public abstract class Parser<T> extends Object
A parser used to parse data from a string or turn data into a string.
See Also:
Classes.registerClass(ClassInfo), ClassInfo, Classes.toString(Object)
  • Constructor Details

    • Parser

      public Parser()
  • Method Details

    • parse

      public @Nullable T parse(String s, ParseContext context)
      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

      public boolean canParse(ParseContext context)
      Returns:
      Whether parse(String, ParseContext) can actually return something other that null for the given context
    • toString

      public abstract String toString(T o, int flags)
      Returns a string representation of the given object to be used in messages.
      Parameters:
      o - The object. This will never be null.
      Returns:
      The String representation of the object.
      See Also:
      getDebugMessage(Object)
    • toString

      public final String toString(T o, StringMode mode)
      Gets a string representation of this object for the given mode
      Parameters:
      o -
      mode -
      Returns:
      A string representation of the given object.
    • toCommandString

      public String toCommandString(T o)
    • toVariableNameString

      public abstract String toVariableNameString(T o)
      Returns an object's string representation in a variable name.
      Parameters:
      o -
      Returns:
      The given object's representation in a variable name.
    • getDebugMessage

      public String 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 returns toString(o, 0).
      Parameters:
      o -
      Returns:
      A message containing debug information about the given object