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

public class JSONParser extends Object
Custom parser for JSON that doesn't trim whitespace or newlines as it is meant for storing data, not for super readable files.
  • Constructor Details

    • JSONParser

      public JSONParser()
  • Method Details

    • parseResource

      public static 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 static 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 static 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 static 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
    • save

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

      public static 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 static 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 static void dump(DataSection data, StringBuilder builder)
      Dumps config data to a string in JSON format
      Parameters:
      data - data to dump
      builder - string builder to use