plugins {
    `java-library`
    id("com.gradleup.shadow") version "8.3.6"
}

group = "fr.luc"
version = "1.0.0-SNAPSHOT"

repositories {
    mavenLocal()
    mavenCentral()
    maven("https://repo.papermc.io/repository/maven-public/")
    maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
    maven("https://oss.sonatype.org/content/groups/public/")
    maven("https://maven.enginehub.org/repo/")
    maven("https://jitpack.io")
}

dependencies {
    // Paper API (1.20.4)
    compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")

    // WorldGuard & WorldEdit APIs
    compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.9")
    compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.3.0")

    // Vault API (Economy & Permissions)
    compileOnly("com.github.MilkBowl:VaultAPI:1.7.1")

    // betterMcCommands - Framework de commandes dynamique
    implementation("fr.luc:betterMcCommands:1.0.0-SNAPSHOT")

    // Adventure platform for Bukkit (cross-version RGB, MiniMessage, Titles, ActionBars)
    implementation("net.kyori:adventure-platform-bukkit:4.3.4")
    implementation("net.kyori:adventure-text-minimessage:4.17.0")

    // XSeries for cross-version Materials, Sounds, Titles, Particles (1.16 - 1.21+)
    implementation("com.github.cryptomorin:XSeries:13.0.0")

    testImplementation(platform("org.junit:junit-bom:6.0.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<JavaCompile> {
    options.encoding = "UTF-8"
    options.release.set(17)
}

tasks.shadowJar {
    archiveClassifier.set("")
    
    // Relocate shaded libraries to avoid collisions with other plugins
    relocate("com.cryptomorin.xseries", "fr.luc.gamingcore.libs.xseries")
    relocate("net.kyori.adventure.platform.bukkit", "fr.luc.gamingcore.libs.adventure.platform")
    relocate("fr.luc.bettermccommands", "fr.luc.gamingcore.libs.bettermccommands")
}

tasks.processResources {
    val props = mapOf(
        "name" to project.rootProject.name,
        "version" to project.version,
        "description" to "Core Gaming Minecraft Plugin",
        "apiVersion" to "1.16"
    )
    inputs.properties(props)
    filesMatching("plugin.yml") {
        expand(props)
    }
}

tasks.build {
    dependsOn(tasks.shadowJar)
}