Class LanguageResourceManager

java.lang.Object
com.winterhavenmc.library.messagebuilder.resources.language.LanguageResourceManager
All Implemented Interfaces:
SectionResourceManager, ResourceManager

public final class LanguageResourceManager extends Object implements SectionResourceManager
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

    • LanguageResourceManager

      public LanguageResourceManager(LanguageResourceInstaller resourceInstaller, LanguageResourceLoader resourceLoader)
      Class constructor
      Parameters:
      resourceInstaller - a LanguageResourceInstaller instance
      resourceLoader - a LanguageResourceLoader instance
  • Method Details

    • 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(Section section)
      Retrieve the configuration provider, a container that carries the current configuration
      Specified by:
      getSectionProvider in interface SectionResourceManager
      Returns:
      the configuration provider
    • 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 String.
      Returns:
      String representation of the potential language resource file installed in the plugin data directory