java.lang.Object
com.winterhavenmc.library.messagebuilder.adapters.resources.language.YamlLanguageResourceManager
All Implemented Interfaces:
ResourceManager

public final class YamlLanguageResourceManager extends Object implements ResourceManager
This class is responsible for the management and lifecycle of the language resource. The language resource is made available as a Bukkit Configuration object, which is loaded into a Supplier that is provided to classes that have a need to access the language configuration object. This supplier will return an up-to-date version of the language configuration object to any consumers, even if the language resource has been reloaded since the creation of the supplier. A convenience method is provided to query the current language setting in the plugin configuration so that changes to this setting may result in a different language resource being used for any subsequent reload operations.

The static getInstance method should be used to acquire an instance of this singleton class. It can be accessed globally, anywhere within this library using this static method.

  • Constructor Details

    • YamlLanguageResourceManager

      public YamlLanguageResourceManager(ResourceInstaller resourceInstaller, ResourceLoader resourceLoader)
      Class constructor
      Parameters:
      resourceInstaller - a YamlLanguageResourceInstaller instance
      resourceLoader - a YamlLanguageResourceLoader instance
    • YamlLanguageResourceManager

      public YamlLanguageResourceManager(ResourceInstaller installer, ResourceLoader loader, org.bukkit.configuration.Configuration configuration)
      package-private constructor for testing purposes
      Parameters:
      installer - a YamlLanguageResourceInstaller instance
      loader - a YamlLanguageResourceLoader instance
      configuration - a bukkit Configuration representing the language resource
  • Method Details

    • getResourceName

      public static String getResourceName(LanguageTag languageTag)
      Constructs the resource path (in the JAR) for a given language tag, e.g. "language/en-US.yml".
    • getFileName

      public static String getFileName(LanguageTag languageTag)
      Retrieve the name of the potential language resource file as installed in the plugin data directory, as a Section.
      Returns:
      Section representation of the potential language resource file installed in the plugin data directory
    • reload

      public boolean reload()
      Reload the language resource. This method first calls the reload method in the resource loader, and receives the new configuration object as the return value. If the new configuration object is null, the old configuration object is not replace, and the method returns false. If the new configuration exists, a new configuration supplier is created with the new configuration, and the method returns true.
      Specified by:
      reload in interface ResourceManager
      Returns:
      true if the configuration was successfully reloaded, false if it failed
    • getSectionProvider

      public SectionProvider getSectionProvider(String sectionName)
      Retrieve the configuration provider, a container that carries the current configuration
      Specified by:
      getSectionProvider in interface ResourceManager
      Returns:
      the configuration provider
    • getConfigurationProvider

      public ConfigurationProvider getConfigurationProvider()
      Specified by:
      getConfigurationProvider in interface ResourceManager
    • installResources

      public void installResources()
      Installs any language resource files listed in auto-install.txt if they are not already installed.
      Specified by:
      installResources in interface ResourceManager