plugins {
    id 'java'
    id 'eclipse'
    id "org.jetbrains.gradle.plugin.idea-ext" version "1.0.1"
    id("xyz.jpenilla.run-velocity") version "2.3.1"
}

group = properties.get('plugin_group')
version = properties.get('plugin_version')
def plugin_name = properties.get('plugin_name')
def plugin_id = properties.get('plugin_id')

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        name = 'papermc-repo'
        url = 'https://repo.papermc.io/repository/maven-public/'
    }
    maven { url 'https://repo.william278.net/releases/' }
}

tasks {
    runVelocity {
        // Configure the Velocity version for our task.
        // This is the only required configuration besides applying the plugin.
        // Your plugin's jar (or shadowJar if present) will be used automatically.
        velocityVersion("4.0.0-SNAPSHOT")
    }
}

dependencies {
    compileOnly 'com.velocitypowered:velocity-api:4.0.0-SNAPSHOT' //2026-7-14 检查更新
    annotationProcessor 'com.velocitypowered:velocity-api:4.0.0-SNAPSHOT' //2026-7-14 检查更新
    compileOnly 'com.electronwill.night-config:toml:3.9.0' //2026-7-14 检查更新
    annotationProcessor 'org.projectlombok:lombok:1.18.46' //2026-7-14 检查更新
    compileOnly 'org.projectlombok:lombok:1.18.46' //2026-7-14 检查更新
    implementation 'net.william278:papiproxybridge:1.6'
}

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

tasks.withType(JavaCompile).configureEach {
    if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
        options.release = targetJavaVersion
    }
    options.encoding = 'UTF-8'
}

// 打包时包含依赖
jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    exclude()
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

def templateSource = file('src/main/templates')
def templateDest = layout.buildDirectory.dir('generated/sources/templates')
def generateTemplates = tasks.register('generateTemplates', Copy) { task ->
    def props = [
            'version': project.version,
            'plugin_id': plugin_id,
            'plugin_name': plugin_name
    ]
    task.inputs.properties props

    task.from templateSource
    task.into templateDest
    task.expand props
}

sourceSets.main.java.srcDir(generateTemplates.map { it.outputs })

rootProject.idea.project.settings.taskTriggers.afterSync generateTemplates
project.eclipse.synchronizationTasks(generateTemplates)
