buildscript { dependencies { classpath group: 'com.diluv.schoomp', name: 'Schoomp', version: '1.1.0' } } plugins { id "architectury-plugin" version "3.4-SNAPSHOT" id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false id 'com.matthewprenger.cursegradle' version '1.4.0' } import com.diluv.schoomp.Webhook import com.diluv.schoomp.message.Message import com.diluv.schoomp.message.embed.Embed architectury { minecraft = rootProject.minecraft_version } subprojects { apply plugin: "dev.architectury.loom" loom { silentMojangMappingsLicense() } repositories { maven { url = 'https://maven.parchmentmc.org' } } dependencies { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" mappings loom.layered() { officialMojangMappings() parchment("org.parchmentmc.data:parchment-${rootProject.parchment_version}@zip") } } } allprojects { apply plugin: "java" apply plugin: "architectury-plugin" apply plugin: "maven-publish" archivesBaseName = rootProject.archives_base_name version = project.minecraft_version + "-" + rootProject.mod_version group = rootProject.maven_group tasks.withType(JavaCompile) { options.encoding = "UTF-8" options.release = 17 } java { withSourcesJar() } } task buildAll { dependsOn(":fabric:build") dependsOn(":forge:build") } task cleanAll { dependsOn clean dependsOn(":common:clean") dependsOn(":fabric:clean") dependsOn(":forge:clean") } task publishAll { dependsOn(":fabric:publish") dependsOn(":forge:publish") } def changelog(int versions) { try { def changelog = "" def match = 0 file("Changelog.md").eachLine { if (it.matches("${project.project_name} ([0-9].([0-9]*).([0-9]*))")) match++ if (match <= versions) { changelog += it + "\n" } else return } return changelog + "\n\n" } catch (exception) { return "${project.project_name} ${project.mod_version}\n==========\n" } } //Splits the changelog into multiple parts if they get bigger than discords embed field size (1024) def discordChangelog() { def changelog = changelog(1) def res = new ArrayList() if (changelog.size() < 1024) { res.add(changelog) return res; } def temp = "" changelog.split("\n").each { it = it + "\n" if ((temp.size() + it.size()) >= 1024) { res.add(temp) temp = it } else temp += it } res.add(temp) return res } curseforge { apiKey = findProperty('curseApiToken') ?: 0 project { id = "${curse_id_fabric}" "${project.curse_versions}".split(', ').each { addGameVersion "${it}" } addGameVersion "Fabric" mainArtifact(project(":fabric").tasks.getByName('remapJar')) { def txt = changelog(1).replace("\n-", "\n\n- ") txt = txt + "\n\n" + "For past versions see: ${project.full_changelog}" changelog = txt changelogType = "markdown" releaseType = 'release' } relations { "${project.curse_dep_fabric}".split(', ').each { requiredDependency "${it}" } } } project { id = "${curse_id_forge}" "${project.curse_versions}".split(', ').each { addGameVersion "${it}" } addGameVersion "Forge" mainArtifact(project(":forge").tasks.getByName('remapJar')) { def txt = changelog(1).replace("\n-", "\n\n- ") txt = txt + "\n\n" + "For past versions see: ${project.full_changelog}" changelog = txt changelogType = "markdown" releaseType = 'release' } /*relations { "${project.curse_dep_forge}".split(', ').each { requiredDependency "${it}" } }*/ } } tasks.getByName("curseforge").doLast { try { def fileIDFabric = tasks.getByName("curseforge${project.curse_id_fabric}").property('mainArtifact').fileID def fileIDForge = tasks.getByName("curseforge${project.curse_id_forge}").property('mainArtifact').fileID def webhook = new Webhook(findProperty('discordHook'), "${project.project_name} Upload") def message = new Message() def version = project.curse_versions.split(', ')[0] message.setUsername("Curseforge Release") message.setContent("<@&${project.discord_role}> ${project.project_name} ${project.mod_version} for Minecraft ${version} has been released!") message.setAvatarUrl("https://cdn.discordapp.com/avatars/680540027255652407/e4b7a058b24843ae13389a9a3cc3ae8c.png?size=128") def embed = new Embed() embed.addField('Get the fabric version here (When it is accepted)', "${project.findProperty('curse_page_fabric')}/files/${fileIDFabric}", false) embed.addField('Get the forge version here (When it is accepted)', "${project.findProperty('curse_page_forge')}/files/${fileIDForge}", false) def changelog = discordChangelog() if (changelog.size() == 1) embed.addField('Change Log', "```md\n${changelog.get(0) ?: 'Unavailable :('}```", false) else changelog.forEach { embed.addField("Change Log", "```md\n${it}```", false) } embed.setColor(0xFF8000) message.addEmbed(embed) webhook.sendMessage(message) } catch (IOException e) { println 'Failed to push to the Discord webhook.' } } task buildUploadAll(group: "publishing") { dependsOn cleanAll, buildAll, publishAll, tasks.getByName("curseforge") buildAll.mustRunAfter cleanAll tasks.findByName("curseforge").mustRunAfter publishAll } tasks.getByName("curseforge").dependsOn buildAll publishAll.dependsOn buildAll