Class YamlLanguageResourceManager
java.lang.Object
com.winterhavenmc.library.messagebuilder.adapters.resources.language.YamlLanguageResourceManager
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionYamlLanguageResourceManager(ResourceInstaller resourceInstaller, ResourceLoader resourceLoader) Class constructorYamlLanguageResourceManager(ResourceInstaller installer, ResourceLoader loader, org.bukkit.configuration.Configuration configuration) package-private constructor for testing purposes -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetFileName(LanguageTag languageTag) Retrieve the name of the potential language resource file as installed in the plugin data directory, as a Section.static StringgetResourceName(LanguageTag languageTag) Constructs the resource path (in the JAR) for a given language tag, e.g.getSectionProvider(String sectionName) Retrieve the configuration provider, a container that carries the current configurationvoidInstalls any language resource files listed in auto-install.txt if they are not already installed.booleanreload()Reload the language resource.
-
Constructor Details
-
YamlLanguageResourceManager
public YamlLanguageResourceManager(ResourceInstaller resourceInstaller, ResourceLoader resourceLoader) Class constructor- Parameters:
resourceInstaller- a YamlLanguageResourceInstaller instanceresourceLoader- 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 instanceloader- a YamlLanguageResourceLoader instanceconfiguration- a bukkit Configuration representing the language resource
-
-
Method Details
-
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 Section.- Returns:
Sectionrepresentation 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 returnsfalse. If the new configuration exists, a new configuration supplier is created with the new configuration, and the method returnstrue.- Specified by:
reloadin interfaceResourceManager- Returns:
trueif the configuration was successfully reloaded,falseif it failed
-
getSectionProvider
Retrieve the configuration provider, a container that carries the current configuration- Specified by:
getSectionProviderin interfaceResourceManager- Returns:
- the configuration provider
-
getConfigurationProvider
- Specified by:
getConfigurationProviderin interfaceResourceManager
-
installResources
public void installResources()Installs any language resource files listed in auto-install.txt if they are not already installed.- Specified by:
installResourcesin interfaceResourceManager
-