More Curseforge stuff

This commit is contained in:
Timo Ley 2020-05-25 23:21:11 +02:00
parent 067994b705
commit 51921aa14d
4 changed files with 110 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package ley.anvil.addonscript.curse;
import com.therandomlabs.curseapi.file.CurseFile;
import ley.anvil.addonscript.v1.AddonscriptJSON;
import java.util.ArrayList;

View File

@ -0,0 +1,37 @@
package ley.anvil.addonscript.curse;
import com.therandomlabs.curseapi.CurseAPI;
import com.therandomlabs.curseapi.CurseException;
import com.therandomlabs.curseapi.file.CurseFile;
import ley.anvil.addonscript.util.IRepository;
import java.util.Optional;
public class CurseforgeRepository implements IRepository {
@Override
public String getFileURL(String artifact) {
CurseFile file = getFile(artifact);
if (file != null) {
return file.downloadURL().toString();
}
return "";
}
public CurseFile getFile(String artifact) {
String[] parts = artifact.split(":");
if (parts.length >= 2) {
int projectID = Integer.parseInt(parts[0]);
int fileID = Integer.parseInt(parts[1]);
try {
Optional<CurseFile> file = CurseAPI.file(projectID, fileID);
if (file.isPresent())
return file.get();
} catch (CurseException e) {
e.printStackTrace();
}
}
return null;
}
}

View File

@ -1,8 +1,10 @@
package ley.anvil.addonscript.curse;
import ley.anvil.addonscript.forge.ForgeTools;
import ley.anvil.addonscript.util.JSON;
import ley.anvil.addonscript.v1.AddonscriptJSON;
import java.util.ArrayList;
import java.util.List;
public class ManifestJSON extends JSON {
@ -35,6 +37,18 @@ public class ManifestJSON extends JSON {
public static class Modloader {
public String id;
public boolean primary;
public AddonscriptJSON.Relation toRelation() {
if (id != null && id.startsWith("forge-")) {
AddonscriptJSON.Relation rel = new AddonscriptJSON.Relation();
rel.installer = "internal.forge";
rel.type = "included";
rel.file = id.replaceAll("forge-", "");
return rel;
}
return null;
}
}
public static class File {
@ -50,4 +64,55 @@ public class ManifestJSON extends JSON {
}
AddonscriptJSON.Contributor getAuthor() {
AddonscriptJSON.Contributor author = new AddonscriptJSON.Contributor();
author.name = this.author;
author.roles = new ArrayList<>();
author.roles.add("author");
return author;
}
AddonscriptJSON.Version getVersion() {
AddonscriptJSON.Version version = new AddonscriptJSON.Version();
version.versionid = -1;
version.versionname = this.version;
version.mcversion = new ArrayList<>();
version.mcversion.add(minecraft.version);
version.files = new ArrayList<>();
version.relations = new ArrayList<>();
AddonscriptJSON.File overrides = new AddonscriptJSON.File();
overrides.id = "overrides";
overrides.file = this.overrides;
version.files.add(overrides);
for (File f : files) {
version.relations.add(f.toRelation());
}
if (minecraft != null) {
for (Modloader l : minecraft.modLoaders) {
version.relations.add(l.toRelation());
}
}
return version;
}
public AddonscriptJSON toAS() {
AddonscriptJSON as = AddonscriptJSON.create();
as.type = "modpack";
as.id = name;
as.meta = new AddonscriptJSON.Meta();
as.meta.contributors = new ArrayList<>();
as.versions = new ArrayList<>();
as.meta.contributors.add(getAuthor());
as.versions.add(getVersion());
CurseTools.addCurseRepo(as);
ForgeTools.addForgeRepo(as);
return as;
}
}

View File

@ -0,0 +1,7 @@
package ley.anvil.addonscript.util;
public interface IRepository {
String getFileURL(String artifact);
}