java.lang.Object
studio.magemonkey.codex.mccore.config.parse.YAMLParser

public class YAMLParser extends Object
Custom parser for YAML that preserves comments with the key they precede.

Fixed up Feb 2024 by Travja for more actual YAML spec compliance.

  • Constructor Details

    • YAMLParser

      public YAMLParser()
  • Method Details

    • parseResource

      public DataSection parseResource(org.bukkit.plugin.Plugin plugin, String path)
      Reads and then parses data from an embedded plugin resource. If the resource does not exist or doesn't contain any data, this will return an empty DataSection object.
      Parameters:
      plugin - plugin containing the embedded resource
      path - path to the resource (not including the beginning slash)
      Returns:
      loaded data
    • parseFile

      public DataSection parseFile(String path)
      Reads and then parses data from the file at the given path. If the file does not exist or doesn't contain any data, this will return an empty DataSection object.
      Parameters:
      path - path to the file load from
      Returns:
      loaded data
    • parseFile

      public DataSection parseFile(File file)
      Reads and then parses data from the file. If the file does not exist or doesn't contain any data, this will return an empty DataSection object.
      Parameters:
      file - the file load from
      Returns:
      loaded data
    • parseText

      public DataSection parseText(String text)
      Parses the text read in from a file. If a null string is passed in, this will return an empty data section.
      Parameters:
      text - text to parse
      Returns:
      parsed data
    • parseText

      public DataSection parseText(String text, char quote)
      Parses the text read in from a file. If a null string is passed in, this will return an empty data section.
      Parameters:
      text - text to parse
      quote - character strings are wrapped in
      Returns:
      parsed data
    • save

      public void save(DataSection data, String path)
      Saves config data to a file
      Parameters:
      path - path to the file
    • save

      public void save(DataSection data, File file)
      Dumps the data contents to a file to the given file
      Parameters:
      file - file to dump to
    • save

      public void save(DataSection data, BufferedWriter write) throws IOException
      Dumps the data contents into the stream
      Parameters:
      write - stream to dump to
      Throws:
      IOException
    • dump

      public void dump(DataSection data, StringBuilder builder, int indent, char quote)
      Dumps config data to a string in YAML format
      Parameters:
      data - data to dump
      builder - string builder to use
      indent - starting indent
      quote - character to use for containing strings