Record Class MessageKey

java.lang.Object
java.lang.Record
com.ultikits.ultitools.text.MessageKey
Record Components:
namespace - the catalogue namespace
path - the catalogue entry path

public record MessageKey(String namespace, String path) extends Record
A stable message key of the form namespace:path, such as ultiessentials:home.set.success. The namespace identifies a module's catalogue and is derived from its plugin.yml name with namespaceFor(String). The path consists of lowercase, dot-separated [a-z0-9_-] segments.
  • Field Details

    • namespace

      private final String namespace
      The field for the namespace record component.
    • path

      private final String path
      The field for the path record component.
    • FRAMEWORK_NAMESPACE

      public static final String FRAMEWORK_NAMESPACE
      The framework's own namespace.
      See Also:
    • NAMESPACE

      private static final Pattern NAMESPACE
    • PATH

      private static final Pattern PATH
  • Constructor Details

    • MessageKey

      public MessageKey(String namespace, String path)
      Validates both parts, each at most 128 characters.
      Throws:
      IllegalArgumentException - if a part is invalid or the namespace is ..
  • Method Details

    • of

      public static MessageKey of(String namespace, String path)
      Returns a validated key, equivalent to the canonical constructor.
    • parse

      public static MessageKey parse(String namespacedKey)
      Parses namespace:path.
      Throws:
      IllegalArgumentException - unless exactly one colon separates two valid parts
    • namespaceFor

      public static String namespaceFor(String moduleName)
      Lowercases a module name with Locale.ROOT, replacing every character outside [a-z0-9_.-] with _. Uniqueness is checked at module load.
      Throws:
      IllegalArgumentException - if the result is empty, .., or longer than 128 characters
    • translationKey

      public String translationKey()
      Returns namespace + ":" + path, the Adventure translation key.
    • asKey

      public net.kyori.adventure.key.Key asKey()
      Returns this key as an Adventure key; always valid by construction.
    • toString

      public String toString()
      Specified by:
      toString in class Record
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • namespace

      public String namespace()
      Returns the value of the namespace record component.
      Returns:
      the value of the namespace record component
    • path

      public String path()
      Returns the value of the path record component.
      Returns:
      the value of the path record component