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 disabled
    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
    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
    BetterLang​(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 disabled
    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
    BetterLang​(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BetterLang

      public BetterLang​(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
      Parameters:
      name - The name of the language (/lang) file, which is equal to the name of the template in the templates folder
      plugin - 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 folder
      validationHandler - the validator that can autocorrect options, based on your provided settings
      plugin - The relevant JavaPlugin
    • BetterLang

      public BetterLang​(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 disabled
      Parameters:
      template - The name of the template in the /templates folder
      localised - The name of the language file, located in the /lang folder
      plugin - 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 folder
      localised - The name of the language file, located in the /lang folder
      validationHandler - the validator that can autocorrect options, based on your provided settings
      plugin - 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 folder
      localised - The name of the language file, located in the /lang folder
      plugin - The relevant JavaPlugin
      doLogging - 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 folder
      localised - The name of the language file, located in the /lang folder
      validationHandler - the validator that can autocorrect options, based on your provided settings
      plugin - The relevant JavaPlugin
      doLogging - 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

      @NotNull public @NotNull Optional<File> 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:
      getFile in interface IOptionalConfigReader
      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:
      getYamlConfiguration in interface IOptionalConfigReader
      Returns:
      an optional YamlConfiguration, never null. But no value will be present if an Exception was thrown while reading the configuration
    • getMessages

      public Map<String,​String> 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