Added ID to Relations

This commit is contained in:
Timo Ley 2020-06-05 22:55:19 +02:00
parent ce5ee87317
commit 31952dc43f
4 changed files with 51 additions and 8 deletions

View File

@ -1,8 +1,12 @@
package ley.anvil.addonscript.curse;
import com.therandomlabs.curseapi.CurseAPI;
import com.therandomlabs.curseapi.CurseException;
import com.therandomlabs.curseapi.project.CurseProject;
import ley.anvil.addonscript.v1.AddonscriptJSON;
import java.util.ArrayList;
import java.util.Optional;
public class CurseTools {
@ -41,4 +45,17 @@ public class CurseTools {
return false;
}
public static String getID(int projectID) {
try {
Optional<CurseProject> project = CurseAPI.project(projectID);
if (project.isPresent()) {
CurseProject proj = project.get();
return proj.slug();
}
} catch (CurseException e) {
return "NOID";
}
return "NOID";
}
}

View File

@ -39,6 +39,7 @@ public class ForgeTools {
}
if (ver != null) {
AddonscriptJSON.Relation rel = new AddonscriptJSON.Relation();
rel.id = "forge";
rel.type = "required";
if (as.type != null && as.type.equals("modpack")) {
rel.type = "included";

View File

@ -0,0 +1,26 @@
package ley.anvil.addonscript.util;
import ley.anvil.addonscript.v1.AddonscriptJSON;
import java.io.Reader;
public abstract class ASBase extends JSON {
public ASBase fromJSON(Reader reader) {
ASBase base = gson.fromJson(reader, ASBase.class);
return gson.fromJson(reader, base.getImpl());
}
/**
* The version of the AddonScript file
*/
public int asversion;
public Class<? extends ASBase> getImpl() {
switch (asversion) {
case 1: return AddonscriptJSON.class;
default: return ASBase.class;
}
}
}

View File

@ -1,10 +1,10 @@
package ley.anvil.addonscript.v1;
import ley.anvil.addonscript.util.JSON;
import ley.anvil.addonscript.util.ASBase;
import java.util.List;
public class AddonscriptJSON extends JSON {
public class AddonscriptJSON extends ASBase {
public static AddonscriptJSON fromJSON(String json) {
return fromJSON(json, AddonscriptJSON.class);
@ -16,11 +16,6 @@ public class AddonscriptJSON extends JSON {
return as;
}
/**
* The version of the AddonScript file
*/
public int asversion;
/**
* The ID of the addon
*/
@ -215,6 +210,11 @@ public class AddonscriptJSON extends JSON {
}
public static class Relation {
/**
* The ID of the relation
* This should be unique in this Addonscript file
*/
public String id;
/**
* The installer for this file
* Format: <installerid>:<param 1>:<param 2>...
@ -237,7 +237,6 @@ public class AddonscriptJSON extends JSON {
* already exposing this information
*/
public Meta meta;
/**
* A list of parameters for this relation.
* Currently supportet parameters: