plugins {
    id "com.github.johnrengelman.shadow"
}
repositories {
    maven { url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
    maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url = "https://jitpack.io" }
    maven { url = "https://repo.codemc.org/repository/maven-public" }
    maven { url = "http://repo.extendedclip.com/content/repositories/placeholderapi/" }
    maven {
        name = "papermc"
        url = "https://papermc.io/repo/repository/maven-public/"
    }
    maven { url = "https://ci.ender.zone/plugin/repository/everything/" }
    maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
    maven { url = "https://repo.wea-ondara.net/repository/public/" }
    mavenLocal()
}


dependencies {
    implementation(project(":PlotSquared-Core"))
    compile("org.bstats:bstats-bukkit:1.7")
    compile(project(":PlotSquared-Core"))
    compile("com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT")
    //implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT'
    implementation("org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT")
    compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.0.1")
    compile("io.papermc:paperlib:1.0.2")
    implementation("net.kyori:text-adapter-bukkit:3.0.3")
    compile("com.github.MilkBowl:VaultAPI:1.7") {
        exclude(module: "bukkit")
    }
    implementation("me.clip:placeholderapi:2.10.6")
    implementation("net.luckperms:api:5.1")
    implementation("net.ess3:EssentialsX:2.17.2")
    implementation("net.alpenblock:BungeePerms:4.0-dev-106")
    compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false }
    compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false }
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

processResources {
    from("src/main/resources") {
        include("plugin.yml")
        expand(
                name: project.parent.name,
                version: project.parent.version
        )
    }
}

//noinspection GroovyAssignabilityCheck
jar.archiveFileName = "PlotSquared-Bukkit-${project.parent.version}.jar"
jar.destinationDirectory = file("../mvn/com/plotsquared/PlotSquared-Bukkit/" + project.parent.version)
task createPom {
    doLast {
        pom {
            project {
                groupId = rootProject.group
                artifactId = "PlotSquared-Bukkit"
                version = rootProject.version
            }
        }.writeTo("../mvn/com/plotsquared/PlotSquared-Bukkit/${project.parent.version}/PlotSquared-Bukkit-${project.parent.version}.pom")
        pom {
            project {
                groupId = rootProject.group
                artifactId = "PlotSquared-Bukkit"
                version = "latest"
            }
        }.writeTo("../mvn/com/plotsquared/PlotSquared-Bukkit/latest/PlotSquared-Bukkit-latest.pom")
         .writeTo("pom.xml")
    }
}

task copyFiles {
    doLast {
        copy {
            from("../mvn/com/plotsquared/PlotSquared-Bukkit/${project.parent.version}/")
            into("../mvn/com/plotsquared/PlotSquared-Bukkit/latest/")
            include("PlotSquared-Bukkit*.jar")
            rename("PlotSquared-Bukkit-${project.parent.version}.jar", "PlotSquared-Bukkit-latest.jar")
        }
    }
}


shadowJar {
    dependencies {
        include(dependency(":PlotSquared-Core"))
        include(dependency("io.papermc:paperlib:1.0.2"))
        include(dependency("net.kyori:text-adapter-bukkit:3.0.3"))
        include(dependency("org.bstats:bstats-bukkit:1.7"))
        include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT"))
        include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT"))
    }
    relocate('net.kyori.text', 'com.plotsquared.formatting.text')
    relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib")
    relocate("org.bstats", "com.plotsquared.metrics")
    relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid')
    relocate('org.khelekore.prtree', 'com.plotsquared.prtree')
    archiveFileName = "${project.name}-${parent.version}.jar"
    destinationDirectory = file "../target"
}

shadowJar.doLast {
    task ->
        ant.checksum file: task.archivePath
}

build.dependsOn(shadowJar)
build.finalizedBy(copyFiles)
copyFiles.dependsOn(createPom)
