-
Notifications
You must be signed in to change notification settings - Fork 0
Using BetterLang
Dieter Nuytemans edited this page Jun 19, 2021
·
2 revisions
You can get the configuration section in exactly the same way as for OptionalBetterYaml, but BetterLang has an additional method: getMessages() which will return a (Hash)Map<String, String> of all key-value pairs.
// Auto-updates the config on the server and loads a YamlConfiguration and File. Optionally, a boolean can be passed, which enables or disables logging.
// lang.yml must be replaced by the name of your language template file, which contains the default lay-out / comments and is located in the templates folder
// localisedCode.yml is the file name in the 'lang' folder that contains our default values (english.yml or dutch.yml in our example setup)
BetterLang localisation = new BetterLang("lang.yml", "localisedCode.yml", javaPlugin);
// Get all message names and their mapped messages. Useful when sending named messages to players (eg: see below)
Map<String, String> messages = localisation.getMessages();
// Our imaginary config contains an option: no_permission: "You have no permission!"
// We want to send this to a player without hard coding the message:
player.sendMessage( messages.getOrDefault("no_permission", "no_permission") );
BetterYaml supports printing information about the lang file (when a new file is copied or missing options are found). If you want your users to see this info, simply pass a boolean in the constructor. It is considered to be false by default.
// Simply pass a boolean as the last argument
BetterLang localisation = new BetterLang("lang.yml", "localisedCode.yml", javaPlugin, true);
Please use OptionalBetterYaml instead.
Auto-correct faulty configuration values! You can create your own, custom validators.