Class LanguageConfig<C>

java.lang.Object
de.themoep.utils.lang.LanguageConfig<C>
Direct Known Subclasses:
BukkitLanguageConfig, BungeeLanguageConfig, SimpleLanguageConfig, VelocityLanguageConfig

public abstract class LanguageConfig<C>
extends java.lang.Object
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected C config  
    protected java.io.File configFile  
    protected C defaultConfig  
    protected java.lang.String resourcePath  
    protected boolean saveFile  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected LanguageConfig​(java.lang.String resourceFolder, java.io.File configFile, java.lang.String locale)  
    protected LanguageConfig​(java.lang.String resourceFolder, java.io.File configFile, java.lang.String locale, boolean saveFile)  
  • Method Summary

    Modifier and Type Method Description
    abstract boolean contains​(java.lang.String key)
    Check if the config contains a certain key
    abstract boolean contains​(java.lang.String key, boolean checkDefault)
    Check if the config contains a certain key
    abstract java.lang.String get​(java.lang.String key)
    Get a string from the config by its key
    java.lang.String get​(java.lang.String key, java.lang.String... replacements)
    Get a string from the config by its key
    java.lang.String get​(java.lang.String key, java.util.Map<java.lang.String,​java.lang.String> replacements)
    Get a string from the config by its key
    java.lang.String getLocale()
    Get the locale that this language config is for
    abstract C getRawConfig()
    Get the raw config object
    abstract void loadConfig()
    Load the config from the file system
    abstract boolean saveConfigResource()
    Save the default config resource from the jar file to the file system
    void setDefaults​(LanguageConfig<? extends C> defaults)
    Set the default config of this config

    Methods inherited from class java.lang.Object

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

    • resourcePath

      protected final java.lang.String resourcePath
    • configFile

      protected final java.io.File configFile
    • saveFile

      protected final boolean saveFile
    • config

      protected C config
    • defaultConfig

      protected C defaultConfig
  • Constructor Details

    • LanguageConfig

      protected LanguageConfig​(java.lang.String resourceFolder, java.io.File configFile, java.lang.String locale)
    • LanguageConfig

      protected LanguageConfig​(java.lang.String resourceFolder, java.io.File configFile, java.lang.String locale, boolean saveFile)
  • Method Details

    • loadConfig

      public abstract void loadConfig()
      Load the config from the file system
    • saveConfigResource

      public abstract boolean saveConfigResource()
      Save the default config resource from the jar file to the file system
      Returns:
      Whether or not the file was saved. If it already existed this will return false
    • contains

      public abstract boolean contains​(java.lang.String key)
      Check if the config contains a certain key
      Parameters:
      key - The key of the string
      Returns:
      true if this config (and not the defaults) has this key, false if not
    • contains

      public abstract boolean contains​(java.lang.String key, boolean checkDefault)
      Check if the config contains a certain key
      Parameters:
      key - The key of the string
      checkDefault - Whether or not to check the default config
      Returns:
      true if this config (and the default) has this key, false if not
    • get

      public abstract java.lang.String get​(java.lang.String key)
      Get a string from the config by its key
      Parameters:
      key - The key of the string
      Returns:
      The message or an error message if it doesn't exist; never null! (use contains(String) to check existance)
    • getRawConfig

      public abstract C getRawConfig()
      Get the raw config object
      Returns:
      The raw config object
    • get

      public java.lang.String get​(java.lang.String key, java.lang.String... replacements)
      Get a string from the config by its key
      Parameters:
      key - The key of the string
      replacements - What to replace the placeholders with. The n-th index is the placeholder, the n+1-th the value.
      Returns:
      The message with the placeholders replaced
    • get

      public java.lang.String get​(java.lang.String key, java.util.Map<java.lang.String,​java.lang.String> replacements)
      Get a string from the config by its key
      Parameters:
      key - The key of the string
      replacements - What to replace the placeholders with
      Returns:
      The message with the placeholders replaced
    • getLocale

      public java.lang.String getLocale()
      Get the locale that this language config is for
      Returns:
      The string representation of the locale of this config
    • setDefaults

      public void setDefaults​(LanguageConfig<? extends C> defaults)
      Set the default config of this config
      Parameters:
      defaults - The default or config or null if it should not have one