Class LanguageResourceLoader
java.lang.Object
com.winterhavenmc.library.messagebuilder.resources.language.LanguageResourceLoader
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionLanguageResourceLoader
(org.bukkit.plugin.Plugin plugin) Class constructorLanguageResourceLoader
(org.bukkit.plugin.Plugin plugin, Supplier<org.bukkit.configuration.file.YamlConfiguration> yamlFactory) Testable constructor allowing custom YamlConfiguration supplier. -
Method Summary
Modifier and TypeMethodDescriptionGets language tag specified in config.yml.org.bukkit.configuration.Configuration
load()
Load the language configuration object for the configured language from file and return it.org.bukkit.configuration.Configuration
loadWithFallback
(LanguageTag preferred, LanguageTag fallback) Attempts to load the preferred language file from disk.
-
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 classyamlFactory
- factory for creating YamlConfiguration instances
-
-
Method Details
-
getConfiguredLanguageTag
Gets language tag specified in config.yml.- Specified by:
getConfiguredLanguageTag
in interfaceResourceLoader
- Returns:
- Optional
LanguageTag
or an empty Optional if config setting is null or empty
-
getConfiguredLocale
- Specified by:
getConfiguredLocale
in interfaceResourceLoader
-
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 interfaceResourceLoader
- 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.
-