Added basic Forge and Curse support
This commit is contained in:
parent
efea6b3d20
commit
9d11ed49fb
|
@ -1,3 +1,4 @@
|
|||
.gradle
|
||||
.idea
|
||||
src/test
|
||||
src/test
|
||||
build
|
|
@ -0,0 +1,32 @@
|
|||
package ley.anvil.addonscript.curse;
|
||||
|
||||
import ley.anvil.addonscript.v1.AddonscriptJSON;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CurseTools {
|
||||
|
||||
public static void addCurseRepo(AddonscriptJSON as) {
|
||||
if (as.repositories == null) {
|
||||
as.repositories = new ArrayList<>();
|
||||
}
|
||||
boolean alreadyAdded = false;
|
||||
for (AddonscriptJSON.Repository repo : as.repositories) {
|
||||
if (repo.id != null && repo.id.equals("curse")) {
|
||||
alreadyAdded = true;
|
||||
}
|
||||
}
|
||||
if (!alreadyAdded) {
|
||||
AddonscriptJSON.Repository curseRepo = new AddonscriptJSON.Repository();
|
||||
curseRepo.id = "curse";
|
||||
curseRepo.type = "curseforge";
|
||||
curseRepo.url = "https://www.curseforge.com/minecraft/";
|
||||
as.repositories.add(curseRepo);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toArtifact(int projectID, int fileID) {
|
||||
return "curse:" + projectID + ":" + fileID;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package ley.anvil.addonscript.curse;
|
||||
|
||||
import ley.anvil.addonscript.util.JSON;
|
||||
import ley.anvil.addonscript.v1.AddonscriptJSON;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ManifestJSON extends JSON {
|
||||
|
||||
public ManifestJSON fromJSON(String json) {
|
||||
return gson.fromJson(json, ManifestJSON.class);
|
||||
}
|
||||
|
||||
public Minecraft minecraft;
|
||||
|
||||
public String manifestType;
|
||||
|
||||
public String manifestVersion;
|
||||
|
||||
public String name;
|
||||
|
||||
public String version;
|
||||
|
||||
public String author;
|
||||
|
||||
public List<File> files;
|
||||
|
||||
public String overrides = "overrides";
|
||||
|
||||
public static class Minecraft {
|
||||
public String version;
|
||||
public List<Modloader> modLoaders;
|
||||
}
|
||||
|
||||
public static class Modloader {
|
||||
public String id;
|
||||
public boolean primary;
|
||||
}
|
||||
|
||||
public static class File {
|
||||
public int projectID;
|
||||
public int fileID;
|
||||
public boolean required;
|
||||
|
||||
public AddonscriptJSON.Relation toRelation() {
|
||||
AddonscriptJSON.Relation rel = new AddonscriptJSON.Relation();
|
||||
rel.file = CurseTools.toArtifact(projectID, fileID);
|
||||
return rel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package ley.anvil.addonscript.forge;
|
||||
|
||||
import ley.anvil.addonscript.v1.AddonscriptJSON;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ForgeTools {
|
||||
|
||||
public static void addForgeRepo(AddonscriptJSON as) {
|
||||
if (as.repositories == null) {
|
||||
as.repositories = new ArrayList<>();
|
||||
}
|
||||
boolean alreadyAdded = false;
|
||||
for (AddonscriptJSON.Repository repo : as.repositories) {
|
||||
if (repo.id != null && repo.id.equals("forge")) {
|
||||
alreadyAdded = true;
|
||||
}
|
||||
}
|
||||
if (!alreadyAdded) {
|
||||
AddonscriptJSON.Repository repo = new AddonscriptJSON.Repository();
|
||||
repo.id = "forge";
|
||||
repo.type = "forge";
|
||||
repo.url = "https://files.minecraftforge.net/";
|
||||
as.repositories.add(repo);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addForge(AddonscriptJSON as, int version, String forgeVersion) {
|
||||
addForgeRepo(as);
|
||||
if (as.versions == null) {
|
||||
as.versions = new ArrayList<>();
|
||||
as.versions.add(new AddonscriptJSON.Version());
|
||||
}
|
||||
AddonscriptJSON.Version ver = null;
|
||||
for (AddonscriptJSON.Version v : as.versions) {
|
||||
if (v.versionid == version || v.versionid == -1) {
|
||||
ver = v;
|
||||
}
|
||||
}
|
||||
if (ver != null) {
|
||||
AddonscriptJSON.Relation rel = new AddonscriptJSON.Relation();
|
||||
rel.type = "required";
|
||||
if (as.type != null && as.type.equals("modpack")) {
|
||||
rel.type = "included";
|
||||
}
|
||||
rel.installer = "internal.forge";
|
||||
rel.file = forgeVersion;
|
||||
if (ver.relations == null) {
|
||||
ver.relations = new ArrayList<>();
|
||||
}
|
||||
ver.relations.add(rel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -3,6 +3,10 @@ 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;
|
||||
|
||||
public abstract class JSON {
|
||||
|
||||
public static Gson gson = new GsonBuilder().create();
|
||||
|
@ -15,5 +19,15 @@ public abstract class JSON {
|
|||
public String toString() {
|
||||
return toJSON();
|
||||
}
|
||||
|
||||
public String toFormattedJSON() {
|
||||
return formatJSON(toJSON());
|
||||
}
|
||||
|
||||
|
||||
public static String formatJSON(String json) {
|
||||
//TODO JSON formatting
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ public class AddonscriptJSON extends JSON {
|
|||
public String id;
|
||||
/**
|
||||
* The type of this repository
|
||||
* Currently supported: curseforge
|
||||
* Currently supported: curseforge, forge
|
||||
*/
|
||||
public String type;
|
||||
/**
|
||||
|
@ -195,7 +195,8 @@ public class AddonscriptJSON extends JSON {
|
|||
*/
|
||||
public String installer = "internal.dir:mods";
|
||||
/**
|
||||
* A link to the file or another Addonscript JSON file
|
||||
* A link to the file, a link to another Addonscript JSON file or an artifact String
|
||||
* Artifact String format: <repository id>:<repository specific string>
|
||||
*/
|
||||
public String file;
|
||||
/**
|
||||
|
@ -203,11 +204,6 @@ public class AddonscriptJSON extends JSON {
|
|||
* Supported type: included, required, recommended, optional or incompatible
|
||||
*/
|
||||
public String type = "included";
|
||||
/**
|
||||
* A String which represents the file as an artifact.
|
||||
* Format: <repository id>:<repository specific string>
|
||||
*/
|
||||
public String artifact;
|
||||
/**
|
||||
* Informations about the version of the addons
|
||||
* Only useable when using a link to a Addonscript JSON file
|
||||
|
|
Loading…
Reference in New Issue