Class LanguageResourceLoader

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

public class LanguageResourceLoader 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

    • LanguageResourceLoader

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

      public LanguageResourceLoader(org.bukkit.plugin.Plugin plugin, Supplier<org.bukkit.configuration.file.YamlConfiguration> yamlFactory)
      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.
      Specified by:
      getConfiguredLanguageTag in interface ResourceLoader
      Returns:
      Optional LanguageTag or an empty Optional if config setting is null or empty
    • getConfiguredLocale

      public Locale getConfiguredLocale()
      Specified by:
      getConfiguredLocale in interface ResourceLoader
    • 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.