Class LanguageManager

java.lang.Object
me.remigio07.chatplugin.api.server.language.LanguageManager
All Implemented Interfaces:
ChatPluginManager

public abstract class LanguageManager extends Object implements ChatPluginManager
Manager that handles Languages.
See Also:
  • Field Details

  • Constructor Details

    • LanguageManager

      public LanguageManager()
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Description copied from interface: ChatPluginManager
      Checks if this manager is enabled.
      Specified by:
      isEnabled in interface ChatPluginManager
      Returns:
      Whether this manager is enabled
    • getDetector

      public LanguageDetector getDetector()
      Gets the language detector currently in use.
      Returns:
      Current language detector
    • getLanguages

      public List<Language> getLanguages()
      Gets the list of loaded languages.

      Do not modify the returned list.

      Returns:
      Loaded languages' list
    • getLanguage

      public Language getLanguage(String id)
      Gets a language from getLanguages() by its ID.

      Will return null if the language is not loaded.

      Parameters:
      id - Language's ID, case insensitive
      Returns:
      Loaded language
    • getMainLanguage

      public Language getMainLanguage()
      Gets the plugin's main and default language.

      Found at: "languages.main-language-id" in ConfigurationType.CONFIG

      Returns:
      Main language
    • isValidLanguageID

      public boolean isValidLanguageID(String languageID)
      Checks if the specified String is a valid language ID.
      Parameters:
      languageID - Language ID to check
      Returns:
      Whether the specified language ID is valid
      See Also:
    • getInstance

      public static LanguageManager getInstance()
      Gets this manager's instance.
      Returns:
      Manager's instance
    • getLanguage

      public abstract Language getLanguage(OfflinePlayer player)
      Gets a player's language using ChatPluginServerPlayer.getLanguage() if they are loaded, otherwise from the storage.

      Will return getMainLanguage() if they are not stored.

      Parameters:
      player - Player to check
      Returns:
      Player's language
    • setLanguage

      public abstract void setLanguage(OfflinePlayer player, Language language)
      Sets a player's language, updates it in the storage and reloads the player if they were loaded.

      Note: if you pass a ChatPluginServerPlayer as player, their reference will be invalidated because they will be unloaded. After calling this method, obtain a new instance of that player using ServerPlayerManager.getPlayer(java.util.UUID).

      Note: this method might take some time to be executed: async calls are recommended.

      Parameters:
      player - Player to set the language for
      language - Language to set
      Throws:
      IllegalArgumentException - If the new specified language corresponds to the old one
      See Also: