java.lang.Object
com.winterhavenmc.library.messagebuilder.adapters.resources.language.YamlLanguageResourceLoader
All Implemented Interfaces:
ResourceLoader

public class YamlLanguageResourceLoader extends Object implements ResourceLoader
This class is responsible for the loading of the language file from the plugin data directory into a configuration object. The configuration object is loaded from file whenever the getConfiguration method is called. The class does not store the configuration; each invocation of the getConfiguration method will result in a new configuration object loaded from the currently configured language file, or the en-US language file if a file for the currently configured language cannot be found in the plugin data directory.
  • Constructor Details

    • YamlLanguageResourceLoader

      public YamlLanguageResourceLoader(org.bukkit.plugin.Plugin plugin, ConfigRepository configRepository)
      Class constructor
      Parameters:
      plugin - an instance of the plugin main class
    • YamlLanguageResourceLoader

      public YamlLanguageResourceLoader(org.bukkit.plugin.Plugin plugin, Supplier<org.bukkit.configuration.file.YamlConfiguration> yamlFactory, ConfigRepository configRepository)
      Testable constructor allowing custom YamlConfiguration supplier.
      Parameters:
      plugin - an instance of the plugin main class
      yamlFactory - factory for creating YamlConfiguration instances
  • Method Details

    • getConfiguredLanguageTag

      public Optional<LanguageTag> getConfiguredLanguageTag()
      Gets language tag specified in config.yml.
      Returns:
      Optional LanguageTag or an empty Optional if config setting is null or empty
    • getConfiguredLocale

      public Locale getConfiguredLocale()
    • load

      public org.bukkit.configuration.Configuration load()
      Load the language configuration object for the configured language from file and return it. The returned configuration object contains no default values loaded, by design.
      Specified by:
      load in interface ResourceLoader
      Returns:
      Configuration - message configuration object
    • loadWithFallback

      public org.bukkit.configuration.Configuration loadWithFallback(LanguageTag preferred, LanguageTag fallback)
      Attempts to load the preferred language file from disk. If unavailable or invalid, falls back to loading the fallback language directly from the plugin resource.
    • loadFromResource

      public org.bukkit.configuration.Configuration loadFromResource(LanguageTag fallback)
      Loads a language YAML file directly from the JAR resource as a last resort.