Curse Updates

This commit is contained in:
Timo Ley 2020-07-17 23:48:30 +02:00
parent 4ff9f44e50
commit a195f248b1
4 changed files with 52 additions and 11 deletions

View File

@ -16,7 +16,7 @@ public class CurseTools {
}
boolean alreadyAdded = false;
for (AddonscriptJSON.Repository repo : as.repositories) {
if (repo.id != null && repo.id.equals("curse")) {
if (repo.type != null && repo.type.equals("curseforge")) {
alreadyAdded = true;
}
}
@ -36,12 +36,14 @@ public class CurseTools {
}
public static boolean isCurseArtifact(String artifact, AddonscriptJSON as) {
String[] parts = artifact.split(">");
if (parts.length == 2 && as.repositories != null) {
for (AddonscriptJSON.Repository repo : as.repositories) {
if (repo.type != null && repo.type.equals("curseforge") && parts[0].equals(repo.id)) {
return true;
}
String[] parts = artifact.split(":");
if (parts.length == 3 && parts[0].equals("curse")) {
try {
int proj = Integer.parseInt(parts[1]);
int file = Integer.parseInt(parts[0]);
return true;
} catch (NumberFormatException e) {
return false;
}
}
return false;

View File

@ -3,8 +3,12 @@ package ley.anvil.addonscript.curse;
import com.therandomlabs.curseapi.CurseAPI;
import com.therandomlabs.curseapi.CurseException;
import com.therandomlabs.curseapi.file.CurseFile;
import com.therandomlabs.curseapi.project.CurseProject;
import ley.anvil.addonscript.util.IRepository;
import ley.anvil.addonscript.v1.AddonscriptJSON;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
public class CurseforgeRepository implements IRepository {
@ -18,11 +22,36 @@ public class CurseforgeRepository implements IRepository {
return "";
}
@Override
public AddonscriptJSON.Meta getMeta(String artifact) {
AddonscriptJSON.Meta meta = new AddonscriptJSON.Meta();
CurseFile file = getFile(artifact);
if (file != null) {
try {
CurseProject project = file.project();
meta.name = project.name();
String desc = project.descriptionPlainText();
meta.description = Arrays.asList(desc.split("\n"));
meta.website = project.url().toString();
meta.contributors = new ArrayList<>();
AddonscriptJSON.Contributor owner = new AddonscriptJSON.Contributor();
owner.roles = new ArrayList<>();
owner.roles.add("owner");
owner.name = project.author().name();
meta.contributors.add(owner);
meta.icon = project.logo().url().toString();
} catch (CurseException e) {
e.printStackTrace();
}
}
return meta;
}
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]);
if (parts.length >= 3 && parts[0].equals("curse")) {
int projectID = Integer.parseInt(parts[1]);
int fileID = Integer.parseInt(parts[2]);
try {
Optional<CurseFile> file = CurseAPI.file(projectID, fileID);
if (file.isPresent())

View File

@ -78,7 +78,7 @@ public class ManifestJSON extends JSON {
AddonscriptJSON.Version getVersion() {
AddonscriptJSON.Version version = new AddonscriptJSON.Version();
version.versionid = -1;
version.versionname = this.version;
version.version = this.version;
version.mcversion = new ArrayList<>();
version.mcversion.add(minecraft.version);
version.files = new ArrayList<>();

View File

@ -1,5 +1,7 @@
package ley.anvil.addonscript.util;
import ley.anvil.addonscript.v1.AddonscriptJSON;
/**
* Interface for all repository types
*/
@ -12,4 +14,12 @@ public interface IRepository {
*/
String getFileURL(String artifact);
/**
* Gets meta information about an artifact.
* Empty Object if nothing was found.
* @param artifact The artifact without the repo ID prefix
* @return A Meta object with meta information
*/
AddonscriptJSON.Meta getMeta(String artifact);
}