Interface IBracketParserRegistrationHandler


public interface IBracketParserRegistrationHandler
Handles registration of parsers for bracket expressions.

A bracket expression in ZenCode is defined as anything starting with a < character. It is up to the BracketExpressionParser to parse the code and define what needs to be done.

This definition is slightly restricted in CraftTweaker to allow for easier parsing and better cooperation. Each bracket parser has a name which uniquely identifies it in the context of a loader. When a < sign is encountered, the first set of tokens until a colon (:) is read. The tokens are used to create a string which forms the name of the parser. The current loader and the name are then used to identify the parser to invoke, which is then handed the rest of the bracket expression.

As an example, when an expression like <item:minecraft:dirt> is found, item is used to build a string (namely, "item") which is then used to identify the "item" bracket parser for the current loader. If a bracket is found, then it is invoked with the remaining token stream (simplifying, with minecraft:dirt>). It is up to the bracket expression parser to then figure out what to do.

Since:
9.1.0
  • Method Details

    • registerParserFor

      void registerParserFor(String loader, String parserName, BracketExpressionParser parser, IBracketParserRegistrationHandler.DumperData parserDumper)
      Registers a bracket expression parser that targets the specified parser name when within the given loader.

      Refer to the main class documentation for more information on bracket parsers.

      Parameters:
      loader - A string representing the loader in which the bracket expression should be parsed by the parser being registered.
      parserName - The name of the bracket that identifies this parser.
      parser - A BracketExpressionParser instance that is responsible for parsing the bracket and building the resulting expression.
      parserDumper - A IBracketParserRegistrationHandler.DumperData holding information relative to expression dumping, if available; null otherwise.
      Since:
      9.1.0
    • registerParserFor

      default void registerParserFor(String loader, String parserName, BracketExpressionParser parser)
      Registers a bracket expression parser that targets the specified parser name when within the given loader.

      Refer to the main class documentation for more information on bracket parsers.

      No IBracketParserRegistrationHandler.DumperData is provided in this case, thus disallowing any possibility of dumping valid expressions for this bracket.

      Parameters:
      loader - A string representing the loader in which the bracket expression should be parsed by the parser being registered.
      parserName - The name of the bracket that identifies this parser.
      parser - A BracketExpressionParser instance that is responsible for parsing the bracket and building the resulting expression.
      Since:
      9.1.0
    • registerParserFor

      void registerParserFor(String loader, String parserName, Method parser, Method validator, IBracketParserRegistrationHandler.DumperData dumper)
      Registers a bracket expression parser that targets the specified parser name when within the given loader.

      Refer to the main class documentation for more information on bracket parsers.

      The parser and validator methods are used to build a default BracketExpressionParser instance that does what is supposed to. Refer to the documentation for the parameters for more information relative to the restrictions imposed on the signature of these methods.

      Parameters:
      loader - A string representing the loader in which the bracket expression should be parsed by the parser being registered.
      parserName - The name of the bracket that identifies this parser.
      parser - The Method responsible for resolution of the bracket parser. The method must be located in a class that is exposed to ZenCode, be public and static, and have a single String parameter as input. The return type should also be a subtype of CommandStringDisplayable. The method will be called automatically by CraftTweaker with the entire token stream between the first colon and the last closing bracket (i.e. between the first : and the ending >) read and converted to a string. It is up to the method to parse the string. If a validator is provided, the validator will be invoked before this method.
      validator - The Method responsible for verifying that the expression given to the bracket parser is correct. The method must be public and static, and have a single input parameter of type String. The return type must be boolean. The method will be called by CraftTweaker with the entire token stream between the first colon and the last closing bracket (i.e. between the first : and the ending >) read and converted to a string. It is up to the validator to parse the string and return true or false depending on the string's validity. If no validator is desired, this parameter can be null.
      dumper - A IBracketParserRegistrationHandler.DumperData holding information relative to expression dumping, if available; or null if not desired.
      Since:
      9.1.0
    • registerParserFor

      default void registerParserFor(String loader, String parserName, Method parser, IBracketParserRegistrationHandler.DumperData dumper)
      Registers a bracket expression parser that targets the specified parser name when within the given loader.

      Refer to the main class documentation for more information on bracket parsers.

      The parser method is used to build a default BracketExpressionParser instance that does what is supposed to. Refer to the documentation for the parameters for more information relative to the restrictions imposed on the signature of the method.

      The created expression parser will have no validator.

      Parameters:
      loader - A string representing the loader in which the bracket expression should be parsed by the parser being registered.
      parserName - The name of the bracket that identifies this parser.
      parser - The Method responsible for resolution of the bracket parser. The method must be located in a class that is exposed to ZenCode, be public and static, and have a single String parameter as input. The return type should also be a subtype of CommandStringDisplayable. The method will be called automatically by CraftTweaker with the entire token stream between the first colon and the last closing bracket (i.e. between the first : and the ending >) read and converted to a string. It is up to the method to parse the string.
      dumper - A IBracketParserRegistrationHandler.DumperData holding information relative to expression dumping, if available; or null if not desired.
      Since:
      9.1.0
    • registerParserFor

      default void registerParserFor(String loader, String parserName, Method parser, Method validator)
      Registers a bracket expression parser that targets the specified parser name when within the given loader.

      Refer to the main class documentation for more information on bracket parsers.

      The parser and validator methods are used to build a default BracketExpressionParser instance that does what is supposed to. Refer to the documentation for the parameters for more information relative to the restrictions imposed on the signature of these methods.

      The created expression parser will not allow dumping of its expressions.

      Parameters:
      loader - A string representing the loader in which the bracket expression should be parsed by the parser being registered.
      parserName - The name of the bracket that identifies this parser.
      parser - The Method responsible for resolution of the bracket parser. The method must be located in a class that is exposed to ZenCode, be public and static, and have a single String parameter as input. The return type should also be a subtype of CommandStringDisplayable. The method will be called automatically by CraftTweaker with the entire token stream between the first colon and the last closing bracket (i.e. between the first : and the ending >) read and converted to a string. It is up to the method to parse the string. If a validator is provided, the validator will be invoked before this method.
      validator - The Method responsible for verifying that the expression given to the bracket parser is correct. The method must be public and static, and have a single input parameter of type String. The return type must be boolean. The method will be called by CraftTweaker with the entire token stream between the first colon and the last closing bracket (i.e. between the first : and the ending >) read and converted to a string. It is up to the validator to parse the string and return true or false depending on the string's validity. If no validator is desired, this parameter can be null.
      Since:
      9.1.0
    • registerParserFor

      default void registerParserFor(String loader, String parserName, Method parser)
      Registers a bracket expression parser that targets the specified parser name when within the given loader.

      Refer to the main class documentation for more information on bracket parsers.

      The parser method is used to build a default BracketExpressionParser instance that does what is supposed to. Refer to the documentation for the parameters for more information relative to the restrictions imposed on the signature of the method.

      The created expression parser will have no validator and no possibility of dumping valid expressions.

      Parameters:
      loader - A string representing the loader in which the bracket expression should be parsed by the parser being registered.
      parserName - The name of the bracket that identifies this parser.
      parser - The Method responsible for resolution of the bracket parser. The method must be located in a class that is exposed to ZenCode, be public and static, and have a single String parameter as input. The return type should also be a subtype of CommandStringDisplayable. The method will be called automatically by CraftTweaker with the entire token stream between the first colon and the last closing bracket (i.e. between the first : and the ending >) read and converted to a string. It is up to the method to parse the string.
      Since:
      9.1.0
    • registerEnumForBracket

      <T extends Enum<T>> void registerEnumForBracket(String loader, net.minecraft.resources.ResourceLocation id, Class<T> enumClass)
      Registers the given enum class as a valid target for the built-in enum bracket parser.

      The enumeration will then be accessible through a bracket structured like the following: <constant:id:constant>, where id represents the ID used to register the enumeration and constant the name of the constant that should be accessed.

      Type Parameters:
      T - The type of the enumeration that is being registered.
      Parameters:
      loader - A string representing the loader in which the enum should be available.
      id - A ResourceLocation that uniquely identifies the enumeration class.
      enumClass - The actual enum class.
      Since:
      9.1.0