java.lang.Object
com.plotsquared.core.configuration.caption.load.CaptionLoader

public final class CaptionLoader extends Object
This class handles loading and updating of message files.
  • Method Details

    • of

      public 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. That instance will use the internalLocale to extract default values from the captionProvider
      Parameters:
      internalLocale - the locale used internally to resolve default messages from the caption provider.
      localeExtractor - a function to extract a locale from a path, e.g. by its name.
      captionProvider - the provider for default captions.
      Returns:
      a CaptionLoader instance that can load and patch message files.
    • 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 an IllegalArgumentException if the matcher doesn't match the file name of the input path. The language tag is loaded using Locale.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:
      Matcher.group(int), Path.getFileName()
    • loadAll

      public @NonNull CaptionMap loadAll(@NonNull Path directory) throws IOException
      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:
      Files.list(Path), loadSingle(Path)
    • loadSingle

      public @NonNull CaptionMap loadSingle(@NonNull Path file) throws IOException
      Load a message file into a new CaptionMap. The file name must match the pattern messages_<locale>.json where <locale> is a valid Locale string.
      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.