4
0
Fork 0
mirror of https://github.com/Anvilcraft/modpacktools synced 2024-09-30 04:59:05 +02:00

Change to new Addonscript (to be tested by Lordy xD)

This commit is contained in:
Timo Ley 2020-07-24 14:30:43 +02:00
parent 6b0e35cf51
commit ad65ffc675
5 changed files with 38 additions and 32 deletions

View file

@ -1,6 +1,7 @@
plugins {
id 'java'
id 'application'
id 'idea'
}
group 'ley.anvil'
@ -15,7 +16,7 @@ repositories {
dependencies {
compile 'com.squareup.okhttp3:okhttp:4.8.0'
compile 'com.github.Anvilcraft:addonscript-java:788659c89a'
compile 'com.github.Anvilcraft:addonscript-java:425271587d'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile 'com.moandjiezana.toml:toml4j:0.7.2'
compile "com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"

View file

@ -63,9 +63,9 @@ public class AddMod implements ICommand {
//Get Mods in manifest file
//Check if Mod already exsits
for(AddonscriptJSON.Relation file : version.relations) {
if(file.file != null) {
String[] parts = file.file.split(":");
if(parts.length == 3 && parts[0].equals("curse")) { //TODO check, if it is a Curse repo, waiting for Addonscript to update this
if(file.file != null && file.file.artifact != null) {
String[] parts = file.file.artifact.split(":");
if(parts.length == 3 && parts[0].equals("curse")) {
int projID = Integer.parseInt(parts[1]);
if(projID == projectID) {
return CommandReturn.fail("The Mod Is already Installed");
@ -78,7 +78,7 @@ public class AddMod implements ICommand {
AddonscriptJSON.Relation rel = new AddonscriptJSON.Relation();
rel.file = CurseTools.toArtifact(projectID, fileID);
rel.type = "included";
rel.installer = "internal.dir";
rel.file.installer = "internal.dir";
//Add Mod to array
if(version.relations == null) {
version.relations = new ArrayList<>();
@ -89,9 +89,10 @@ public class AddMod implements ICommand {
}
}else {
AddonscriptJSON.Relation rel = new AddonscriptJSON.Relation();
rel.file = args[1];
rel.file = new AddonscriptJSON.File();
rel.file.link = args[1];
rel.type = "included";
rel.installer = "internal.dir";
rel.file.installer = "internal.dir";
if(version.relations == null) {
version.relations = new ArrayList<>();
}

View file

@ -47,7 +47,7 @@ public class ConvertManifestToModpackJSON implements ICommand {
@Nonnull
@Override
public String getName() {
return "convertmanifesttomodpackjson";
return "import";
}
@Nonnull

View file

@ -2,6 +2,8 @@ package ley.anvil.modpacktools.commands;
import j2html.TagCreator;
import j2html.tags.ContainerTag;
import ley.anvil.addonscript.v1.AddonscriptJSON;
import ley.anvil.modpacktools.Main;
import ley.anvil.modpacktools.command.CommandReturn;
import ley.anvil.modpacktools.command.ICommand;
import ley.anvil.modpacktools.command.LoadCommand;
@ -33,23 +35,24 @@ public class CreateModList implements ICommand {
try(CSVPrinter printer = new CSVPrinter(new FileWriter(csvFile), CSVFormat.EXCEL.withDelimiter(';'))) {
printer.printRecord("Name", "Authors", "Link", "Downloads", "ID");
printer.println();
ArrayList<ModInfo> modlist = ModInfo.getModInfo();
Collections.sort(modlist, Comparator.comparing(a -> a.getName().toLowerCase()));
for(ModInfo mod : modlist) {
String name = mod.getName();
String[] authorArr = mod.getAuthors();
String link = mod.getLink();
int downloads = mod.getDownloads();
int id = mod.getId();
ArrayList<AddonscriptJSON.Meta> modlist = new ArrayList<>();
for (AddonscriptJSON.Relation rel : Main.MPJH.getJson().getDefaultVersion().getRelations("client", false, null)) {
modlist.add(rel.getMeta(Main.MPJH.getJson().indexes));
}
Collections.sort(modlist, Comparator.comparing(a -> a.name.toLowerCase()));
for(AddonscriptJSON.Meta mod : modlist) {
String name = mod.name;
AddonscriptJSON.Contributor[] authorArr = mod.contributors.toArray(new AddonscriptJSON.Contributor[0]);
String link = mod.website;
StringBuilder sb = new StringBuilder();
for(String author : authorArr) {
sb.append(author);
for(AddonscriptJSON.Contributor author : authorArr) {
sb.append(author.name);
sb.append(", ");
}
String authors = sb.toString();
authors = authors.substring(0, authors.length() - 2);
printer.printRecord(name, authors, link, downloads, id);
printer.printRecord(name, authors, link);
}
}catch(IOException e) {
e.printStackTrace();
@ -59,8 +62,11 @@ public class CreateModList implements ICommand {
if(htmlFile.exists()) {
return CommandReturn.fail("Delete " + htmlFile);
}
ArrayList<ModInfo> mods = ModInfo.getModInfo();
Collections.sort(mods, Comparator.comparing(a -> a.getName().toLowerCase()));
ArrayList<AddonscriptJSON.Meta> mods = new ArrayList<>();
for (AddonscriptJSON.Relation rel : Main.MPJH.getJson().getDefaultVersion().getRelations("client", false, null)) {
mods.add(rel.getMeta(Main.MPJH.getJson().indexes));
}
Collections.sort(mods, Comparator.comparing(a -> a.name.toLowerCase()));
ContainerTag table = body(
TagCreator.table(TagCreator.attrs("#mods"), TagCreator.tbody(
tr(td(b("Name")),
@ -70,20 +76,18 @@ public class CreateModList implements ICommand {
),
TagCreator.each(mods, i -> {
StringBuilder sb = new StringBuilder();
for(String author : i.getAuthors()) {
sb.append(author);
for(AddonscriptJSON.Contributor author : i.contributors) {
sb.append(author.name);
sb.append(", ");
}
String authors = sb.toString();
authors = authors.substring(0, authors.length() - 2);
return tr(td(a(i.getName())
.withHref(i.getLink())
return tr(td(a(i.name)
.withHref(i.website)
.withRel("noopener noreferrer")
.withTarget("_blank")),
td(authors),
td(String.valueOf(i.getId())),
td(String.valueOf(i.getDownloads())));
td(authors));
})
))
);

View file

@ -1,5 +1,6 @@
package ley.anvil.modpacktools.commands;
import ley.anvil.modpacktools.Main;
import ley.anvil.modpacktools.command.CommandReturn;
import ley.anvil.modpacktools.command.ICommand;
import ley.anvil.modpacktools.command.LoadCommand;
@ -33,11 +34,10 @@ public class DownloadMods implements ICommand {
};
FileDownloader.downloadAsync(
ModInfo.getModInfo()
.stream()
Main.MPJH.getJson().getDefaultVersion().getRelLinks(Main.MPJH.getJson().indexes, "client", false, "internal.dir:mods", null).stream()
.collect(Collectors.toMap(
i -> Util.sanitizeURL(toURL.apply(i.getDownload())),
i -> new File(args[1], Paths.get(toURL.apply(i.getDownload()).getPath()).getFileName().toString())
i -> Util.sanitizeURL(toURL.apply(i.getKey())),
i -> new File(args[1], Paths.get(toURL.apply(i.getKey()).getPath()).getFileName().toString())
)),
r -> {
//Synced to prevent the exception being printed too late