Interface LocaleService


public interface LocaleService
Access to Zentrix's active locale and text formatting pipeline.

Addons should use this service when they need messages to match the server's current Zentrix locale, prefix, small-caps setting, hex colors, and legacy color handling without depending on Zentrix internals.

Inline flags

A locale value may start with whitespace-separated flags, in any order and any combination. Every method here removes them before formatting, so they never reach a player:

  • !disabled - the owner asked for this text not to be delivered to chat or console. It stays available everywhere else, so a GUI, item, or title built from the same key still renders normally.
  • !no-prefix - never prepend the Zentrix prefix, even when the caller asked for a prefixed message.
  • !no-small-caps - keep the original capitalization regardless of the server's small-caps setting.

!no-prefix and !no-small-caps are applied by the formatting methods on their own. !disabled cannot be, because a returned string or component carries no way to say "do not send me" - so prefer send(Audience, String, Object...) and sendWithoutPrefix(Audience, String, Object...) for chat and console delivery. Only reach for isDisabled(String) when the message has to be assembled by hand, such as when click or hover components are appended to it.

Multi-line chat messages

From 1.7.0 a server owner may write a chat message as a list, one chat line per entry in order, blank entries included. The prefix leads only the first line, !disabled or !no-prefix on any line applies to the whole message, and !no-small-caps and center tags affect only their own line. send(Audience, String, Object...) and sendWithoutPrefix(Audience, String, Object...) handle this on their own. To assemble such a message by hand, use getChatComponents(String, Object...) or getChatComponentsWithoutPrefix(String, Object...). The single-value getters are unchanged and keep treating every value as one string, since they also serve GUI, item, and title text.

