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

Implemented new Addonscript

This commit is contained in:
Timo Ley 2020-07-26 16:38:16 +02:00
parent cc5fcd6cd2
commit fdbbea9682
5 changed files with 31 additions and 19 deletions

View file

@ -22,7 +22,7 @@ dependencies {
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.8'
//Other
compile 'com.github.Anvilcraft:addonscript-java:7507be1'
compile 'com.github.Anvilcraft:addonscript-java:b560f84d5f'
compile 'com.squareup.okhttp3:okhttp:4.8.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'

View file

@ -24,7 +24,7 @@ public class AddMod implements ICommand {
public CommandReturn execute(String[] args) {
//Check if the command has the correct number of args
if(args.length >= 2) {
AddonscriptJSON json = Main.MPJH.getJson();
AddonscriptJSON json = Main.MPJH.getJson().getJson();
AddonscriptJSON.Version version = null;
if(json != null && json.versions != null) {
if(json.versions.size() == 1) {

View file

@ -2,6 +2,7 @@ package ley.anvil.modpacktools.commands
import j2html.TagCreator.*
import ley.anvil.addonscript.v1.AddonscriptJSON
import ley.anvil.addonscript.wrapper.MetaData
import ley.anvil.modpacktools.Main
import ley.anvil.modpacktools.command.CommandReturn
import ley.anvil.modpacktools.command.CommandReturn.Companion.fail
@ -43,7 +44,7 @@ object CreateModlist : ICommand {
for(mod in getMods()) {
printer.printRecord(
mod.name,
mod.contributors.joinToString {c -> c.name},
mod.contributors.keys.joinToString(),
mod.website
)
}
@ -81,7 +82,7 @@ object CreateModlist : ICommand {
.withTarget("_blank")),
td(ul(
each(it.contributors) {contr ->
li(contr.name)
li(contr.key)
}
))
)
@ -94,19 +95,23 @@ object CreateModlist : ICommand {
return success("Wrote HTML file")
}
private fun getMods(): List<AddonscriptJSON.Meta> {
private fun getMods(): List<MetaData> {
println("Getting mods... this may take a while (TODO)")
val asJson = Main.MPJH.json
val mods = ArrayList<AddonscriptJSON.Meta>()
val mods = ArrayList<MetaData>()
val toGet = ArrayList<String>()
asJson!!.load()
for(rel in asJson.defaultVersion.getRelations("client", false, null)) {
val meta = rel.getMeta(asJson.indexes)
println("got info for file ${meta.name}")
if(meta.name != null) mods.add(meta) else println("meta name == null")
for(rel in asJson!!.defaultVersion.getRelations(arrayOf("client"), null)) {
if (rel.hasLocalMeta()) {
println("got info for file ${rel.localMeta.name}")
mods.add(rel.localMeta)
}
else if (rel.hasFile() && rel.file.isArtifact)
toGet.add(rel.file.artifact)
}
return mods.sortedBy {m -> m.name.toLowerCase()}
val metaMap = asJson.repositories.getMeta(toGet.toArray(emptyArray()))
mods.addAll(metaMap.values)
return mods.sortedBy {m -> m.name?.toLowerCase() }
}
private fun Array<out String>.checkArgs(): Boolean = this.size >= 3 && this[1] in arrayOf("html", "csv")

View file

@ -1,5 +1,6 @@
package ley.anvil.modpacktools.commands
import ley.anvil.addonscript.wrapper.ASWrapper
import ley.anvil.addonscript.wrapper.LinkInstPair
import ley.anvil.modpacktools.Main.MPJH
import ley.anvil.modpacktools.command.CommandReturn
@ -26,12 +27,17 @@ object DownloadMods : ICommand {
val json = MPJH.json
json!!.load()
var filelist = ArrayList<ASWrapper.FileWrapper>()
for (rel in json?.defaultVersion?.getRelations(arrayOf("client"), "mod")!!) {
if (rel.hasFile())
filelist.add(rel.file)
}
FileDownloader(
json!!.defaultVersion.getRelLinks(json.indexes, "client", false, "internal.dir:mods", null).stream()
filelist.stream()
.filter {it.isURL}
.collect(toMap<LinkInstPair, URL, File>(
{it.asURL()},
.collect(toMap<ASWrapper.FileWrapper, URL, File>(
{URL(it.link)}, //TODO Get the link using Multithreadding
{File(args[1], Paths.get(URL(it.link).path).fileName.toString())},
{_: File, f: File -> f}
)),

View file

@ -1,16 +1,17 @@
package ley.anvil.modpacktools.util
import ley.anvil.addonscript.v1.AddonscriptJSON
import ley.anvil.addonscript.wrapper.ASWrapper
import java.io.File
import java.io.FileReader
class ModpackJsonHandler(val modpackJsonFile: File) {
var json: AddonscriptJSON? = null
var json: ASWrapper? = null
private set
get() = field ?: run {
if(modpackJsonFile.exists()) {
val reader = FileReader(modpackJsonFile)
field = AddonscriptJSON.read(reader, AddonscriptJSON::class.java)
field = ASWrapper(AddonscriptJSON.read(reader, AddonscriptJSON::class.java))
reader.close()
}
field