public class JSONUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
JSONUtils.CommonDataJSONObject
Provides a wrapper around
JSONObject that allows saving and restoring its values to/from the common data
folder (saves/common). |
Modifier and Type | Method and Description |
---|---|
static void |
clear(JSONObject toClear)
Clears all entries in a
JSONObject . |
static JSONUtils.CommonDataJSONObject |
loadCommonJSON(String filename)
Loads a JSON file from common data, or creates it if it does not already exist.
|
static JSONUtils.CommonDataJSONObject |
loadCommonJSON(String filename,
@Nullable String defaultJSONPath)
Loads a JSON file from common data, or creates it, populates it with default values, and saves it to disk
if it does not already exist.
|
static Color |
toColor(JSONArray array)
|
public static void clear(JSONObject toClear)
JSONObject
.toClear
- The JSONObject
to clear.public static Color toColor(JSONArray array) throws JSONException
JSONArray
of int
s into a Color
.
Use with SettingsAPI
's file loading methods to read a color
from a file.array
- The JSONArray
to convert to a Color
.Color
using array
's color values.JSONException
- if array
doesn't contain three or more ints
public static JSONUtils.CommonDataJSONObject loadCommonJSON(String filename, @Nullable @Nullable String defaultJSONPath) throws IOException, JSONException
filename
- The filename to load (or create) in common data.defaultJSONPath
- The path to a default JSON in a mod folder. If filename
does not already exist in
the common data directory, it will be created and populated with the contents of this JSON
file.JSONObject
that allows saving to common data.IOException
JSONException
public static JSONUtils.CommonDataJSONObject loadCommonJSON(String filename) throws IOException, JSONException
filename
- The filename to load (or create) in common data.JSONObject
that allows saving to common data.IOException
JSONException