Class LanguageManagerCore<S,​C>

java.lang.Object
de.themoep.utils.lang.LanguageManagerCore<S,​C>
Type Parameters:
S - The command sender type
C - The configuration type
Direct Known Subclasses:
LanguageManager, LanguageManager, LanguageManager, LanguageManager

public abstract class LanguageManagerCore<S,​C>
extends java.lang.Object
The core language manager
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected java.lang.String filePrefix  
    protected java.lang.String fileSuffix  
    protected boolean saveFiles  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected LanguageManagerCore​(java.lang.String defaultLocale, java.lang.String resourceFolder, java.io.File folder, LanguageProvider<S> provider, java.lang.String filePrefix, java.lang.String fileSuffix, boolean saveFiles, LanguageConfig<C>... configs)  
  • Method Summary

    Modifier and Type Method Description
    LanguageConfig<C> addConfig​(LanguageConfig<C> config)
    Add a new language config for a specific locale
    LanguageConfig<C> getConfig​(java.lang.String locale)
    Get a language config for a specific locale
    LanguageConfig<C> getConfig​(S sender)
    Get a language config for a sender object using the specified provider
    java.util.Collection<LanguageConfig<C>> getConfigs()
    Get all defined language configs
    LanguageConfig<C> getDefaultConfig()
    Get the default language config
    java.lang.String getDefaultLocale()
    Get the default locale to use when no special one was specified or the one requested doesn't exist.
    java.io.File getFolder()
    Get the folder that the language files are in
    java.lang.String getPlaceholderPrefix()
    Get the prefix of placeholders for replacements
    java.lang.String getPlaceholderSuffix()
    Get the suffix of placeholders for replacements
    LanguageProvider<S> getProvider()
    Get the specified language provider
    java.lang.String getResourceFolder()
    Get the path to the folder that contains the default language configs inside of the jar
    abstract void loadConfigs()  
    protected void loadConfigs​(java.lang.Class<?> pluginClass, LangLogger logger, java.util.function.Function<java.lang.String,​LanguageConfig<C>> configCreator)  
    void setDefaultLocale​(java.lang.String locale)
    Set the default locale to use when no special one was specified or the one requested doesn't exist.
    void setPlaceholderPrefix​(java.lang.String placeholderPrefix)
    Set the prefix of placeholders for replacements
    void setPlaceholderSuffix​(java.lang.String placeholderSuffix)
    Set the suffix of placeholders for replacements
    void setProvider​(LanguageProvider<S> provider)
    Set the provider for the player's language

    Methods inherited from class java.lang.Object

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

    • filePrefix

      protected final java.lang.String filePrefix
    • fileSuffix

      protected final java.lang.String fileSuffix
    • saveFiles

      protected final boolean saveFiles
  • Constructor Details

    • LanguageManagerCore

      protected LanguageManagerCore​(java.lang.String defaultLocale, java.lang.String resourceFolder, java.io.File folder, LanguageProvider<S> provider, java.lang.String filePrefix, java.lang.String fileSuffix, boolean saveFiles, LanguageConfig<C>... configs)
  • Method Details

    • loadConfigs

      public abstract void loadConfigs()
    • loadConfigs

      protected void loadConfigs​(java.lang.Class<?> pluginClass, LangLogger logger, java.util.function.Function<java.lang.String,​LanguageConfig<C>> configCreator)
    • addConfig

      public LanguageConfig<C> addConfig​(LanguageConfig<C> config)
      Add a new language config for a specific locale
      Parameters:
      config - The language config that holds all messages for the specified locale
      Returns:
      The previous language config if it existed or null if not
    • getConfig

      public LanguageConfig<C> getConfig​(java.lang.String locale)
      Get a language config for a specific locale
      Parameters:
      locale - The string representation of the locale to add the config for
      Returns:
      The language config that holds all messages for the specified locale. If no config is defined for that locale it will return the default locale.
    • getConfig

      public LanguageConfig<C> getConfig​(S sender)
      Get a language config for a sender object using the specified provider
      Parameters:
      sender - The sender to get the language config for
      Returns:
      The language config that holds all messages for the locale specified by the provider. If no config is defined for that locale it will return the default locale.
    • getConfigs

      public java.util.Collection<LanguageConfig<C>> getConfigs()
      Get all defined language configs
      Returns:
      A collection of defined language configs
    • getDefaultLocale

      public java.lang.String getDefaultLocale()
      Get the default locale to use when no special one was specified or the one requested doesn't exist. Also used as the default config when querying a message by its key.
      Returns:
      The default locale string
    • setDefaultLocale

      public void setDefaultLocale​(java.lang.String locale)
      Set the default locale to use when no special one was specified or the one requested doesn't exist. Also used as the default config when querying a message by its key. If set to null it will use the first define language config.
      Parameters:
      locale - The default locale string
    • getPlaceholderPrefix

      public java.lang.String getPlaceholderPrefix()
      Get the prefix of placeholders for replacements
      Returns:
      The placeholder prefix
    • setPlaceholderPrefix

      public void setPlaceholderPrefix​(java.lang.String placeholderPrefix)
      Set the prefix of placeholders for replacements
      Parameters:
      placeholderPrefix - The placeholder prefix
    • getPlaceholderSuffix

      public java.lang.String getPlaceholderSuffix()
      Get the suffix of placeholders for replacements
      Returns:
      The placeholder suffix
    • setPlaceholderSuffix

      public void setPlaceholderSuffix​(java.lang.String placeholderSuffix)
      Set the suffix of placeholders for replacements
      Parameters:
      placeholderSuffix - The placeholder suffix
    • getDefaultConfig

      public LanguageConfig<C> getDefaultConfig()
      Get the default language config
      Returns:
      The default language config. If none was defined it will return the first found language. If none is found then it returns null.
    • getResourceFolder

      public java.lang.String getResourceFolder()
      Get the path to the folder that contains the default language configs inside of the jar
      Returns:
      The path to the folder, should never be null or empty!
    • getFolder

      public java.io.File getFolder()
      Get the folder that the language files are in
      Returns:
      The folder that is used to store this manager's config files
    • setProvider

      public void setProvider​(LanguageProvider<S> provider) throws java.lang.IllegalArgumentException
      Set the provider for the player's language
      Parameters:
      provider - The provider
      Throws:
      java.lang.IllegalArgumentException - when provider is null
    • getProvider

      public LanguageProvider<S> getProvider()
      Get the specified language provider
      Returns:
      The specified provider or null if not set