Since:
1.5.0
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull String
    formatRaw(@NotNull String message, boolean includePrefix, Object... placeholders)
    Formats a raw addon-owned message through Zentrix's text pipeline.
    @NotNull net.kyori.adventure.text.Component
    formatRawComponent(@NotNull String message, boolean includePrefix, Object... placeholders)
    Formats a raw addon-owned message through Zentrix's text pipeline.
    default List<net.kyori.adventure.text.Component>
    getChatComponents(@NotNull String key, Object... placeholders)
    Resolves a chat message as one prefixed component per chat line.
    default List<net.kyori.adventure.text.Component>
    getChatComponentsWithoutPrefix(@NotNull String key, Object... placeholders)
    Resolves a chat message as one unprefixed component per chat line.
    @NotNull net.kyori.adventure.text.Component
    getComponent(@NotNull String key, Object... placeholders)
    Resolves a locale key as a prefixed Adventure component.
    @NotNull net.kyori.adventure.text.Component
    getComponentWithoutPrefix(@NotNull String key, Object... placeholders)
    Resolves a locale key as an unprefixed Adventure component.
    @NotNull String
    Gets the active global Zentrix locale name, such as en.
    @NotNull String
    getMessage(@NotNull String key, Object... placeholders)
    Resolves a locale key as a prefixed legacy string.
    @NotNull String
    getMessageWithoutPrefix(@NotNull String key, Object... placeholders)
    Resolves a locale key as an unprefixed legacy string.
    default @NotNull String
    getRaw(@NotNull String key)
    One locale value exactly as the file holds it, with no formatting applied.
    default List<String>
    getStringList(@NotNull String key)
    The lines a list-valued locale key holds, unformatted.
    default boolean
    isDisabled(@NotNull String key)
    Returns whether a locale value carries the !disabled inline flag.
    default boolean
    isRawDisabled(@NotNull String message)
    Returns whether an addon-owned raw message carries the !disabled inline flag, so text from an addon's own config can support the flag the same way a Zentrix locale value does.
    default @NotNull Registration
    registerMessages(@NotNull org.bukkit.plugin.Plugin owner, @NotNull Map<String,?> messages)
    Registers an addon's own messages, so they resolve through every method of this service exactly like Zentrix's: prefix, small caps, colours, inline flags and multi-line lists.
    default @NotNull Registration
    registerOverrides(@NotNull org.bukkit.plugin.Plugin owner, @NotNull Map<String,?> overrides, int priority)
    Replaces some of Zentrix's own messages while the registration lasts.
    default void
    send(@NotNull net.kyori.adventure.audience.Audience recipient, @NotNull String key, Object... placeholders)
    Sends a prefixed locale message to a player or the console, unless the value opted out with !disabled.
    default void
    sendWithoutPrefix(@NotNull net.kyori.adventure.audience.Audience recipient, @NotNull String key, Object... placeholders)
    Sends an unprefixed locale message to a player or the console, unless the value opted out with !disabled.
  • Method Details

    • getCurrentLocale

      @NotNull @NotNull String getCurrentLocale()
      Gets the active global Zentrix locale name, such as en.
      Returns:
      active locale name
    • getComponent

      @NotNull @NotNull net.kyori.adventure.text.Component getComponent(@NotNull @NotNull String key, Object... placeholders)
      Resolves a locale key as a prefixed Adventure component.
      Parameters:
      key - locale key
      placeholders - placeholder key/value pairs
      Returns:
      formatted component with the Zentrix prefix
    • getComponentWithoutPrefix

      @NotNull @NotNull net.kyori.adventure.text.Component getComponentWithoutPrefix(@NotNull @NotNull String key, Object... placeholders)
      Resolves a locale key as an unprefixed Adventure component.
      Parameters:
      key - locale key
      placeholders - placeholder key/value pairs
      Returns:
      formatted component without the Zentrix prefix
    • getMessage

      @NotNull @NotNull String getMessage(@NotNull @NotNull String key, Object... placeholders)
      Resolves a locale key as a prefixed legacy string.
      Parameters:
      key - locale key
      placeholders - placeholder key/value pairs
      Returns:
      formatted string with the Zentrix prefix
    • getMessageWithoutPrefix

      @NotNull @NotNull String getMessageWithoutPrefix(@NotNull @NotNull String key, Object... placeholders)
      Resolves a locale key as an unprefixed legacy string.
      Parameters:
      key - locale key
      placeholders - placeholder key/value pairs
      Returns:
      formatted string without the Zentrix prefix
    • getChatComponents

      @NotNull default List<net.kyori.adventure.text.Component> getChatComponents(@NotNull @NotNull String key, Object... placeholders)
      Resolves a chat message as one prefixed component per chat line.

      A list-valued key yields one component per entry, with the Zentrix prefix on the first line only. A single value yields one component, equal to getComponent(String, Object...). Like the other getters this ignores !disabled, so check isDisabled(String) before sending.

      A Zentrix build older than 1.7.0 has no multi-line messages, so it returns getComponent(String, Object...) as the only line.

      Parameters:
      key - locale key
      placeholders - placeholder key/value pairs
      Returns:
      the formatted lines, in order, never null
      Since:
      1.7.0
    • getChatComponentsWithoutPrefix

      @NotNull default List<net.kyori.adventure.text.Component> getChatComponentsWithoutPrefix(@NotNull @NotNull String key, Object... placeholders)
      Resolves a chat message as one unprefixed component per chat line.

      The unprefixed counterpart to getChatComponents(String, Object...). A Zentrix build older than 1.7.0 returns getComponentWithoutPrefix(String, Object...) as the only line.

      Parameters:
      key - locale key
      placeholders - placeholder key/value pairs
      Returns:
      the formatted lines, in order, never null
      Since:
      1.7.0
    • getStringList

      @NotNull default List<String> getStringList(@NotNull @NotNull String key)
      The lines a list-valued locale key holds, unformatted.

      Everything a GUI shows more than one line of — item lore, click instructions, multi-line descriptions — is a list in the locale file. Each line still carries its & colour codes and placeholders, so run it through formatRawComponent(String, boolean, Object...) with whatever placeholders belong to it. An addon building a menu that has to look like a Zentrix one wants this rather than its own copy of the wording.

      A key that is missing, or holds a single value rather than a list, returns an empty list. So does a Zentrix build older than 1.6.0.

      Parameters:
      key - locale key
      Returns:
      the raw lines, never null
      Since:
      1.6.0
    • getRaw

      @NotNull default @NotNull String getRaw(@NotNull @NotNull String key)
      One locale value exactly as the file holds it, with no formatting applied.

      For the handful of locale entries that are data rather than text — a wrapping width, a separator — where running them through the colour pipeline would be wrong.

      Returns an empty string for a missing key, and on a Zentrix build older than 1.6.0.

      Parameters:
      key - locale key
      Returns:
      the raw value, never null
      Since:
      1.6.0
    • formatRawComponent

      @NotNull @NotNull net.kyori.adventure.text.Component formatRawComponent(@NotNull @NotNull String message, boolean includePrefix, Object... placeholders)
      Formats a raw addon-owned message through Zentrix's text pipeline.
      Parameters:
      message - raw message containing Zentrix placeholders/color codes
      includePrefix - whether to prepend the active Zentrix prefix
      placeholders - placeholder key/value pairs
      Returns:
      formatted component
    • formatRaw

      @NotNull @NotNull String formatRaw(@NotNull @NotNull String message, boolean includePrefix, Object... placeholders)
      Formats a raw addon-owned message through Zentrix's text pipeline.
      Parameters:
      message - raw message containing Zentrix placeholders/color codes
      includePrefix - whether to prepend the active Zentrix prefix
      placeholders - placeholder key/value pairs
      Returns:
      formatted legacy string
    • isDisabled

      default boolean isDisabled(@NotNull @NotNull String key)
      Returns whether a locale value carries the !disabled inline flag.

      Only chat and console delivery honors the flag. Every getter on this service keeps returning the formatted text, so the same key still works in GUIs, item text, titles, and subtitles.

      For a multi-line chat message, the flag on any line disables the whole message.

      A Zentrix build older than 1.6.0 has no inline flags, so it reports every key as enabled.

      Parameters:
      key - locale key
      Returns:
      true when the value opts out of chat and console delivery
      Since:
      1.6.0
    • isRawDisabled

      default boolean isRawDisabled(@NotNull @NotNull String message)
      Returns whether an addon-owned raw message carries the !disabled inline flag, so text from an addon's own config can support the flag the same way a Zentrix locale value does.

      A Zentrix build older than 1.6.0 has no inline flags, so it reports every message as enabled.

      Parameters:
      message - raw message that may start with inline flags
      Returns:
      true when the message opts out of chat and console delivery
      Since:
      1.6.0
    • send

      default void send(@NotNull @NotNull net.kyori.adventure.audience.Audience recipient, @NotNull @NotNull String key, Object... placeholders)
      Sends a prefixed locale message to a player or the console, unless the value opted out with !disabled. A multi-line message is sent one chat line per entry, with the prefix on the first line only.
      Parameters:
      recipient - player, console, or any other Adventure audience
      key - locale key
      placeholders - placeholder key/value pairs
      Since:
      1.6.0
    • sendWithoutPrefix

      default void sendWithoutPrefix(@NotNull @NotNull net.kyori.adventure.audience.Audience recipient, @NotNull @NotNull String key, Object... placeholders)
      Sends an unprefixed locale message to a player or the console, unless the value opted out with !disabled. A multi-line message is sent one chat line per entry.
      Parameters:
      recipient - player, console, or any other Adventure audience
      key - locale key
      placeholders - placeholder key/value pairs
      Since:
      1.6.0
    • registerMessages

      @NotNull default @NotNull Registration registerMessages(@NotNull @NotNull org.bukkit.plugin.Plugin owner, @NotNull @NotNull Map<String,?> messages)
      Registers an addon's own messages, so they resolve through every method of this service exactly like Zentrix's: prefix, small caps, colours, inline flags and multi-line lists.

      Keys are dotted paths under the addon's own top-level section, such as myaddon.welcome; values are a string or a list of strings. They are defaults: a server owner who adds the same key to the active locale file overrides them, and nothing is ever written to that file. A key Zentrix's own locale already defines is ignored, so an addon cannot change a built-in message this way; see registerOverrides(org.bukkit.plugin.Plugin, java.util.Map<java.lang.String, ?>, int).

      Parameters:
      owner - the registering plugin; the messages are removed when it is disabled
      messages - the messages, by key
      Returns:
      the registration, to remove the messages early
      Throws:
      IllegalArgumentException - if a key's top-level section is one Zentrix uses itself, or a value is neither a string nor a list of strings
      Since:
      1.8.0
    • registerOverrides

      @NotNull default @NotNull Registration registerOverrides(@NotNull @NotNull org.bukkit.plugin.Plugin owner, @NotNull @NotNull Map<String,?> overrides, int priority)
      Replaces some of Zentrix's own messages while the registration lasts.

      An override wins over the active locale file, so use it deliberately - for an addon that reworks a feature and needs its messages to match. When several addons override the same key, the highest priority wins, and on equal priority the earliest registration. Removing an override restores the next one, or the server's own text; the locale file is never changed.

      Parameters:
      owner - the registering plugin; the overrides are removed when it is disabled
      overrides - the replacement values, by key; each a string or a list of strings
      priority - higher wins over other addons' overrides of the same key
      Returns:
      the registration, to remove the overrides early
      Throws:
      IllegalArgumentException - if a value is neither a string nor a list of strings
      Since:
      1.8.0