plugins {
    id 'java'
    id 'io.github.goooler.shadow' version "8.1.7"
    id 'maven-publish'
    id "com.modrinth.minotaur" version "2.8.7"
}

group = 'dev.unnm3d'
version = '2.1.2'

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
    maven { url = "https://repo.papermc.io/repository/maven-public/" }
    maven {
        name = "sonatype"
        url = "https://oss.sonatype.org/content/groups/public/"
    }
    maven { url = "https://repo.codemc.io/repository/maven-public/" }
    maven { url 'https://repo.xenondevs.xyz/releases' }
    maven { url 'https://maven.enginehub.org/repo/' }
    maven { url 'https://repo.rosewooddev.io/repository/public/' }
    maven { url 'https://repo.opencollab.dev/main/' }
}

dependencies {
    compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT"
    compileOnly 'com.zaxxer:HikariCP:5.1.0'
    compileOnly 'org.postgresql:postgresql:42.7.5'
    compileOnly 'org.projectlombok:lombok:1.18.34'
    compileOnly 'io.lettuce:lettuce-core:6.5.5.RELEASE'
    compileOnly "com.github.MilkBowl:VaultAPI:1.7.1"
    compileOnly "com.github.Emibergo02:RedisEconomy:4.3.19"
    compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.9-SNAPSHOT'
    compileOnly 'org.black_ixx:playerpoints:3.3.0'
    compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'

    implementation 'de.exlll:configlib-paper:4.6.1' exclude group: 'org.snakeyaml', module: 'snakeyaml-engine'
    implementation 'com.github.alexdev03:drink:1.5.3'
    implementation 'com.github.Anon8281:UniversalScheduler:0.1.7'
    implementation 'xyz.xenondevs.invui:invui-core:1.46'
    implementation 'xyz.xenondevs.invui:inventory-access-r19:1.46'
    implementation 'xyz.xenondevs.invui:inventory-access-r20:1.46'
    implementation 'xyz.xenondevs.invui:inventory-access-r21:1.46'
    implementation 'xyz.xenondevs.invui:inventory-access-r22:1.46'
    implementation 'xyz.xenondevs.invui:inventory-access-r23:1.46'
    implementation 'xyz.xenondevs.invui:inventory-access-r24:1.46'

    annotationProcessor 'org.projectlombok:lombok:1.18.34'

    testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
    testImplementation(platform("org.junit:junit-bom:5.10.2"))
    testImplementation 'io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT'
    testImplementation 'org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.21.0'
    testImplementation 'com.zaxxer:HikariCP:5.1.0'
    testImplementation 'org.xerial:sqlite-jdbc:3.46.0.0'
    testImplementation 'xyz.xenondevs.invui:invui:1.44'
    testImplementation 'org.projectlombok:lombok:1.18.34'
    testImplementation 'io.lettuce:lettuce-core:6.5.2.RELEASE'
    testImplementation "com.github.MilkBowl:VaultAPI:1.7.1"
    testImplementation "com.github.Emibergo02:RedisEconomy:4.3.19"
    testImplementation 'com.github.alexdev03:drink:1.5.3'
    testImplementation 'org.awaitility:awaitility:4.2.2'

}

test {
    useJUnitPlatform()
}

shadowJar {
    destinationDirectory.set(file("$rootDir/target"))
    archiveClassifier.set('')

    relocate 'de.exlll.configlib', 'dev.unnm3d.redistrade.libraries.configlib'
    relocate 'dev.jorel.commandapi', 'dev.unnm3d.redistrade.libraries.commandapi'
    relocate 'com.jonahseguin.drink', 'dev.unnm3d.redistrade.libraries.drink'
    relocate 'xyz.xenondevs.invui', 'dev.unnm3d.redistrade.libraries.invui'
    relocate 'xyz.xenondevs.inventoryaccess', 'dev.unnm3d.redistrade.libraries.inventoryaccess'
    relocate 'com.github.Anon8281.universalScheduler', 'dev.unnm3d.redistrade.libraries.universalScheduler'

    exclude 'colors.bin'
}

def targetJavaVersion = 21
java {
    def javaVersion = JavaVersion.toVersion(targetJavaVersion)
    sourceCompatibility = javaVersion
    targetCompatibility = javaVersion
    if (JavaVersion.current() < javaVersion) {
        toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
    }
}

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'

    if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
        options.release.set(targetJavaVersion)
    }
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = 'dev.unnm3d'
            artifactId = 'redistrade'
            version = "$version"
            artifact shadowJar
        }
    }
}

modrinth {
    token = System.getenv("MODRINTH_TOKEN") // Remember to have the MODRINTH_TOKEN environment variable set or else this will fail - just make sure it stays private!
    projectId = "redistrade" // This can be the project ID or the slug. Either will work!
    versionType = "release" // This is the default -- can also be `beta` or `alpha`
    uploadFile = shadowJar // With Loom, this MUST be set to `remapJar` instead of `jar`!
    gameVersions = ["1.21.9","1.21.8","1.21.7","1.21.6","1.21.5","1.21.4", "1.21.3","1.21.1","1.21.2","1.20.6"] // Must be an array, even with only one version
    loaders = ["paper","spigot","bukkit"] // Must also be an array - no need to specify this if you're using Loom or ForgeGradle
}

processResources {
    def props = [version: version]
    inputs.properties props
    filteringCharset 'UTF-8'
    filesMatching('plugin.yml') {
        expand props
    }
    filesMatching('source') {
        expand props
    }
}
