TheAwesomeGem / BlockDropsTweaker

Repository for the mod BlockDropsTweaker
Apache License 2.0
1 stars 0 forks source link

Change /bd save to save JSON pretty-printed #2

Open ChiriVulpes opened 6 years ago

ChiriVulpes commented 6 years ago

https://github.com/TheAwesomeGem/BlockDropsTweaker/blob/master/src/main/java/net/theawesomegem/blockdropstweaker/common/blockconfig/ConfigurationHandler.java#L156-L169

This is the way I write JsonObjects to strings in my mod:

private static String getJsonString (final JsonObject json, final String indent) {
    try {
        final StringWriter stringWriter = new StringWriter();
        final JsonWriter jsonWriter = new JsonWriter(stringWriter);
        jsonWriter.setLenient(true);
        jsonWriter.setIndent(indent == null ? "" : indent);
        Streams.write(json, jsonWriter);
        return stringWriter.toString();

    } catch (final IOException e) {
        return null;
    }
}

And then you just provide the method with the string it should indent with. Passing null or an empty string does minified JSON (like it is currently).

darchitectlp commented 6 years ago

In the meantime, if you use Sublime Text, install the "JSON Reindent" package. Fix you right up. But I agree, it'd be nice to have this as the default.