/*
 * Iris is a World Generator for Minecraft Bukkit Servers
 * Copyright (c) 2021 Arcane Arts (Volmit Software)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.guardsquare:proguard-gradle:7.1.0'
    }
}

plugins {
    id 'java'
    id 'io.freefair.lombok' version '5.2.1'
    id "com.github.johnrengelman.shadow" version "7.0.0"
}

group 'com.volmit.iris'
version '1.7'
def apiVersion = '1.17'
def name = getRootProject().getName() // See settings.gradle
def main = 'com.volmit.iris.Iris'
// You need to also set command usage, aliases and description in src/main/resources/plugin.yml

// ADD YOURSELF AS A NEW LINE IF YOU WANT YOUR OWN BUILD TASK GENERATED
// ==============================================================
registerCustomOutputTask('Cyberpwn', 'C://Users/cyberpwn/Documents/development/server/plugins', name)
registerCustomOutputTask('Psycho', 'D://Dan/MinecraftDevelopment/server/plugins', name)
registerCustomOutputTask('ArcaneArts', 'C://Users/arcane/Documents/development/server/plugins', name)
registerCustomOutputTask('Coco', 'C:/Users/sjoer/Documents/Development/MCServer/plugins', name)
registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins', name)
// ==============================================================

def dependsDir = "${buildDir}/libs/dependencies/" as String

task copyDepends(type: Copy) {
    dependsOn(":shadowJar")
    group('proguard')
    from configurations.default
    into "${dependsDir}"
}

task release(type: proguard.gradle.ProGuardTask) {
    dependsOn(":copyDepends")
    group('proguard')
    configuration 'proguard.pro'
    injars("${buildDir}/libs/" + name + "-" + version + "-all.jar")
    outjars("${buildDir}/production/" + name + "/" + version + "/" + name + "-" + version + ".jar")
    libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
    libraryjars "${System.getProperty('java.home')}/jmods/"
    libraryjars "${dependsDir}"
    dontobfuscate()
    dontwarn()
    dontshrink()
    dontoptimize()
    dontnote()
    verbose()
}

def registerCustomOutputTask(name, path, plugin) {
    tasks.register('build' + name, Copy) {
        group('development')
        outputs.upToDateWhen { false }
        dependsOn ':shadowJar'
        from(file('build/libs/' + plugin + '-' + version + '-all.jar'))
        into(file(path))
        rename { String fileName ->
            fileName.replace(plugin + '-' + version + '-all.jar', plugin + ".jar")
        }
    }
}

file(jar.archiveFile.get().getAsFile().getParentFile().getParentFile().getParentFile().getAbsolutePath() + '/build/resources/main/plugin.yml').delete()

processResources {
    filesMatching('**/plugin.yml') {
        expand(
            'name': name.toString(),
            'version': version.toString(),
            'main': main.toString(),
            'apiversion': apiVersion.toString()
        )
    }
}

repositories {
    maven {
        allowInsecureProtocol true
        url "http://archive.arcane.art/repository/arcane"
    }
    mavenLocal()
    maven {
        url 'https://repo.maven.apache.org/maven2'
    }
}

shadowJar
{
    minimize()
    append("plugin.yml")
    relocate 'com.dfsek.paralithic', 'com.volmit.iris.util.paralithic'
    relocate 'io.papermc.lib', 'com.volmit.iris.util.paper'
    dependencies {
        include(dependency('io.papermc:paperlib'))
        include(dependency('com.dfsek:Paralithic'))
        include(dependency('net.kyori:'))
    }
}

dependencies {
    // Provided or Classpath
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'
    implementation 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
    implementation 'org.bukkit.craftbukkit:1.17.1:1.17.1'
    implementation 'me.clip:placeholderapi:2.10.10'
    implementation 'io.th0rgal:oraxen:1.94.0'

    // Shaded
    implementation 'com.dfsek:Paralithic:0.4.0'
    implementation 'io.papermc:paperlib:1.0.5'
    implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT"
    implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT"
    implementation 'net.kyori:adventure-api:4.8.1'

    // Dynamically Loaded
    implementation 'it.unimi.dsi:fastutil:8.5.4'
    implementation 'com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2'
    implementation 'org.zeroturnaround:zt-zip:1.14'
    implementation 'com.google.code.gson:gson:2.8.7'
    implementation 'org.ow2.asm:asm:9.2'
    implementation 'com.google.guava:guava:30.1.1-jre'
    implementation 'bsf:bsf:2.4.0'
    implementation 'rhino:js:1.7R2'
}
