Class CaptionLoader
java.lang.Object
com.plotsquared.core.configuration.caption.load.CaptionLoader
This class handles loading and updating of message files.
-
Method Summary
Modifier and TypeMethodDescriptionLoad all message files in the given directory into a new CaptionMap.loadOrCreateSingle
(@NonNull Path file) Load a message file into a new CaptionMap.loadSingle
(@NonNull Path file) Load a message file into a new CaptionMap.static @NonNull CaptionLoader
of
(@NonNull Locale internalLocale, @NonNull Function<@NonNull Path, @NonNull Locale> localeExtractor, @NonNull DefaultCaptionProvider captionProvider, @NonNull String namespace) Returns a new CaptionLoader instance.patternExtractor
(@NonNull Pattern pattern) Returns a function that extracts a locale from a path using the given pattern.
-
Method Details
-
patternExtractor
public static @NonNull Function<@NonNull Path,@NonNull Locale> patternExtractor(@NonNull Pattern pattern) Returns a function that extracts a locale from a path using the given pattern. The pattern is required to have (at least) one capturing group, as this is used to access the locale tag.The function will throw anIllegalArgumentException
if the matcher doesn't match the file name of the input path. The language tag is loaded usingLocale.forLanguageTag(String)
.- Parameters:
pattern
- the pattern to match and extract the language tag with.- Returns:
- a function to extract a locale from a path using a pattern.
- See Also:
-
loadAll
Load all message files in the given directory into a new CaptionMap.- Parameters:
directory
- The directory to load files from- Returns:
- A new CaptionMap containing the loaded messages
- Throws:
IOException
- if the files in the given path can't be listed- See Also:
-
loadSingle
Load a message file into a new CaptionMap. The file name must match the pattern expected by thelocaleExtractor
. Note that this method does not attempt to create a new file.- Parameters:
file
- The file to load- Returns:
- A new CaptionMap containing the loaded messages
- Throws:
IOException
- if the file couldn't be accessed or read successfully.IllegalArgumentException
- if the file name doesn't match the specified format.- See Also:
-
loadOrCreateSingle
Load a message file into a new CaptionMap. The file name must match the pattern expected by thelocaleExtractor
. If no file exists at the given path, this method will attempt to create one and fill it with default values.- Parameters:
file
- The file to load- Returns:
- A new CaptionMap containing the loaded messages
- Throws:
IOException
- if the file couldn't be accessed or read successfully.IllegalArgumentException
- if the file name doesn't match the specified format.- Since:
- 6.9.3
- See Also: