Class LanguageManager
java.lang.Object
me.remigio07.chatplugin.api.server.language.LanguageManager
- All Implemented Interfaces:
ChatPluginManager
Manager that handles
Languages.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternPattern representing the allowed language IDs. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the language detector currently in use.static LanguageManagerGets this manager's instance.getLanguage(String id) Gets a language fromgetLanguages()by its ID.abstract LanguagegetLanguage(OfflinePlayer player) Gets a player's language usingChatPluginServerPlayer.getLanguage()if they are loaded, otherwise from the storage.Gets the list of loaded languages.Gets the plugin's main and default language.booleanChecks if this manager is enabled.booleanisValidLanguageID(String languageID) Checks if the specified String is a valid language ID.abstract voidsetLanguage(OfflinePlayer player, Language language) Sets a player's language, updates it in the storage and reloads the player if they were loaded.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.remigio07.chatplugin.api.common.util.manager.ChatPluginManager
checkAvailability, isReloadable, load, reload, unload
-
Field Details
-
LANGUAGE_ID_PATTERN
Pattern representing the allowed language IDs.Regex:
^[a-zA-Z0-9-_]{2,36}$- See Also:
-
-
Constructor Details
-
LanguageManager
public LanguageManager()
-
-
Method Details
-
isEnabled
public boolean isEnabled()Description copied from interface:ChatPluginManagerChecks if this manager is enabled.- Specified by:
isEnabledin interfaceChatPluginManager- Returns:
- Whether this manager is enabled
-
getDetector
Gets the language detector currently in use.- Returns:
- Current language detector
-
getLanguages
Gets the list of loaded languages.Do not modify the returned list.
- Returns:
- Loaded languages' list
-
getLanguage
Gets a language fromgetLanguages()by its ID.Will return
nullif the language is not loaded.- Parameters:
id- Language's ID, case insensitive- Returns:
- Loaded language
-
getMainLanguage
Gets the plugin's main and default language.Found at: "languages.main-language-id" in
ConfigurationType.CONFIG- Returns:
- Main language
-
isValidLanguageID
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
Gets this manager's instance.- Returns:
- Manager's instance
-
getLanguage
Gets a player's language usingChatPluginServerPlayer.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
Sets a player's language, updates it in the storage and reloads the player if they were loaded.Note: if you pass a
ChatPluginServerPlayerasplayer, their reference will be invalidated because they will be unloaded. After calling this method, obtain a new instance of that player usingServerPlayerManager.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 forlanguage- Language to set- Throws:
IllegalArgumentException- If the new specified language corresponds to the old one- See Also:
-