Class YAMLUtil

java.lang.Object
com.ranull.graves.util.YAMLUtil

public class YAMLUtil extends Object
Utility class for handling YAML file operations.
  • Method Details

    • isValidYAML

      public static boolean isValidYAML(File file)
      Checks if a given file is a valid YAML file.
      Parameters:
      file - The file to check.
      Returns:
      True if the file is a valid YAML file (i.e., does not start with a dot and ends with ".yml"), otherwise false.
    • validateWithBukkit

      @Nullable public static @Nullable YAMLUtil.YamlParseError validateWithBukkit(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull File diskFile, @Nullable @Nullable String jarResource)
      Validates a YAML file by attempting to load it through Bukkit's YamlConfiguration.
      Parameters:
      plugin - The plugin instance used to read bundled resources.
      diskFile - The YAML file on disk to validate.
      jarResource - The resource path inside the JAR for the corresponding config file (maybe null).
      Returns:
      Null if the YAML loads successfully; otherwise a populated YAMLUtil.YamlParseError.
    • logParseError

      public static void logParseError(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull String fileName, @NotNull @NotNull YAMLUtil.YamlParseError err)
      Logs a formatted YAML parse error to the console.
      Parameters:
      plugin - The plugin instance used for logging.
      fileName - The file name being logged (used only for display).
      err - The parse error to log.
    • buildSnippet

      @Nullable public static @Nullable String buildSnippet(@NotNull @NotNull List<String> lines, int line0, int col0, int above, int below)
      Builds a context snippet around a line with optional caret.
      Parameters:
      lines - Tab-expanded lines for accurate display.
      line0 - 0-based line index.
      col0 - 0-based column index, -1 for none.
      above - how many lines above to include
      below - how many lines below to include
    • guessNearestKey

      @Nullable public static @Nullable String guessNearestKey(@NotNull @NotNull List<String> rawLines, int errorLine0)
      Attempts to find the nearest YAML key above the specified line index.
      Parameters:
      rawLines - The raw file lines (unmodified).
      errorLine0 - The 0-based line index where the error occurred.
      Returns:
      The nearest key name, or null if none can be determined.
    • buildJarContextAroundKey

      @Nullable public static @Nullable String buildJarContextAroundKey(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull String resourcePath, @NotNull @NotNull String key, int above, int below)
      Builds a formatted snippet of a bundled JAR resource around a matching key line.
      Parameters:
      plugin - The plugin instance used to read bundled resources.
      resourcePath - The resource path inside the JAR.
      key - The key name to locate.
      above - Number of lines above the key line to include.
      below - Number of lines below the key line to include.
      Returns:
      A formatted snippet, or null if the resource is missing or the key cannot be found.