Class LanguageResourceManager
java.lang.Object
com.winterhavenmc.library.messagebuilder.resources.language.LanguageResourceManager
- All Implemented Interfaces:
SectionResourceManager
,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 Summary
ConstructorsConstructorDescriptionLanguageResourceManager
(LanguageResourceInstaller resourceInstaller, LanguageResourceLoader resourceLoader) Class constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getFileName
(LanguageTag languageTag) Retrieve the name of the potential language resource file as installed in the plugin data directory, as a String.static String
getResourceName
(LanguageTag languageTag) Constructs the resource path (in the JAR) for a given language tag, e.g.getSectionProvider
(Section section) Retrieve the configuration provider, a container that carries the current configurationboolean
reload()
Reload the language resource.
-
Constructor Details
-
LanguageResourceManager
public LanguageResourceManager(LanguageResourceInstaller resourceInstaller, LanguageResourceLoader resourceLoader) Class constructor- Parameters:
resourceInstaller
- a LanguageResourceInstaller instanceresourceLoader
- 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 returnsfalse
. If the new configuration exists, a new configuration supplier is created with the new configuration, and the method returnstrue
.- Specified by:
reload
in interfaceResourceManager
- Returns:
true
if the configuration was successfully reloaded,false
if it failed
-
getSectionProvider
Retrieve the configuration provider, a container that carries the current configuration- Specified by:
getSectionProvider
in interfaceSectionResourceManager
- Returns:
- the configuration provider
-
getResourceName
Constructs the resource path (in the JAR) for a given language tag, e.g. "language/en-US.yml". -
getFileName
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
-