Class YamlLanguageResourceLoader
java.lang.Object
com.winterhavenmc.library.messagebuilder.adapters.resources.language.YamlLanguageResourceLoader
- 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
ConstructorsConstructorDescriptionYamlLanguageResourceLoader(org.bukkit.plugin.Plugin plugin, ConfigRepository configRepository) Class constructorYamlLanguageResourceLoader(org.bukkit.plugin.Plugin plugin, Supplier<org.bukkit.configuration.file.YamlConfiguration> yamlFactory, ConfigRepository configRepository) Testable constructor allowing custom YamlConfiguration supplier. -
Method Summary
Modifier and TypeMethodDescriptionGets language tag specified in config.yml.org.bukkit.configuration.Configurationload()Load the language configuration object for the configured language from file and return it.org.bukkit.configuration.ConfigurationloadFromResource(LanguageTag fallback) Loads a language YAML file directly from the JAR resource as a last resort.org.bukkit.configuration.ConfigurationloadWithFallback(LanguageTag preferred, LanguageTag fallback) Attempts to load the preferred language file from disk.
-
Constructor Details
-
YamlLanguageResourceLoader
public YamlLanguageResourceLoader(org.bukkit.plugin.Plugin plugin, ConfigRepository configRepository) Class constructor- Parameters:
plugin- an instance of the plugin main class
-
YamlLanguageResourceLoader
public YamlLanguageResourceLoader(org.bukkit.plugin.Plugin plugin, Supplier<org.bukkit.configuration.file.YamlConfiguration> yamlFactory, ConfigRepository configRepository) 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.- Returns:
- Optional
LanguageTagor an empty Optional if config setting is null or empty
-
getConfiguredLocale
-
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:
loadin 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. -
loadFromResource
Loads a language YAML file directly from the JAR resource as a last resort.
-