Package be.dezijwegel.betteryaml
Class BetterLang
java.lang.Object
be.dezijwegel.betteryaml.BetterLang
- All Implemented Interfaces:
IOptionalConfigReader
public class BetterLang extends Object implements IOptionalConfigReader
BetterLang wraps BetterYaml and allows easy language file reading with support for multiple, localised default contents
It also introduces a getMessages() method that returns a Map, linking message path to message
-
Constructor Summary
Constructors Constructor Description BetterLang(String name, ValidationHandler validationHandler, org.bukkit.plugin.java.JavaPlugin plugin)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder Logging is disabledBetterLang(String template, String localised, ValidationHandler validationHandler, org.bukkit.plugin.java.JavaPlugin plugin)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder Logging is disabledBetterLang(String template, String localised, ValidationHandler validationHandler, org.bukkit.plugin.java.JavaPlugin plugin, boolean doLogging)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folderBetterLang(String template, String localised, org.bukkit.plugin.java.JavaPlugin plugin)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder Logging is disabledBetterLang(String template, String localised, org.bukkit.plugin.java.JavaPlugin plugin, boolean doLogging)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folderBetterLang(String name, org.bukkit.plugin.java.JavaPlugin plugin)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder Logging is disabled -
Method Summary
Modifier and Type Method Description @NotNull Optional<File>getFile()Get the loaded File.Map<String,String>getMessages()Get all messages in this language file.@NotNull Optional<org.bukkit.configuration.file.YamlConfiguration>getYamlConfiguration()Get the loaded YamlConfiguration.
-
Constructor Details
-
BetterLang
Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder Logging is disabled- Parameters:
name- The name of the language (/lang) file, which is equal to the name of the template in the templates folderplugin- The relevant JavaPlugin
-
BetterLang
public BetterLang(String name, ValidationHandler validationHandler, org.bukkit.plugin.java.JavaPlugin plugin)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder Logging is disabled- Parameters:
name- The name of the language (/lang) file, which is equal to the name of the template in the templates foldervalidationHandler- the validator that can autocorrect options, based on your provided settingsplugin- The relevant JavaPlugin
-
BetterLang
Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder Logging is disabled- Parameters:
template- The name of the template in the /templates folderlocalised- The name of the language file, located in the /lang folderplugin- The relevant JavaPlugin
-
BetterLang
public BetterLang(String template, String localised, ValidationHandler validationHandler, org.bukkit.plugin.java.JavaPlugin plugin)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder Logging is disabled- Parameters:
template- The name of the template in the /templates folderlocalised- The name of the language file, located in the /lang foldervalidationHandler- the validator that can autocorrect options, based on your provided settingsplugin- The relevant JavaPlugin
-
BetterLang
public BetterLang(String template, String localised, org.bukkit.plugin.java.JavaPlugin plugin, boolean doLogging)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder- Parameters:
template- The name of the template in the /templates folderlocalised- The name of the language file, located in the /lang folderplugin- The relevant JavaPlugindoLogging- whether or not basic logging is done in your plugin's name. (Only logs on copying a new file and when missing options are found)
-
BetterLang
public BetterLang(String template, String localised, ValidationHandler validationHandler, org.bukkit.plugin.java.JavaPlugin plugin, boolean doLogging)Easily manage localised language files The language template must be located in the /templates folder Any default language contents must be located in the /lang folder- Parameters:
template- The name of the template in the /templates folderlocalised- The name of the language file, located in the /lang foldervalidationHandler- the validator that can autocorrect options, based on your provided settingsplugin- The relevant JavaPlugindoLogging- whether or not basic logging is done in your plugin's name. (Only logs on copying a new file and when missing options are found)
-
-
Method Details
-
getFile
Get the loaded File. You can check if any error has occurred with Optional#isEmpty(). First, see if it is loaded correctly with Optional#isPresent(), this ensures a non-null value Then, you can get the File instance with Optional#get()- Specified by:
getFilein interfaceIOptionalConfigReader- Returns:
- an optional file, never null. But no value will be present if an Exception was thrown while reading the configuration
-
getYamlConfiguration
@NotNull public @NotNull Optional<org.bukkit.configuration.file.YamlConfiguration> getYamlConfiguration()Get the loaded YamlConfiguration. You can check if any error has occurred with Optional#isEmpty(). First, see if it is loaded correctly with Optional#isPresent(), this ensures a non-null value Then, you can get the YamlConfiguration instance with Optional#get()- Specified by:
getYamlConfigurationin interfaceIOptionalConfigReader- Returns:
- an optional YamlConfiguration, never null. But no value will be present if an Exception was thrown while reading the configuration
-
getMessages
Get all messages in this language file. This reads the configuration and returns a Mapping of key <-> message Try to only call this once per lang file (to prevent an overhead)- Returns:
- a Map that may, or may not contain the mapping of keys to messages
-