Interface FormatManager


public interface FormatManager
Central registry and handler for all text-based formats used within the Takion framework.

A FormatManager allows you to dynamically register new parsing/formatting rules at runtime, keyed by a unique identifier. Once loaded, each format can be retrieved, edited, or removed by its ID. This interface abstracts the lifecycle of Format instances, which encapsulate:

  • A regular expression pattern to locate format markers in strings.
  • Logic to strip the markers from the text.
  • Transformation logic to produce a value of type T from the marked text.

Example Usage:

 // Create and register a custom format that parses "invalid input: '<'uppercase:...>" blocks
 FormatManager manager = new MyFormatManagerImplementation();
 manager.load("upper", new Format<String>() {
     public @Regex String getRegex() {
         return "<uppercase:(.+?)>";
     }
     public String apply(Collection<? extends Player> players, String input) {
         Matcher m = matcher(input);
         if (m.find()) return m.group(1).toUpperCase();
         return input;
     }
 });

 // Apply the format
 String result = manager.get("upper").apply("Hello invalid input: '<'uppercase:world>!");
 // "Hello WORLD!"
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> boolean
    editFormat(String id, Format<T> newFormat)
    Replace the existing format under the specified id with a new implementation.
    boolean
    editId(String oldId, String newId)
    Change the key under which a format is stored.
    <T, F extends Format<T>>
    F
    get(String identifier)
    Retrieve the format instance tied to the given identifier.
    <T> boolean
    load(String id, Format<T> format)
    Register a new format under the specified identifier.
    boolean
    Remove the format associated with the given identifier.
  • Method Details

    • load

      <T> boolean load(String id, Format<T> format)
      Register a new format under the specified identifier.

      If the given id is already in use, the existing format is not replaced and this method returns false. Otherwise, the format is stored and will be used for all subsequent retrievals via get(String).

      Type Parameters:
      T - the output type produced by the format when applied
      Parameters:
      id - a case-sensitive key under which this format will be stored
      format - the Format implementation encapsulating regex, removal, and transformation logic
      Returns:
      true if the format was successfully registered; false if the id was already taken
    • remove

      boolean remove(String id)
      Remove the format associated with the given identifier.

      All future calls to get(String) with this id will return null.

      Parameters:
      id - the identifier of the format to remove
      Returns:
      true if a format existed and was removed; false if no format was mapped to the id
    • editFormat

      <T> boolean editFormat(String id, Format<T> newFormat)
      Replace the existing format under the specified id with a new implementation.

      Allows you to update parsing/transformation logic without changing the format key. Calling this with an id that does not exist returns false.

      Type Parameters:
      T - the output type of the new format
      Parameters:
      id - the identifier of the existing format
      newFormat - the new Format instance to use
      Returns:
      true if the format was successfully replaced; false otherwise
    • editId

      boolean editId(String oldId, String newId)
      Change the key under which a format is stored.

      Useful for renaming a format without losing its existing logic. If oldId is not found or newId is already in use, no change is made.

      Parameters:
      oldId - the current identifier of the format
      newId - the desired new identifier
      Returns:
      true if the key was successfully updated; false otherwise
    • get

      <T, F extends Format<T>> F get(String identifier)
      Retrieve the format instance tied to the given identifier.

      The returned Format can be used to detect, strip, or transform strings according to its regex and logic. If no format exists for identifier, this method returns null.

      Type Parameters:
      T - the output type produced by the format
      F - the concrete Format implementation type
      Parameters:
      identifier - the key of the desired format
      Returns:
      the Format registered under identifier, or null if none exists