diff --git a/build.gradle b/build.gradle index 3766af8..b227ca9 100644 --- a/build.gradle +++ b/build.gradle @@ -9,12 +9,13 @@ sourceCompatibility = 1.8 repositories { mavenCentral() + maven { url 'https://jitpack.io' } } dependencies { compile 'com.google.code.gson:gson:+' compile 'org.apache.maven:maven-core:+' compile 'org.python:jython:2.7.0' - + compile "com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT" testCompile group: 'junit', name: 'junit', version: '4.12' } diff --git a/src/main/java/ley/anvil/addonscript/util/JSON.java b/src/main/java/ley/anvil/addonscript/util/JSON.java index 1d8e27b..d6e0c36 100644 --- a/src/main/java/ley/anvil/addonscript/util/JSON.java +++ b/src/main/java/ley/anvil/addonscript/util/JSON.java @@ -3,13 +3,12 @@ package ley.anvil.addonscript.util; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; +import java.io.Reader; +import java.io.Writer; public abstract class JSON { - public static Gson gson = new GsonBuilder().create(); + public static Gson gson = new GsonBuilder().setPrettyPrinting().create(); public String toJSON() { return gson.toJson(this); @@ -20,14 +19,16 @@ public abstract class JSON { return toJSON(); } - public String toFormattedJSON() { - return formatJSON(toJSON()); + public void write(Writer writer) { + gson.toJson(this, writer); } + public static T read(Reader reader, Class type) { + return gson.fromJson(reader, type); + } - public static String formatJSON(String json) { - //TODO JSON formatting - return json; + public static T fromJSON(String json, Class type) { + return gson.fromJson(json, type); } } diff --git a/src/main/java/ley/anvil/addonscript/v1/AddonscriptJSON.java b/src/main/java/ley/anvil/addonscript/v1/AddonscriptJSON.java index de0aad5..05b2716 100644 --- a/src/main/java/ley/anvil/addonscript/v1/AddonscriptJSON.java +++ b/src/main/java/ley/anvil/addonscript/v1/AddonscriptJSON.java @@ -7,7 +7,7 @@ import java.util.List; public class AddonscriptJSON extends JSON { public static AddonscriptJSON fromJSON(String json) { - return gson.fromJson(json, AddonscriptJSON.class); + return fromJSON(json, AddonscriptJSON.class); } public static AddonscriptJSON create() { @@ -176,6 +176,14 @@ public class AddonscriptJSON extends JSON { } public static class File { + /** + * The ID of this file. + * If multiple files have the same ID, + * Addonscript will interpret this files as identical. + * Addonscript will then try to install the first of them + * and only if this fails, it will try the next. + */ + public String id; /** * The installer for this file * Format: ::... @@ -219,12 +227,6 @@ public class AddonscriptJSON extends JSON { * Supported type: included, required, recommended, optional or incompatible */ public String type = "included"; - /** - * Informations about the version of the addons - * Only useable when using a link to a Addonscript JSON file - */ - public VersionData version; - /** * Meta information for this relation * This is not always useful, because some repositories, like curseforge, are @@ -247,25 +249,4 @@ public class AddonscriptJSON extends JSON { } - /** - * Currently useless - */ - public static class VersionData { - - public String version; - - public int versionID; - - public int minVersion; - - public int maxVersion; - - public boolean openUp; - - public boolean openDown; - - } - - - }