plugins {
    id 'java'
    id 'com.github.johnrengelman.shadow' version '8.1.1'
}

group = 'ru.Fronzter'
version = '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    maven {
        name = "papermc-repo"
        url = "https://repo.papermc.io/repository/maven-public/"
    }
    maven {
        name = "sonatype"
        url = "https://oss.sonatype.org/content/groups/public/"
    }
    maven {
        name = "codemc-public"
        url = "https://repo.codemc.io/repository/maven-public/"
    }
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compileOnly "com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT"

    implementation "com.github.retrooper:packetevents-spigot:2.7.0"
    implementation "com.squareup.moshi:moshi:1.15.0"
    implementation "com.squareup.moshi:moshi-adapters:1.15.0"
    implementation "com.squareup.okhttp3:okhttp:4.12.0"
    implementation "org.ejml:ejml-core:0.41"
    implementation "org.ejml:ejml-ddense:0.41"
    implementation "org.ejml:ejml-simple:0.41"
    implementation "com.zaxxer:HikariCP:5.1.0"
    compileOnly("org.projectlombok:lombok:1.18.38")
    annotationProcessor("org.projectlombok:lombok:1.18.38")
}



def targetJavaVersion = 8
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)
    }
}

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

tasks.named('shadowJar') {
    archiveClassifier.set('all')

    relocate 'com.github.retrooper.packetevents', 'ru.Fronzter.shadow.packetevents'
    relocate 'com.squareup.moshi', 'ru.Fronzter.shadow.moshi'
    relocate 'okhttp3', 'ru.Fronzter.shadow.okhttp'
    relocate 'org.ejml', 'ru.Fronzter.shadow.ejml'

    minimize()
}

tasks.build {
    dependsOn tasks.shadowJar
}