java.lang.Object
com.winterhavenmc.library.messagebuilder.resources.configuration.LocaleProvider
All Implemented Interfaces:
ConfigProvider<LocaleSetting>

public class LocaleProvider extends Object implements ConfigProvider<LocaleSetting>
A configuration-backed provider for both Locale and ZoneId settings.

This class wraps a LocaleSetting and provides a centralized access point for retrieving the user's desired locale and timezone, both of which are commonly required for time/date formatting and localization operations throughout the plugin.

The LocaleProvider resolves configuration values from the plugin config.yml in the following order:

The timezone configuration value, if present and valid, is resolved into a ZoneId. If the value is invalid or missing, the system default time zone is used.

See Also:
  • Method Details

    • create

      public static LocaleProvider create(org.bukkit.plugin.Plugin plugin)
      Factory method to construct a LocaleProvider using a plugin's configuration.

      This method attempts to extract valid configuration values in the following order:

      1. locale setting (must be a valid BCP-47 language tag)
      2. language setting (fallback, same format or else ignored)
      3. System default locale and timezone as final fallback
      Parameters:
      plugin - the plugin whose configuration will be consulted
      Returns:
      a new LocaleProvider with dynamic access to locale and time zone settings
    • get

      public LocaleSetting get()
      Returns the resolved LocaleSetting based on the plugin configuration.
      Specified by:
      get in interface ConfigProvider<LocaleSetting>
      Returns:
      a locale setting encapsulating a LanguageTag
    • getLanguageTag

      public LanguageTag getLanguageTag()
      Returns the resolved LanguageTag representing the locale tag.
      Returns:
      a valid LanguageTag
    • getLocale

      public Locale getLocale()
      Returns the Locale object derived from the configuration.
      Returns:
      a Java Locale
    • getZoneId

      public ZoneId getZoneId()
      Returns the configured ZoneId if valid, or the system default otherwise.
      Returns:
      the applicable time zone as represented by a ZoneId object.