diff --git a/.gitignore b/.gitignore index 9101ae8..f8c8b9c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ modules/api-local/build modules/api-remote/build modules/dto/build # instances -instances/fabric -instances/forge -instances/plugin -instances/velocity \ No newline at end of file +instances/fabric/build +instances/forge/build +instances/plugin/build +instances/velocity/build \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index ceff010..af240c1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,9 +4,7 @@ plugins { `java-library` alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.kotlin.serialization) apply false - alias(libs.plugins.minecraft.fabric.loom) apply false alias(libs.plugins.gradle.buildconfig) apply false - alias(libs.plugins.gradle.shadow) apply false // klibs - core alias(libs.plugins.klibs.gradle.detekt) apply false @@ -16,7 +14,6 @@ plugins { alias(libs.plugins.klibs.gradle.java.core) apply false alias(libs.plugins.klibs.gradle.publication) apply false alias(libs.plugins.klibs.gradle.rootinfo) apply false - alias(libs.plugins.klibs.minecraft.shadow) apply false alias(libs.plugins.klibs.minecraft.resource.processor) apply false } diff --git a/gradle.properties b/gradle.properties index 864fe15..69d7f29 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ makeevrserg.java.ktarget=21 # Project makeevrserg.project.name=AstraTemplate makeevrserg.project.group=ru.astrainteractive.astratemplate -makeevrserg.project.version.string=7.8.0 +makeevrserg.project.version.string=8.0.0-alpha01 makeevrserg.project.description=Template plugin for EmpireProjekt makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com makeevrserg.project.url=https://github.com/Astra-Interactive/AstraTemplate diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d589bb3..89079a8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,145 +1,163 @@ [versions] -# Kotlin -kotlin-version = "2.2.0" # https://github.com/JetBrains/kotlin -kotlin-coroutines = "1.10.2" # https://github.com/Kotlin/kotlinx.coroutines -kotlin-json = "1.9.0" # https://github.com/Kotlin/kotlinx.serialization -kotlin-kaml = "0.92.0" # https://github.com/charleskorn/kaml - -# Drivers -driver-jdbc = "3.50.3.0" # https://github.com/xerial/sqlite-jdbc -driver-mysql = "8.0.33" # https://github.com/mysql/mysql-connector-j - -# Minecraft -minecraft-version = "1.21" -minecraft-velocity = "3.4.0-SNAPSHOT" # https://github.com/PaperMC/Velocity -minecraft-spigot = "1.21.4-R0.1-SNAPSHOT" # https://github.com/PaperMC/Paper -minecraft-papi = "2.11.6" # https://github.com/PlaceholderAPI/PlaceholderAPI -minecraft-protocollib = "5.3.0" -minecraft-wg = "7.0.7" -minecraft-vault = "1.7.1" # https://github.com/MilkBowl/VaultAPI -minecraft-coreprotect = "21.2" -minecraft-astralibs = "3.25.1" # https://github.com/Astra-Interactive/AstraLibs +cache4k = "0.14.0" +discordsrv = "1.30.2" +driver-h2 = "2.4.240" +driver-jdbc = "3.50.3.0" +driver-mariadb = "3.5.6" +driver-mysql = "8.0.33" +exposed = "0.61.0" +forgegradle = "[6.0,6.2)" +gradle-buildconfig = "5.7.0" +gradle-ftp = "0.1.2" +gradle-shadow = "9.2.2" +gson = "2.13.2" +guava = "33.5.0-jre" +jda = "6.1.0" +jda-webhook = "0.8.4" +klibs-gradleplugin = "1.11.1" +klibs-kdi = "1.4.8" +klibs-kstorage = "4.4.1" +klibs-mikro = "1.16.0" +kotlin-benchmark = "0.4.14" +kotlin-coroutines = "1.10.2" +kotlin-datetime = "0.7.1-0.6.x-compat" +kotlin-json = "1.9.0" +kotlin-serialization-kaml = "0.102.0" +kotlin-serialization = "1.9.0" +kotlin-version = "2.2.0" +ktor = "3.3.1" +kyori = "4.25.0" +kyori-adventure = "4.25.0" +mcprotocollib = "1.21.7-SNAPSHOT" +minecraft-astralibs = "3.29.0" minecraft-bstats = "3.1.0" +minecraft-bungee = "1.21-R0.5-SNAPSHOT" +minecraft-essentialsx = "2.21.2" +minecraft-fabric-api = "0.134.1+" +minecraft-fabric-yarn = "1.20.1+build.10" +minecraft-fabric-kotlin = "1.13.1+" +minecraft-fabric-loader = "0.17.2" +minecraft-fabric-loom = "1.11.8" +minecraft-luckperms = "5.5" minecraft-mockbukkit = "4.33.2" - -# Testing +minecraft-mojang-version = "1.20.1" +minecraft-packetevents = "2.10.0" +minecraft-papi = "2.11.6" +minecraft-protocollib = "5.3.0" +minecraft-spigot = "1.21.9-R0.1-SNAPSHOT" +minecraft-towny = "0.101.2.1" +minecraft-vault = "1.7.1" +minecraft-velocity = "3.4.0-SNAPSHOT" # https://github.com/PaperMC/Velocity +minecraft-forgeversion = "47.2.20" +shadow = "8.1.8" +telegrambots = "9.2.0" +tests-junit-bom = "6.0.1" +tests-junit-jupiter-api = "6.0.1" +tests-mockito = "5.20.0" tests-org-testing = "7.11.0" -tests-junit = "4.12" -tests-mockito = "4.0.0" -tests-junit-jupiter-api = "5.13.4" -tests-junit-bom = "5.13.4" - -# Fabric -minecraft-fabric-loom = "1.10.1" -minecraft-fabric-kotlin = "1.13.1+" -minecraft-fabric-loader = "0.16.10" -minecraft-fabric-api = "0.116.0+" -minecraft-fabric-yarn = "1.21+build.2" - -# Shadow -gradle-shadow = "9.0.0-beta12" # https://github.com/johnrengelman/shadow - -# BuildConfig -gradle-buildconfig = "5.6.7" - -# Exposed -exposed = "0.61.0" - -# klibs -klibs-gradleplugin = "1.10.0" # https://github.com/makeevrserg/gradle-plugin -klibs-kstorage = "4.2.2" # https://github.com/makeevrserg/klibs.kstorage -klibs-mikro = "1.12.0" # https://github.com/makeevrserg/klibs.mikro - -[bundles] -exposed = ["exposed-java-time", "exposed-jdbc", "exposed-dao", "exposed-core"] -minecraft-bukkit = ["minecraft-paper-api", "minecraft-spigot-api", "minecraft-spigot-core", "minecraft-vaultapi", "minecraft-papi"] -testing-kotlin = ["kotlin-coroutines-core", "kotlin-coroutines-coreJvm", "driver-jdbc", "driver-mysql", "kotlin-serialization", "kotlin-serializationJson"] -kotlin = ["kotlin-coroutines-core", "kotlin-coroutines-coreJvm", "kotlin-serialization", "kotlin-serializationJson", "kotlin-serializationKaml", "kotlin-tooling-core"] +turbine = "1.2.1" [libraries] - -# Kotlin -kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" } -kotlin-coroutines-coreJvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "kotlin-coroutines" } -kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin-version" } -kotlin-serializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlin-json" } -kotlin-serializationKaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kotlin-kaml" } -kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-version" } -kotlin-tooling-core = { module = "org.jetbrains.kotlin:kotlin-tooling-core", version.ref = "kotlin-version" } - -# Testing -tests-kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" } - -# Shadow -gradle-shadow = { module = "gradle.plugin.com.github.johnrengelman:shadow", version.ref = "gradle-shadow" } - -# Drivers +minecraft-astralibs-core = { module = "ru.astrainteractive.astralibs:core", version.ref = "minecraft-astralibs" } +cache4k = { module = "io.github.reactivecircus.cache4k:cache4k-jvm", version.ref = "cache4k" } +discord-webhook = { module = "club.minnced:discord-webhooks", version.ref = "jda-webhook" } +driver-h2 = { module = "com.h2database:h2", version.ref = "driver-h2" } driver-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "driver-jdbc" } +driver-mariadb = { module = "org.mariadb.jdbc:mariadb-java-client", version.ref = "driver-mariadb" } driver-mysql = { module = "mysql:mysql-connector-java", version.ref = "driver-mysql" } - -# Testing -tests-junit-bom = { module = "org.junit:junit-bom", version.ref = "tests-junit-bom" } -tests-junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "tests-junit-jupiter-api" } -tests-org-testing = { module = "org.testng:testng", version.ref = "tests-org-testing" } -tests-junit5 = { module = "org.jetbrains.kotlin:kotlin-test-junit5" } -tests-junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" } - -# Exposed +exposed-core = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" } +exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exposed" } exposed-java-time = { module = "org.jetbrains.exposed:exposed-java-time", version.ref = "exposed" } exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" } -exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exposed" } -exposed-core = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" } - -# Minecraft -minecraft-paper-api = { module = "io.papermc.paper:paper-api", version.ref = "minecraft-spigot" } -minecraft-spigot-api = { module = "org.spigotmc:spigot-api", version.ref = "minecraft-spigot" } -minecraft-spigot-core = { module = "org.spigotmc:spigot", version.ref = "minecraft-spigot" } -minecraft-velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "minecraft-velocity" } -minecraft-protocollib = { module = "com.comphenix.protocol:ProtocolLib", version.ref = "minecraft-protocollib" } -minecraft-papi = { module = "me.clip:placeholderapi", version.ref = "minecraft-papi" } -minecraft-vaultapi = { module = "com.github.MilkBowl:VaultAPI", version.ref = "minecraft-vault" } -minecraft-bstats = { module = "org.bstats:bstats-bukkit", version.ref = "minecraft-bstats" } -minecraft-mockbukkit = { module = "com.github.MockBukkit:MockBukkit", version.ref = "minecraft-mockbukkit" } - -# AstraLibs -minecraft-astralibs-exposed = { module = "ru.astrainteractive.astralibs:exposed", version.ref = "minecraft-astralibs" } -minecraft-astralibs-core = { module = "ru.astrainteractive.astralibs:core", version.ref = "minecraft-astralibs" } -minecraft-astralibs-menu-bukkit = { module = "ru.astrainteractive.astralibs:menu-bukkit", version.ref = "minecraft-astralibs" } -minecraft-astralibs-core-bukkit = { module = "ru.astrainteractive.astralibs:core-bukkit", version.ref = "minecraft-astralibs" } +gradle-shadow = { module = "gradle.plugin.com.github.johnrengelman:shadow", version.ref = "gradle-shadow" } +gson = { module = "com.google.code.gson:gson", version.ref = "gson" } +guava = { module = "com.google.guava:guava", version.ref = "guava" } +jda = { module = "net.dv8tion:JDA", version.ref = "jda" } +klibs-kdi = { module = "ru.astrainteractive.klibs:kdi-jvm", version.ref = "klibs-kdi" } +klibs-kstorage = { module = "ru.astrainteractive.klibs:kstorage", version.ref = "klibs-kstorage" } +klibs-mikro-core = { module = "ru.astrainteractive.klibs:mikro-core", version.ref = "klibs-mikro" } +klibs-mikro-extensions = { module = "ru.astrainteractive.klibs:mikro-extensions", version.ref = "klibs-mikro" } +kotlin-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlin-benchmark" } +kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" } +kotlin-coroutines-coreJvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "kotlin-coroutines" } +kotlin-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlin-coroutines" } +kotlin-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime-jvm", version.ref = "kotlin-datetime" } +kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-version" } +kotlin-serialization-kaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kotlin-serialization-kaml" } +kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin-version" } +kotlin-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlin-serialization" } +kotlin-serialization-protobuf = { module = "org.jetbrains.kotlinx:kotlinx-serialization-protobuf", version.ref = "kotlin-json" } +kotlin-tooling-core = { module = "org.jetbrains.kotlin:kotlin-tooling-core", version.ref = "kotlin-version" } +ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" } +ktor-client-contentNegitiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" } +ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } +ktor-client-json = { module = "io.ktor:ktor-client-json", version.ref = "ktor" } +ktor-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" } +ktor-serialization-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } +kyori-plain = { module = "net.kyori:adventure-text-serializer-plain", version.ref = "kyori-adventure" } +kyori-api = { module = "net.kyori:adventure-api", version.ref = "kyori" } +kyori-gson = { module = "net.kyori:adventure-text-serializer-gson", version.ref = "kyori" } +kyori-legacy = { module = "net.kyori:adventure-text-serializer-legacy", version.ref = "kyori" } +kyori-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "kyori" } +mcprotocollib = { module = "org.geysermc.mcprotocollib:protocol", version.ref = "mcprotocollib" } minecraft-astralibs-command = { module = "ru.astrainteractive.astralibs:command", version.ref = "minecraft-astralibs" } minecraft-astralibs-command-bukkit = { module = "ru.astrainteractive.astralibs:command-bukkit", version.ref = "minecraft-astralibs" } - -# Fabric +minecraft-astralibs-core-bukkit = { module = "ru.astrainteractive.astralibs:core-bukkit", version.ref = "minecraft-astralibs" } +minecraft-astralibs-core-forge = { module = "ru.astrainteractive.astralibs:core-forge", version.ref = "minecraft-astralibs" } +minecraft-astralibs-exposed = { module = "ru.astrainteractive.astralibs:exposed", version.ref = "minecraft-astralibs" } +minecraft-astralibs-menu-bukkit = { module = "ru.astrainteractive.astralibs:menu-bukkit", version.ref = "minecraft-astralibs" } +minecraft-astralibs-orm = { module = "ru.astrainteractive.astralibs:orm", version.ref = "minecraft-astralibs" } +minecraft-bstats = { module = "org.bstats:bstats-bukkit", version.ref = "minecraft-bstats" } +minecraft-bungee = { module = "net.md-5:bungeecord-api", version.ref = "minecraft-bungee" } +minecraft-discordsrv = { module = "com.discordsrv:discordsrv", version.ref = "discordsrv" } +minecraft-essentialsx = { module = "net.essentialsx:EssentialsX", version.ref = "minecraft-essentialsx" } +minecraft-fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "minecraft-fabric-api" } minecraft-fabric-kotlin = { module = "net.fabricmc:fabric-language-kotlin", version.ref = "minecraft-fabric-kotlin" } minecraft-fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "minecraft-fabric-loader" } -minecraft-fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "minecraft-fabric-api" } -minecraft-mojang = { module = "com.mojang:minecraft", version.ref = "minecraft-version" } - -# klibs -klibs-mikro-core = { module = "ru.astrainteractive.klibs:mikro-core", version.ref = "klibs-mikro" } -klibs-kstorage = { module = "ru.astrainteractive.klibs:kstorage", version.ref = "klibs-kstorage" } +minecraft-fabric-mojang = { module = "com.mojang:minecraft", version.ref = "minecraft-mojang-version" } +minecraft-luckperms = { module = "net.luckperms:api", version.ref = "minecraft-luckperms" } +minecraft-mockbukkit = { module = "com.github.MockBukkit:MockBukkit", version.ref = "minecraft-mockbukkit" } +minecraft-packetevents = { module = "com.github.retrooper:packetevents-spigot", version.ref = "minecraft-packetevents" } +minecraft-paper-api = { module = "io.papermc.paper:paper-api", version.ref = "minecraft-spigot" } +minecraft-papi = { module = "me.clip:placeholderapi", version.ref = "minecraft-papi" } +minecraft-protocollib = { module = "com.comphenix.protocol:ProtocolLib", version.ref = "minecraft-protocollib" } +minecraft-spigot-api = { module = "org.spigotmc:spigot-api", version.ref = "minecraft-spigot" } +minecraft-spigot-core = { module = "org.spigotmc:spigot", version.ref = "minecraft-spigot" } +minecraft-towny = { module = "com.palmergames.bukkit.towny:towny", version.ref = "minecraft-towny" } +minecraft-vaultapi = { module = "com.github.MilkBowl:VaultAPI", version.ref = "minecraft-vault" } +minecraft-velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "minecraft-velocity" } +telegrambots-client = { module = "org.telegram:telegrambots-client", version.ref = "telegrambots" } +telegrambots-extensions = { module = "org.telegram:telegrambots-extensions", version.ref = "telegrambots" } +telegrambots-longpolling = { module = "org.telegram:telegrambots-longpolling", version.ref = "telegrambots" } +tests-junit-bom = { module = "org.junit:junit-bom", version.ref = "tests-junit-bom" } +tests-junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" } +tests-junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "tests-junit-jupiter-api" } +tests-junit5 = { module = "org.jetbrains.kotlin:kotlin-test-junit5" } +tests-kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" } +tests-mockito = { module = "org.mockito:mockito-core", version.ref = "tests-mockito" } +tests-org-testing = { module = "org.testng:testng", version.ref = "tests-org-testing" } +turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" } [plugins] -# Kotlin -kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-version" } -kotlin-gradle = { id = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-version" } -kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-version" } - -# Minecraft -minecraft-fabric-loom = { id = "fabric-loom", version.ref = "minecraft-fabric-loom" } - -# Gradle -gradle-shadow = { id = "com.gradleup.shadow", version.ref = "gradle-shadow" } +fabric-loom = { id = "fabric-loom", version.ref = "minecraft-fabric-loom" } +forgegradle = { id = "net.minecraftforge.gradle", version.ref = "forgegradle" } gradle-buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "gradle-buildconfig" } - -# klibs - core +gradle-ftp = { id = "ru.astrainteractive.ftpplugin.gradleftp", version.ref = "gradle-ftp" } +gradle-shadow = { id = "com.gradleup.shadow", version.ref = "gradle-shadow" } klibs-gradle-detekt = { id = "ru.astrainteractive.gradleplugin.detekt", version.ref = "klibs-gradleplugin" } klibs-gradle-detekt-compose = { id = "ru.astrainteractive.gradleplugin.detekt.compose", version.ref = "klibs-gradleplugin" } -klibs-gradle-dokka-root = { id = "ru.astrainteractive.gradleplugin.dokka.root", version.ref = "klibs-gradleplugin" } klibs-gradle-dokka-module = { id = "ru.astrainteractive.gradleplugin.dokka.module", version.ref = "klibs-gradleplugin" } +klibs-gradle-dokka-root = { id = "ru.astrainteractive.gradleplugin.dokka.root", version.ref = "klibs-gradleplugin" } klibs-gradle-java-core = { id = "ru.astrainteractive.gradleplugin.java.core", version.ref = "klibs-gradleplugin" } -klibs-gradle-stub-javadoc = { id = "ru.astrainteractive.gradleplugin.stub.javadoc", version.ref = "klibs-gradleplugin" } +klibs-gradle-minecraft-empty = { id = "ru.astrainteractive.gradleplugin.minecraft.empty", version.ref = "klibs-gradleplugin" } +klibs-gradle-minecraft-multiplatform = { id = "ru.astrainteractive.gradleplugin.minecraft.multiplatform", version.ref = "klibs-gradleplugin" } klibs-gradle-publication = { id = "ru.astrainteractive.gradleplugin.publication", version.ref = "klibs-gradleplugin" } klibs-gradle-rootinfo = { id = "ru.astrainteractive.gradleplugin.root.info", version.ref = "klibs-gradleplugin" } +klibs-gradle-stub-javadoc = { id = "ru.astrainteractive.gradleplugin.stub.javadoc", version.ref = "klibs-gradleplugin" } klibs-minecraft-resource-processor = { id = "ru.astrainteractive.gradleplugin.minecraft.resource-processor", version.ref = "klibs-gradleplugin" } -klibs-minecraft-shadow = { id = "ru.astrainteractive.gradleplugin.minecraft.shadow", version.ref = "klibs-gradleplugin" } +kotlin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin-version" } +kotlin-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlin-benchmark" } +kotlin-gradle = { id = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-version" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-version" } +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin-version" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-version" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d6e308a..5c82cb0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/instances/bukkit/build.gradle.kts b/instances/bukkit/build.gradle.kts index 104b4a9..53f7c9d 100644 --- a/instances/bukkit/build.gradle.kts +++ b/instances/bukkit/build.gradle.kts @@ -1,15 +1,20 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.kotlin.dsl.named import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo + plugins { kotlin("jvm") alias(libs.plugins.klibs.gradle.java.core) - alias(libs.plugins.klibs.minecraft.shadow) alias(libs.plugins.klibs.minecraft.resource.processor) + alias(libs.plugins.gradle.shadow) } dependencies { // Kotlin - implementation(libs.bundles.kotlin) + implementation(libs.kotlin.coroutines.core) + implementation(libs.kotlin.serialization.json) + implementation(libs.kotlin.serialization.kaml) // AstraLibs implementation(libs.minecraft.astralibs.core) implementation(libs.minecraft.astralibs.command) @@ -28,29 +33,63 @@ dependencies { } minecraftProcessResource { - bukkit() + bukkit( + customProperties = mapOf( + "libraries" to listOf( + libs.driver.h2.get(), + libs.driver.jdbc.get(), + libs.driver.mysql.get(), + ).joinToString("\",\"", "[\"", "\"]") + ) + ) } -astraShadowJar { - requireShadowJarTask { - destination = File("/home/makeevrserg/Desktop/git/AstraTemplate/build/bukkit/plugins/") - .takeIf { it.exists() } - ?: File(rootDir, "jars") - - val projectInfo = requireProjectInfo - isReproducibleFileOrder = true - mergeServiceFiles() - dependsOn(configurations) - archiveClassifier.set(null as String?) - relocate("org.bstats", projectInfo.group) - - minimize { - exclude(dependency(libs.exposed.jdbc.get())) - exclude(dependency(libs.exposed.dao.get())) - exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib:${libs.versions.kotlin.version.get()}")) +val shadowJar = tasks.named("shadowJar") +shadowJar.configure { + + val projectInfo = requireProjectInfo + isReproducibleFileOrder = true + mergeServiceFiles() + dependsOn(configurations) + archiveClassifier.set(null as String?) + + minimize { + exclude(dependency(libs.exposed.jdbc.get())) + exclude(dependency(libs.exposed.dao.get())) + } + archiveVersion.set(projectInfo.versionString) + archiveBaseName.set("${projectInfo.name}-bukkit") + destinationDirectory = rootDir.resolve("build") + .resolve("bukkit") + .resolve("plugins") + .takeIf(File::exists) + ?: File(rootDir, "jars").also(File::mkdirs) + + relocate("org.bstats", projectInfo.group) + listOf( + "co.touchlab", + "com.mysql", + "google.protobuf", + "io.github.reactivecircus", + "ch.qos.logback", + "com.charleskorn.kaml", + "com.ibm.icu", + "it.krzeminski.snakeyaml", + "net.thauvin.erik", + "okio", + "org.apache", + "org.intellij", + "org.slf4j", + "org.jetbrains.annotations", + "ru.astrainteractive.klibs", + "ru.astrainteractive.astralibs" + ).forEach { pattern -> relocate(pattern, "${projectInfo.group}.$pattern") } + listOf( + "org.jetbrains.exposed", + "kotlinx", + ).forEach { pattern -> + relocate(pattern, "${projectInfo.group}.$pattern") { + exclude("kotlin/kotlin.kotlin_builtins") } - archiveVersion.set(projectInfo.versionString) - archiveBaseName.set("${projectInfo.name}-bukkit") - destinationDirectory.set(destination.get()) } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt index b4fd46d..329980b 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt @@ -1,19 +1,17 @@ package ru.astrainteractive.astratemplate -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.lifecycle.Lifecycle -import ru.astrainteractive.astralibs.logging.JUtiltLogger -import ru.astrainteractive.astralibs.logging.Logger +import ru.astrainteractive.astralibs.lifecycle.LifecyclePlugin import ru.astrainteractive.astratemplate.di.RootModule +import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger +import ru.astrainteractive.klibs.mikro.core.logging.Logger /** * Initial class for your plugin */ class AstraTemplate : - JavaPlugin(), - Logger by JUtiltLogger("AstraTemplate"), - Lifecycle { + LifecyclePlugin(), + Logger by JUtiltLogger("AstraTemplate") { private val rootModule = RootModule(this) /** diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommand.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommand.kt index bac2d2c..a3dae44 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommand.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommand.kt @@ -12,7 +12,7 @@ internal interface AddItemCommand { ) sealed class Error(message: String) : CommandException(message) { - data object SenderNotPlayer : Error("SenderNotPlayer") - data object ItemNotfound : Error("ItemNotfound") + class SenderNotPlayer : Error("SenderNotPlayer") + class ItemNotfound : Error("ItemNotfound") } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommandParser.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommandParser.kt deleted file mode 100644 index 5023783..0000000 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommandParser.kt +++ /dev/null @@ -1,32 +0,0 @@ -package ru.astrainteractive.astratemplate.command.additem - -import org.bukkit.Bukkit -import org.bukkit.Material -import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.command.api.context.BukkitCommandContext -import ru.astrainteractive.astralibs.command.api.exception.NoPlayerException -import ru.astrainteractive.astralibs.command.api.parser.CommandParser - -internal class AddItemCommandParser : CommandParser { - override fun parse(ctx: BukkitCommandContext): AddItemCommand.Result { - if (ctx.sender !is Player) throw AddItemCommand.Error.SenderNotPlayer - - val playerString = ctx.args.getOrNull(0) - val player = playerString - ?.let { value -> Bukkit.getOnlinePlayers().firstOrNull { it.name == value } } - ?: throw NoPlayerException(playerString.orEmpty()) - - val amount = ctx.args.getOrNull(2) - ?.toIntOrNull() ?: 1 - - val item = ctx.args.getOrNull(1) - ?.let(Material::getMaterial) - ?: throw AddItemCommand.Error.ItemNotfound - - return AddItemCommand.Result( - player = player, - amount = amount, - item = item - ) - } -} diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommandRegistry.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommandRegistry.kt index 0f4ccbf..d1db451 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommandRegistry.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommandRegistry.kt @@ -1,40 +1,56 @@ package ru.astrainteractive.astratemplate.command.additem +import com.mojang.brigadier.arguments.IntegerArgumentType +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.tree.LiteralCommandNode +import io.papermc.paper.command.brigadier.CommandSourceStack import org.bukkit.Bukkit import org.bukkit.Material -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.command.api.context.BukkitCommandContext -import ru.astrainteractive.astralibs.command.api.error.ErrorHandler -import ru.astrainteractive.astralibs.command.api.util.PluginExt.setCommandExecutor +import ru.astrainteractive.astralibs.command.api.argumenttype.ArgumentConverter +import ru.astrainteractive.astralibs.command.api.exception.NoPlayerException +import ru.astrainteractive.astralibs.command.api.util.argument +import ru.astrainteractive.astralibs.command.api.util.command +import ru.astrainteractive.astralibs.command.api.util.requireArgument +import ru.astrainteractive.astralibs.command.api.util.runs import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer import ru.astrainteractive.astralibs.kyori.unwrap -import ru.astrainteractive.astralibs.util.withEntry +import ru.astrainteractive.astratemplate.command.errorhandler.DefaultErrorHandler import ru.astrainteractive.klibs.kstorage.api.CachedKrate internal class AddItemCommandRegistry( - private val plugin: JavaPlugin, - private val errorHandler: ErrorHandler, - kyoriKrate: CachedKrate + kyoriKrate: CachedKrate, + private val errorHandler: DefaultErrorHandler, + private val executor: AddItemExecutor ) : KyoriComponentSerializer by kyoriKrate.unwrap() { - private val alias = "add" - - private fun tabCompleter(plugin: JavaPlugin) { - plugin.getCommand(alias)?.setTabCompleter { sender, command, label, args -> - when (args.size) { - 2 -> Material.entries.map { it.name }.withEntry(args.last()) - 3 -> IntRange(1, 64).map { it.toString() }.withEntry(args.last()) - else -> Bukkit.getOnlinePlayers().map { it.name }.withEntry(args.last()) - } + private object MaterialArgumentConverter : ArgumentConverter { + override fun transform(argument: String): Material { + return Material.getMaterial(argument) ?: throw AddItemCommand.Error.ItemNotfound() } } - fun register() { - tabCompleter(plugin) - plugin.setCommandExecutor( - alias = alias, - commandParser = AddItemCommandParser(), - commandExecutor = AddItemExecutor(), - errorHandler = errorHandler - ) + fun createNode(): LiteralCommandNode { + return command("add") { + argument("player", StringArgumentType.word()) { playerArg -> + argument("material", StringArgumentType.word()) { materialArg -> + argument("amount", IntegerArgumentType.integer(1, 64)) { amountArg -> + runs(errorHandler::handle) { ctx -> + val playerName = ctx.requireArgument(playerArg) + val player = Bukkit.getPlayerExact(playerName) ?: throw NoPlayerException(playerName) + + val material = ctx.requireArgument(materialArg, MaterialArgumentConverter) + + val amount = ctx.requireArgument(amountArg) + executor.execute( + AddItemCommand.Result( + player = player, + amount = amount, + item = material + ) + ) + } + } + } + } + }.build() } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemExecutor.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemExecutor.kt index e9e0792..5c55c80 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemExecutor.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemExecutor.kt @@ -1,10 +1,9 @@ package ru.astrainteractive.astratemplate.command.additem import org.bukkit.inventory.ItemStack -import ru.astrainteractive.astralibs.command.api.executor.CommandExecutor -internal class AddItemExecutor : CommandExecutor { - override fun execute(input: AddItemCommand.Result) { +internal class AddItemExecutor { + fun execute(input: AddItemCommand.Result) { val itemStack = ItemStack(input.item, input.amount) input.player.inventory.addItem(itemStack) } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/common/CommonCommandsRegistry.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/common/CommonCommandsRegistry.kt index 425ae4e..fca9ef8 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/common/CommonCommandsRegistry.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/common/CommonCommandsRegistry.kt @@ -1,31 +1,26 @@ package ru.astrainteractive.astratemplate.command.common -import org.bukkit.plugin.java.JavaPlugin +import com.mojang.brigadier.tree.LiteralCommandNode +import io.papermc.paper.command.brigadier.CommandSourceStack +import ru.astrainteractive.astralibs.command.api.util.command +import ru.astrainteractive.astralibs.command.api.util.runs import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer import ru.astrainteractive.astralibs.kyori.unwrap -import ru.astrainteractive.astralibs.util.withEntry import ru.astrainteractive.astratemplate.core.plugin.PluginTranslation import ru.astrainteractive.klibs.kstorage.api.CachedKrate import ru.astrainteractive.klibs.kstorage.util.getValue internal class CommonCommandsRegistry( - private val plugin: JavaPlugin, translationKrate: CachedKrate, kyoriKrate: CachedKrate ) : KyoriComponentSerializer by kyoriKrate.unwrap() { private val translation by translationKrate - fun register() { - plugin.getCommand("atemp")?.setTabCompleter { sender, command, label, args -> - when { - args.isEmpty() -> listOf("atemp", "atempreload") - args.size == 1 -> listOf("atemp", "atempreload").withEntry(args.last()) - else -> emptyList() + fun createNode(): LiteralCommandNode { + return command("translation") { + runs { ctx -> + ctx.source.sender.sendMessage(translation.general.getByByCheck.component) } - } - plugin.getCommand("translation")?.setExecutor { sender, command, label, args -> - sender.sendMessage(translation.general.getByByCheck.component) - true - } + }.build() } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/damage/DamageCommand.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/damage/DamageCommand.kt deleted file mode 100644 index 3300a60..0000000 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/damage/DamageCommand.kt +++ /dev/null @@ -1,11 +0,0 @@ -package ru.astrainteractive.astratemplate.command.damage - -import org.bukkit.entity.Player - -internal interface DamageCommand { - class Result( - val player: Player, - val damage: Double, - val damagerName: String - ) -} diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/damage/DamageCommandRegistry.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/damage/DamageCommandRegistry.kt index 3f4b8bc..8653fb9 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/damage/DamageCommandRegistry.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/damage/DamageCommandRegistry.kt @@ -1,76 +1,54 @@ package ru.astrainteractive.astratemplate.command.damage +import com.mojang.brigadier.arguments.DoubleArgumentType +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.tree.LiteralCommandNode +import io.papermc.paper.command.brigadier.CommandSourceStack import org.bukkit.Bukkit -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.command.api.context.BukkitCommandContext -import ru.astrainteractive.astralibs.command.api.error.ErrorHandler -import ru.astrainteractive.astralibs.command.api.exception.NoPermissionException import ru.astrainteractive.astralibs.command.api.exception.NoPlayerException -import ru.astrainteractive.astralibs.command.api.executor.CommandExecutor -import ru.astrainteractive.astralibs.command.api.parser.CommandParser -import ru.astrainteractive.astralibs.command.api.util.PluginExt.setCommandExecutor +import ru.astrainteractive.astralibs.command.api.util.argument +import ru.astrainteractive.astralibs.command.api.util.command +import ru.astrainteractive.astralibs.command.api.util.requireArgument +import ru.astrainteractive.astralibs.command.api.util.requirePermission +import ru.astrainteractive.astralibs.command.api.util.runs import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer import ru.astrainteractive.astralibs.kyori.unwrap -import ru.astrainteractive.astralibs.permission.BukkitPermissibleExt.toPermissible +import ru.astrainteractive.astratemplate.command.errorhandler.DefaultErrorHandler import ru.astrainteractive.astratemplate.core.plugin.PluginPermission import ru.astrainteractive.astratemplate.core.plugin.PluginTranslation import ru.astrainteractive.klibs.kstorage.api.CachedKrate import ru.astrainteractive.klibs.kstorage.util.getValue internal class DamageCommandRegistry( - private val plugin: JavaPlugin, - private val errorHandler: ErrorHandler, translationKrate: CachedKrate, - kyoriKrate: CachedKrate + kyoriKrate: CachedKrate, + private val errorHandler: DefaultErrorHandler ) : KyoriComponentSerializer by kyoriKrate.unwrap() { private val translation by translationKrate - private val alias = "adamage" - private inner class CommandParserImpl : CommandParser { - override fun parse(commandContext: BukkitCommandContext): DamageCommand.Result { - val hasPermission = commandContext.sender.toPermissible().hasPermission(PluginPermission.Damage) - if (!hasPermission) throw NoPermissionException(PluginPermission.Damage) - - val playerString = commandContext.args.getOrNull(0) - val player = playerString - ?.let(Bukkit::getPlayerExact) - ?: throw NoPlayerException(playerString.orEmpty()) - - val damage = commandContext.args.getOrNull(1) - ?.toDoubleOrNull() - ?: 0.0 - - return DamageCommand.Result( - player = player, - damage = damage, - damagerName = commandContext.sender.name - ) - } - } - - private inner class CommandExecutorImpl : CommandExecutor { - override fun execute(input: DamageCommand.Result) { - input.player.sendMessage(translation.custom.damaged(input.damagerName).let(::toComponent)) - input.player.damage(input.damage) - } - } - - private fun tabCompleter() = plugin.getCommand(alias)?.setTabCompleter { sender, command, label, args -> - when (args.size) { - 0 -> listOf("adamage") - 1 -> Bukkit.getOnlinePlayers().map { it.name } - 2 -> listOf(translation.custom.damageHint.raw) - else -> Bukkit.getOnlinePlayers().map { it.name } - } - } - - fun register() { - tabCompleter() - plugin.setCommandExecutor( - alias = alias, - commandParser = CommandParserImpl(), - commandExecutor = CommandExecutorImpl(), - errorHandler = errorHandler - ) + fun createNode(): LiteralCommandNode { + return command("adamage") { + argument("player", StringArgumentType.word()) { playerArg -> + runs(errorHandler::handle) { ctx -> + ctx.requirePermission(PluginPermission.Damage) + + val playerName = ctx.requireArgument(playerArg) + val player = Bukkit.getPlayerExact(playerName) ?: throw NoPlayerException(playerName) + player.sendMessage(translation.custom.damaged(ctx.source.sender.name).component) + player.damage(0.0) + } + argument("damage", DoubleArgumentType.doubleArg(0.0)) { damageArg -> + runs(errorHandler::handle) { ctx -> + ctx.requirePermission(PluginPermission.Damage) + + val playerName = ctx.requireArgument(playerArg) + val player = Bukkit.getPlayerExact(playerName) ?: throw NoPlayerException(playerName) + val damage = ctx.requireArgument(damageArg) + player.sendMessage(translation.custom.damaged(ctx.source.sender.name).component) + player.damage(damage) + } + } + } + }.build() } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/di/CommandModule.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/di/CommandModule.kt index 49bbe53..1eb3906 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/di/CommandModule.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/di/CommandModule.kt @@ -1,63 +1,72 @@ package ru.astrainteractive.astratemplate.command.di +import ru.astrainteractive.astralibs.command.api.registrar.PaperCommandRegistrarContext import ru.astrainteractive.astralibs.lifecycle.Lifecycle -import ru.astrainteractive.astratemplate.command.DefaultErrorHandler +import ru.astrainteractive.astratemplate.api.remote.di.ApiRemoteModule import ru.astrainteractive.astratemplate.command.additem.AddItemCommandRegistry +import ru.astrainteractive.astratemplate.command.additem.AddItemExecutor import ru.astrainteractive.astratemplate.command.common.CommonCommandsRegistry import ru.astrainteractive.astratemplate.command.damage.DamageCommandRegistry +import ru.astrainteractive.astratemplate.command.errorhandler.DefaultErrorHandler import ru.astrainteractive.astratemplate.command.gui.GuiCommandRegistry import ru.astrainteractive.astratemplate.command.reload.ReloadCommandRegistry -import ru.astrainteractive.astratemplate.command.rickmorty.RandomRickAndMortyCommandRegistry -import ru.astrainteractive.astratemplate.di.RootModule +import ru.astrainteractive.astratemplate.command.rickmorty.RickMortyCommandRegistrar +import ru.astrainteractive.astratemplate.core.di.CoreModule +import ru.astrainteractive.astratemplate.di.BukkitModule +import ru.astrainteractive.astratemplate.gui.di.GuiModule -internal interface CommandModule { - val lifecycle: Lifecycle - - class Default(rootModule: RootModule) : CommandModule { - override val lifecycle: Lifecycle by lazy { - Lifecycle.Lambda( - onEnable = { - val errorHandler = DefaultErrorHandler( - translationKrate = rootModule.coreModule.translationKrate, - kyoriKrate = rootModule.bukkitModule.kyoriKrate - ) - AddItemCommandRegistry( - plugin = rootModule.bukkitModule.plugin, - kyoriKrate = rootModule.bukkitModule.kyoriKrate, - errorHandler = errorHandler - ).register() - CommonCommandsRegistry( - plugin = rootModule.bukkitModule.plugin, - kyoriKrate = rootModule.bukkitModule.kyoriKrate, - translationKrate = rootModule.coreModule.translationKrate, - ).register() - DamageCommandRegistry( - errorHandler = errorHandler, - plugin = rootModule.bukkitModule.plugin, - kyoriKrate = rootModule.bukkitModule.kyoriKrate, - translationKrate = rootModule.coreModule.translationKrate, - ).register() - GuiCommandRegistry( - errorHandler = errorHandler, - plugin = rootModule.bukkitModule.plugin, - kyoriKrate = rootModule.bukkitModule.kyoriKrate, - router = rootModule.guiModule.router, - ).register() - ReloadCommandRegistry( - errorHandler = errorHandler, - plugin = rootModule.bukkitModule.plugin, - kyoriKrate = rootModule.bukkitModule.kyoriKrate, - translationKrate = rootModule.coreModule.translationKrate, - ).register() - RandomRickAndMortyCommandRegistry( - scope = rootModule.coreModule.ioScope, - dispatchers = rootModule.bukkitModule.dispatchers, - rmApi = rootModule.apiRemoteModule.rickMortyApi, - errorHandler = errorHandler, - plugin = rootModule.bukkitModule.plugin, - ).register() - } - ) - } +internal class CommandModule( + coreModule: CoreModule, + bukkitModule: BukkitModule, + guiModule: GuiModule, + apiRemoteModule: ApiRemoteModule, +) { + private val commandRegistrarContext = PaperCommandRegistrarContext( + coreModule.mainScope, + bukkitModule.plugin + ) + private val nodes = buildList { + val errorHandler = DefaultErrorHandler( + translationKrate = coreModule.translationKrate, + kyoriKrate = bukkitModule.kyoriKrate + ) + AddItemCommandRegistry( + kyoriKrate = bukkitModule.kyoriKrate, + errorHandler = errorHandler, + executor = AddItemExecutor() + ).createNode().run(::add) + CommonCommandsRegistry( + kyoriKrate = bukkitModule.kyoriKrate, + translationKrate = coreModule.translationKrate, + ).createNode().run(::add) + DamageCommandRegistry( + errorHandler = errorHandler, + kyoriKrate = bukkitModule.kyoriKrate, + translationKrate = coreModule.translationKrate, + ).createNode().run(::add) + GuiCommandRegistry( + router = guiModule.router, + kyoriKrate = bukkitModule.kyoriKrate, + errorHandler = errorHandler, + ).createNode().run(::add) + ReloadCommandRegistry( + plugin = bukkitModule.plugin, + translationKrate = coreModule.translationKrate, + kyoriKrate = bukkitModule.kyoriKrate, + errorHandler = errorHandler, + ).createNode().run(::add) + RickMortyCommandRegistrar( + scope = coreModule.ioScope, + dispatchers = coreModule.dispatchers, + rmApi = apiRemoteModule.rickMortyApi, + errorHandler = errorHandler, + ).createNode().run(::add) + } + val lifecycle: Lifecycle by lazy { + Lifecycle.Lambda( + onEnable = { + nodes.forEach(commandRegistrarContext::registerWhenReady) + } + ) } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/DefaultErrorHandler.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/errorhandler/DefaultErrorHandler.kt similarity index 54% rename from instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/DefaultErrorHandler.kt rename to instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/errorhandler/DefaultErrorHandler.kt index 9ba14d5..f7a2365 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/DefaultErrorHandler.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/errorhandler/DefaultErrorHandler.kt @@ -1,63 +1,53 @@ -package ru.astrainteractive.astratemplate.command +package ru.astrainteractive.astratemplate.command.errorhandler -import ru.astrainteractive.astralibs.command.api.context.BukkitCommandContext -import ru.astrainteractive.astralibs.command.api.error.ErrorHandler -import ru.astrainteractive.astralibs.command.api.exception.ArgumentTypeException +import com.mojang.brigadier.context.CommandContext +import io.papermc.paper.command.brigadier.CommandSourceStack +import ru.astrainteractive.astralibs.command.api.exception.ArgumentConverterException import ru.astrainteractive.astralibs.command.api.exception.BadArgumentException import ru.astrainteractive.astralibs.command.api.exception.NoPermissionException import ru.astrainteractive.astralibs.command.api.exception.NoPlayerException import ru.astrainteractive.astralibs.command.api.exception.NoPotionEffectTypeException import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer import ru.astrainteractive.astralibs.kyori.unwrap -import ru.astrainteractive.astralibs.logging.JUtiltLogger -import ru.astrainteractive.astralibs.logging.Logger import ru.astrainteractive.astratemplate.command.additem.AddItemCommand -import ru.astrainteractive.astratemplate.command.gui.GuiCommand import ru.astrainteractive.astratemplate.core.plugin.PluginTranslation import ru.astrainteractive.klibs.kstorage.api.CachedKrate import ru.astrainteractive.klibs.kstorage.util.getValue +import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger +import ru.astrainteractive.klibs.mikro.core.logging.Logger internal class DefaultErrorHandler( translationKrate: CachedKrate, kyoriKrate: CachedKrate -) : ErrorHandler, - Logger by JUtiltLogger("AstraTemplate-DefaultErrorHandler"), +) : Logger by JUtiltLogger("AstraTemplate-DefaultErrorHandler"), KyoriComponentSerializer by kyoriKrate.unwrap() { private val translation by translationKrate - override fun handle(ctx: BukkitCommandContext, throwable: Throwable) { + fun handle(ctx: CommandContext, throwable: Throwable) { when (throwable) { is AddItemCommand.Error -> { when (throwable) { - AddItemCommand.Error.ItemNotfound -> { - ctx.sender.sendMessage(translation.fault.itemNotFound.component) + is AddItemCommand.Error.ItemNotfound -> { + ctx.source.sender.sendMessage(translation.fault.itemNotFound.component) } - AddItemCommand.Error.SenderNotPlayer -> { - ctx.sender.sendMessage(translation.fault.notPlayer.component) - } - } - } - - is GuiCommand.Error -> { - when (throwable) { - GuiCommand.Error.NotPlayer -> { - ctx.sender.sendMessage(translation.fault.notPlayer.component) + is AddItemCommand.Error.SenderNotPlayer -> { + ctx.source.sender.sendMessage(translation.fault.notPlayer.component) } } } is NoPlayerException -> { - ctx.sender.sendMessage(translation.fault.playerNotExists.component) + ctx.source.sender.sendMessage(translation.fault.playerNotExists.component) } is NoPermissionException -> { - ctx.sender.sendMessage(translation.fault.noPermission.component) + ctx.source.sender.sendMessage(translation.fault.noPermission.component) } is NoPotionEffectTypeException, is BadArgumentException, - is ArgumentTypeException -> { + is ArgumentConverterException -> { error { "#handle intentionally unhandled error: $throwable" } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/gui/GuiCommand.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/gui/GuiCommand.kt deleted file mode 100644 index a4acd9d..0000000 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/gui/GuiCommand.kt +++ /dev/null @@ -1,16 +0,0 @@ -package ru.astrainteractive.astratemplate.command.gui - -import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.command.api.exception.CommandException -import ru.astrainteractive.astratemplate.gui.router.Router - -internal interface GuiCommand { - class Result( - val player: Player, - val route: Router.Route - ) - - sealed class Error(message: String) : CommandException(message) { - data object NotPlayer : Error("NotPlayer") - } -} diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/gui/GuiCommandRegistry.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/gui/GuiCommandRegistry.kt index de0ecda..b32411e 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/gui/GuiCommandRegistry.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/gui/GuiCommandRegistry.kt @@ -1,34 +1,29 @@ package ru.astrainteractive.astratemplate.command.gui -import org.bukkit.entity.Player -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.command.api.context.BukkitCommandContext -import ru.astrainteractive.astralibs.command.api.error.ErrorHandler -import ru.astrainteractive.astralibs.command.api.util.PluginExt.setCommandExecutor +import com.mojang.brigadier.tree.LiteralCommandNode +import io.papermc.paper.command.brigadier.CommandSourceStack +import ru.astrainteractive.astralibs.command.api.util.command +import ru.astrainteractive.astralibs.command.api.util.requirePlayer +import ru.astrainteractive.astralibs.command.api.util.runs import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer import ru.astrainteractive.astralibs.kyori.unwrap +import ru.astrainteractive.astratemplate.command.errorhandler.DefaultErrorHandler import ru.astrainteractive.astratemplate.gui.router.Router import ru.astrainteractive.klibs.kstorage.api.CachedKrate internal class GuiCommandRegistry( - private val plugin: JavaPlugin, - private val errorHandler: ErrorHandler, + kyoriKrate: CachedKrate, private val router: Router, - kyoriKrate: CachedKrate + private val errorHandler: DefaultErrorHandler ) : KyoriComponentSerializer by kyoriKrate.unwrap() { - fun register() { - plugin.setCommandExecutor( - alias = "atempgui", - commandParser = commandParser@{ commandContext -> - val player = commandContext.sender as? Player ?: throw GuiCommand.Error.NotPlayer + fun createNode(): LiteralCommandNode { + return command("atempgui") { + runs(errorHandler::handle) { ctx -> + val player = ctx.requirePlayer() val route = Router.Route.Sample - GuiCommand.Result(player, route) - }, - commandExecutor = { result -> - router.open(result.player, result.route) - }, - errorHandler = errorHandler - ) + router.open(player, route) + } + }.build() } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/ReloadCommandRegistry.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/ReloadCommandRegistry.kt index 150453f..19b65c9 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/ReloadCommandRegistry.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/ReloadCommandRegistry.kt @@ -1,56 +1,35 @@ package ru.astrainteractive.astratemplate.command.reload -import org.bukkit.command.CommandSender -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.command.api.context.BukkitCommandContext -import ru.astrainteractive.astralibs.command.api.error.ErrorHandler -import ru.astrainteractive.astralibs.command.api.exception.NoPermissionException -import ru.astrainteractive.astralibs.command.api.executor.CommandExecutor -import ru.astrainteractive.astralibs.command.api.parser.CommandParser -import ru.astrainteractive.astralibs.command.api.util.PluginExt.setCommandExecutor +import com.mojang.brigadier.tree.LiteralCommandNode +import io.papermc.paper.command.brigadier.CommandSourceStack +import ru.astrainteractive.astralibs.command.api.util.command +import ru.astrainteractive.astralibs.command.api.util.requirePermission +import ru.astrainteractive.astralibs.command.api.util.runs import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer import ru.astrainteractive.astralibs.kyori.unwrap -import ru.astrainteractive.astralibs.permission.BukkitPermissibleExt.toPermissible -import ru.astrainteractive.astratemplate.AstraTemplate +import ru.astrainteractive.astralibs.lifecycle.LifecyclePlugin +import ru.astrainteractive.astratemplate.command.errorhandler.DefaultErrorHandler import ru.astrainteractive.astratemplate.core.plugin.PluginPermission import ru.astrainteractive.astratemplate.core.plugin.PluginTranslation import ru.astrainteractive.klibs.kstorage.api.CachedKrate import ru.astrainteractive.klibs.kstorage.util.getValue internal class ReloadCommandRegistry( - private val plugin: JavaPlugin, - private val errorHandler: ErrorHandler, translationKrate: CachedKrate, - kyoriKrate: CachedKrate + kyoriKrate: CachedKrate, + private val plugin: LifecyclePlugin, + private val errorHandler: DefaultErrorHandler ) : KyoriComponentSerializer by kyoriKrate.unwrap() { private val translation by translationKrate - interface ReloadCommand { - class Result(val sender: CommandSender) - } - - private inner class CommandParserImpl : CommandParser { - override fun parse(ctx: BukkitCommandContext): ReloadCommand.Result { - val hasPermission = ctx.sender.toPermissible().hasPermission(PluginPermission.Damage) - if (!hasPermission) throw NoPermissionException(PluginPermission.Damage) - return ReloadCommand.Result(ctx.sender) - } - } - - private inner class CommandExecutorImpl : CommandExecutor { - override fun execute(input: ReloadCommand.Result) { - input.sender.sendMessage(translation.general.reload.let(::toComponent)) - (plugin as AstraTemplate).onReload() - input.sender.sendMessage(translation.general.reloadComplete.let(::toComponent)) - } - } - - fun register() { - plugin.setCommandExecutor( - alias = "atempreload", - commandParser = CommandParserImpl(), - commandExecutor = CommandExecutorImpl(), - errorHandler = errorHandler - ) + fun createNode(): LiteralCommandNode { + return command("atempreload") { + runs(errorHandler::handle) { ctx -> + ctx.requirePermission(PluginPermission.Damage) + ctx.source.sender.sendMessage(translation.general.reload.component) + plugin.onReload() + ctx.source.sender.sendMessage(translation.general.reloadComplete.component) + } + }.build() } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RandomRickAndMortyCommand.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RandomRickAndMortyCommand.kt deleted file mode 100644 index 3e338c0..0000000 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RandomRickAndMortyCommand.kt +++ /dev/null @@ -1,7 +0,0 @@ -package ru.astrainteractive.astratemplate.command.rickmorty - -import org.bukkit.command.CommandSender - -internal interface RandomRickAndMortyCommand { - class Result(val sender: CommandSender) -} diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RandomRickAndMortyCommandRegistry.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RandomRickAndMortyCommandRegistry.kt deleted file mode 100644 index f25449d..0000000 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RandomRickAndMortyCommandRegistry.kt +++ /dev/null @@ -1,43 +0,0 @@ -package ru.astrainteractive.astratemplate.command.rickmorty - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.command.api.context.BukkitCommandContext -import ru.astrainteractive.astralibs.command.api.error.ErrorHandler -import ru.astrainteractive.astralibs.command.api.util.PluginExt.setCommandExecutor -import ru.astrainteractive.astratemplate.api.remote.RickMortyApi -import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers -import kotlin.random.Random - -internal class RandomRickAndMortyCommandRegistry( - private val plugin: JavaPlugin, - private val scope: CoroutineScope, - private val dispatchers: KotlinDispatchers, - private val rmApi: RickMortyApi, - private val errorHandler: ErrorHandler -) { - - fun register() { - plugin.setCommandExecutor( - alias = "rickandmorty", - commandParser = { commandContext -> - RandomRickAndMortyCommand.Result(commandContext.sender) - }, - commandExecutor = { input -> - scope.launch(dispatchers.IO) { - val randomInt = Random.nextInt(0, 100) - val result = rmApi.getRandomCharacter(randomInt) - result.onSuccess { - input.sender.sendMessage("Got response: $it") - } - result.onFailure { - it.printStackTrace() - input.sender.sendMessage("Fail: ${it.message}") - } - } - }, - errorHandler = errorHandler - ) - } -} diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RickMortyCommandRegistrar.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RickMortyCommandRegistrar.kt new file mode 100644 index 0000000..d5e5ed9 --- /dev/null +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RickMortyCommandRegistrar.kt @@ -0,0 +1,61 @@ +package ru.astrainteractive.astratemplate.command.rickmorty + +import com.mojang.brigadier.arguments.IntegerArgumentType +import com.mojang.brigadier.tree.LiteralCommandNode +import io.papermc.paper.command.brigadier.CommandSourceStack +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch +import org.bukkit.command.CommandSender +import ru.astrainteractive.astralibs.command.api.util.argument +import ru.astrainteractive.astralibs.command.api.util.command +import ru.astrainteractive.astralibs.command.api.util.literal +import ru.astrainteractive.astralibs.command.api.util.requireArgument +import ru.astrainteractive.astralibs.command.api.util.runs +import ru.astrainteractive.astratemplate.api.remote.RickMortyApi +import ru.astrainteractive.astratemplate.command.errorhandler.DefaultErrorHandler +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers +import kotlin.random.Random + +internal class RickMortyCommandRegistrar( + private val scope: CoroutineScope, + private val dispatchers: KotlinDispatchers, + private val rmApi: RickMortyApi, + private val errorHandler: DefaultErrorHandler +) { + + private fun send(sender: CommandSender, number: Int) { + scope.launch(dispatchers.IO) { + val result = rmApi.getRandomCharacter(number) + result.onSuccess { + sender.sendMessage("Got response: $it") + } + result.onFailure { + it.printStackTrace() + sender.sendMessage("Fail: ${it.message}") + } + } + } + + fun createNode(): LiteralCommandNode { + return command("rickandmorty") { + literal("random") { + runs(errorHandler::handle) { ctx -> + send( + sender = ctx.source.sender, + number = Random.nextInt(0, 100) + ) + } + } + literal("specific") { + argument("number", IntegerArgumentType.integer()) { numberArg -> + runs(errorHandler::handle) { ctx -> + send( + sender = ctx.source.sender, + number = ctx.requireArgument(numberArg) + ) + } + } + } + }.build() + } +} diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/di/BukkitModule.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/di/BukkitModule.kt index d1fd5d6..902dcea 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/di/BukkitModule.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/di/BukkitModule.kt @@ -1,13 +1,11 @@ package ru.astrainteractive.astratemplate.di -import ru.astrainteractive.astralibs.async.DefaultBukkitDispatchers import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer import ru.astrainteractive.astratemplate.AstraTemplate import ru.astrainteractive.klibs.kstorage.api.impl.DefaultMutableKrate import ru.astrainteractive.klibs.kstorage.util.asCachedKrate class BukkitModule(val plugin: AstraTemplate) { - val dispatchers = DefaultBukkitDispatchers(plugin) val kyoriKrate = DefaultMutableKrate( loader = { null }, factory = { KyoriComponentSerializer.Legacy } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt index 6436965..ec316eb 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt @@ -1,5 +1,6 @@ package ru.astrainteractive.astratemplate.di +import ru.astrainteractive.astralibs.async.DefaultBukkitDispatchers import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astratemplate.AstraTemplate import ru.astrainteractive.astratemplate.api.local.di.ApiLocalModule @@ -13,9 +14,10 @@ internal class RootModule(plugin: AstraTemplate) { val bukkitModule: BukkitModule = BukkitModule(plugin) - val coreModule: CoreModule by lazy { - CoreModule(bukkitModule.plugin.dataFolder) - } + val coreModule: CoreModule = CoreModule( + dataFolder = bukkitModule.plugin.dataFolder, + dispatchers = DefaultBukkitDispatchers(plugin) + ) val apiLocalModule: ApiLocalModule = ApiLocalModule( dataFolder = bukkitModule.plugin.dataFolder, @@ -26,14 +28,18 @@ internal class RootModule(plugin: AstraTemplate) { val apiRemoteModule: ApiRemoteModule = ApiRemoteModule() val eventModule: EventModule = EventModule(this) - - val commandModule: CommandModule = CommandModule.Default(this) - val guiModule: GuiModule = GuiModule( coreModule = coreModule, bukkitModule = bukkitModule, apiLocalModule = apiLocalModule ) + val commandModule: CommandModule = CommandModule( + coreModule = coreModule, + bukkitModule = bukkitModule, + apiRemoteModule = apiRemoteModule, + guiModule = guiModule + ) + private val lifecycles: List get() = listOf( coreModule.lifecycle, diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/event/di/EventModule.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/event/di/EventModule.kt index 9f643b8..8138be0 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/event/di/EventModule.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/event/di/EventModule.kt @@ -10,12 +10,8 @@ import ru.astrainteractive.astratemplate.event.event.MultipleEventsDSL import ru.astrainteractive.astratemplate.event.event.TemplateEvent internal class EventModule(rootModule: RootModule) { - val eventListener: EventListener by lazy { - EventListener.Default() - } - val inventoryClickListener: EventListener by lazy { - DefaultInventoryClickEvent() - } + val eventListener: EventListener = EventListener.Default() + val inventoryClickListener: EventListener = DefaultInventoryClickEvent() private val events = buildList { eventListener.run(::add) diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/di/GuiModule.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/di/GuiModule.kt index 4747623..a2383ad 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/di/GuiModule.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/di/GuiModule.kt @@ -16,8 +16,8 @@ internal class GuiModule( ) { private val getRandomColorUseCase = GetRandomColorUseCaseImpl() val router: Router = RouterImpl( - scope = coreModule.ioScope, - dispatchers = bukkitModule.dispatchers, + ioScope = coreModule.ioScope, + dispatchers = coreModule.dispatchers, kyoriKrate = bukkitModule.kyoriKrate, translationKrate = coreModule.translationKrate, localDao = apiLocalModule.localDao, diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/router/RouterImpl.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/router/RouterImpl.kt index 53786d8..3e1d45f 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/router/RouterImpl.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/router/RouterImpl.kt @@ -17,7 +17,7 @@ import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers @Suppress("LongParameterList") internal class RouterImpl( - private val scope: CoroutineScope, + private val ioScope: CoroutineScope, private val dispatchers: KotlinDispatchers, private val kyoriKrate: CachedKrate, private val translationKrate: CachedKrate, @@ -41,7 +41,7 @@ internal class RouterImpl( } override fun open(player: Player, route: Router.Route) { - scope.launch(dispatchers.IO) { + ioScope.launch { val gui = buildRoute(player, route) withContext(dispatchers.Main) { gui.open() } } diff --git a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/sample/feature/DefaultSampleGUIComponent.kt b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/sample/feature/DefaultSampleGUIComponent.kt index 2103186..3ff7ca7 100644 --- a/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/sample/feature/DefaultSampleGUIComponent.kt +++ b/instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/gui/sample/feature/DefaultSampleGUIComponent.kt @@ -7,14 +7,15 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import org.bukkit.ChatColor import org.bukkit.event.inventory.ClickType -import ru.astrainteractive.astralibs.async.CoroutineFeature -import ru.astrainteractive.astralibs.logging.JUtiltLogger -import ru.astrainteractive.astralibs.logging.Logger +import ru.astrainteractive.astralibs.async.withTimings import ru.astrainteractive.astratemplate.api.local.dao.LocalDao import ru.astrainteractive.astratemplate.api.local.model.UserModel import ru.astrainteractive.astratemplate.gui.api.ItemStackSpigotAPI import ru.astrainteractive.astratemplate.gui.domain.GetRandomColorUseCase import ru.astrainteractive.astratemplate.gui.domain.SetDisplayNameUseCase +import ru.astrainteractive.klibs.mikro.core.coroutines.CoroutineFeature +import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger +import ru.astrainteractive.klibs.mikro.core.logging.Logger import kotlin.random.Random /** @@ -25,7 +26,7 @@ internal class DefaultSampleGUIComponent( private val itemStackSpigotAPi: ItemStackSpigotAPI, private val getRandomColorUseCase: GetRandomColorUseCase, private val setDisplayNameUseCase: SetDisplayNameUseCase -) : CoroutineFeature by CoroutineFeature.Default(Dispatchers.IO), +) : CoroutineFeature by CoroutineFeature.IO.withTimings(), SampleGuiComponent, Logger by JUtiltLogger("AstraTemplate-DefaultSampleGUIComponent") { diff --git a/instances/bukkit/src/main/resources/plugin.yml b/instances/bukkit/src/main/resources/plugin.yml index 7ce1352..e9a683e 100644 --- a/instances/bukkit/src/main/resources/plugin.yml +++ b/instances/bukkit/src/main/resources/plugin.yml @@ -10,10 +10,7 @@ api-version: 1.18 softdepend: [ ] depend: [ ] loadbefore: [ ] -libraries: - - "org.xerial:sqlite-jdbc:3.46.1.0" - - "mysql:mysql-connector-java:8.0.33" - - "com.h2database:h2:2.2.224" +libraries: ${libraries} commands: add: rickandmorty: diff --git a/instances/fabric/build.gradle.kts b/instances/fabric/build.gradle.kts index f614703..0780230 100644 --- a/instances/fabric/build.gradle.kts +++ b/instances/fabric/build.gradle.kts @@ -4,16 +4,15 @@ import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt plugins { kotlin("jvm") - id("fabric-loom") - alias(libs.plugins.gradle.shadow) + alias(libs.plugins.fabric.loom) alias(libs.plugins.klibs.gradle.java.core) - alias(libs.plugins.klibs.minecraft.shadow) alias(libs.plugins.klibs.minecraft.resource.processor) + alias(libs.plugins.gradle.shadow) } dependencies { + minecraft(libs.minecraft.fabric.mojang.get()) mappings("net.fabricmc:yarn:${libs.versions.minecraft.fabric.yarn.get()}:v2") - minecraft(libs.minecraft.mojang.get()) modImplementation(libs.minecraft.fabric.kotlin.get()) modImplementation(libs.minecraft.fabric.loader.get()) modImplementation(libs.minecraft.fabric.api.get()) @@ -24,7 +23,9 @@ dependencies { implementation(libs.klibs.kstorage) implementation(libs.klibs.mikro.core) // Kotlin - implementation(libs.bundles.kotlin) + implementation(libs.kotlin.coroutines.core) + implementation(libs.kotlin.serialization.json) + implementation(libs.kotlin.serialization.kaml) // Driver implementation(libs.driver.jdbc) // Local @@ -33,29 +34,91 @@ dependencies { implementation(projects.modules.core) } -val destination = File("C:\\Users\\Roman\\Desktop\\Fabric\\mods") - .takeIf(File::exists) +minecraftProcessResource { + fabric() +} + +val destination = rootDir.resolve("build") + .resolve("fabric") + .resolve("mods") + .takeIf { it.exists() } ?: File(rootDir, "jars") val shadowJar by tasks.getting(ShadowJar::class) { - dependencies { - // Kotlin - include(dependency(libs.minecraft.astralibs.core.asProvider().get())) - include(dependency(projects.modules.core)) - include(dependency(projects.modules.apiRemote)) - include(dependency(projects.modules.apiLocal)) - // TODO somehow fix the multiplatform libraries - include(dependency("ru.astrainteractive.klibs:kdi-jvm")) - include(dependency("ru.astrainteractive.klibs:mikro-core-jvm")) - include(dependency(libs.driver.jdbc.get())) - } - exclude("mappings/") - dependsOn(configurations) - from(sourceSets.main.get().allSource) mergeServiceFiles() +// mustRunAfter(minecraftProcessResource.task) +// dependsOn(minecraftProcessResource.task) + configurations = listOf(project.configurations.shadow.get()) isReproducibleFileOrder = true - archiveClassifier.set(null as String?) - archiveBaseName.set("${requireProjectInfo.name}-fabric-shadow") + archiveClassifier = null as String? + archiveVersion = requireProjectInfo.versionString + archiveBaseName = "${requireProjectInfo.name}-fabric" + dependencies { + // deps + exclude(dependency("org.jetbrains:annotations")) + // deps paths + exclude("co/touchlab/stately/**") + exclude("club/minnced/opus/**") + exclude("com/google/**") + exclude("com/sun/**") + exclude("google/protobuf/**") + exclude("io/github/**") + exclude("io/javalin/**") + exclude("jakarta/servlet/**") + exclude("javax/annotation/**") + exclude("javax/servlet/**") + exclude("natives/**") + exclude("nl/altindag/**") + exclude("org/eclipse/**") + exclude("org/bouncycastle/**") + exclude("org/checkerframework/**") + exclude("org/conscrypt/**") + exclude("tomp2p/opuswrapper/**") + exclude("DebugProbesKt.bin") + exclude("_COROUTINE/**") + // meta +// exclude("META-INF/services/**") + exclude("META-INF/*.kotlin_module") + exclude("META-INF/com.android.tools/**") + exclude("META-INF/gradle-plugins/**") + exclude("META-INF/maven/**") + exclude("META-INF/proguard/**") + exclude("META-INF/versions/**") + exclude("META-INF/native/**") + exclude("META-INF/**LICENCE**") + } + // Be sure to relocate EXACT PACKAGES!! + // For example, relocate org.some.package instead of org + // Becuase relocation org will break other non-relocated dependencies such as org.minecraft + listOf( + "com.fasterxml", + "net.kyori", + "org.h2", + "com.neovisionaries", + "gnu.trove", + "org.json", + "org.apache", + "org.telegram", + "okhttp3", + "net.dv8tion", + "okio", + "org.slf4j", + "kotlin", + "kotlinx", + "it.krzeminski", + "net.thauvin", + "org.jetbrains.exposed.dao", + "org.jetbrains.exposed.exceptions", + "org.jetbrains.exposed.sql", + "org.jetbrains.exposed.jdbc", + "org.jetbrains.kotlin", + "org.jetbrains.kotlinx", + "com.charleskorn.kaml", + "ru.astrainteractive.klibs", + "ru.astrainteractive.astralibs", + "club.minnced.discord", + "club.minnced.opus" + ).forEach { pattern -> relocate(pattern, "${requireProjectInfo.group}.shade.$pattern") } } val remapJar = tasks.getByName("remapJar") { @@ -65,6 +128,7 @@ val remapJar = tasks.getByName("remapJar") { addNestedDependencies.set(true) archiveBaseName.set("${requireProjectInfo.name}-fabric") destinationDirectory.set(destination) + archiveVersion = requireProjectInfo.versionString } tasks.assemble { diff --git a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/ClientEntryPoint.kt b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/ClientEntryPoint.kt index 1969d03..3647d1d 100644 --- a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/ClientEntryPoint.kt +++ b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/ClientEntryPoint.kt @@ -6,7 +6,7 @@ import ru.astrainteractive.astratemplate.di.RootModule class ClientEntryPoint : ClientModInitializer { private val rootModule: RootModule by lazy { - RootModule.Default() + RootModule() } override fun onInitializeClient() { diff --git a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/FabricEntryPoint.kt b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/FabricEntryPoint.kt index 37ead75..4a39dd5 100644 --- a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/FabricEntryPoint.kt +++ b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/FabricEntryPoint.kt @@ -6,7 +6,7 @@ import ru.astrainteractive.astratemplate.di.RootModule class FabricEntryPoint : ModInitializer { private val rootModule: RootModule by lazy { - RootModule.Default() + RootModule() } override fun onInitialize() { diff --git a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/command/di/CommandModule.kt b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/command/di/CommandModule.kt index 42c5d52..53279e7 100644 --- a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/command/di/CommandModule.kt +++ b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/command/di/CommandModule.kt @@ -7,30 +7,24 @@ import ru.astrainteractive.astratemplate.command.core.DefaultCommandRegistry import ru.astrainteractive.astratemplate.command.helloworld.HelloWorldCommand import ru.astrainteractive.astratemplate.command.rickmorty.RickMortyCommand import ru.astrainteractive.astratemplate.core.di.CoreModule -import ru.astrainteractive.klibs.mikro.core.dispatchers.DefaultKotlinDispatchers -interface CommandModule { - val lifecycle: Lifecycle - - class Default( - private val coreModule: CoreModule, - private val apiRemoteModule: ApiRemoteModule - ) : CommandModule { - private val commands: List - get() = listOf( - HelloWorldCommand(), - RickMortyCommand( - rickMortyApi = apiRemoteModule.rickMortyApi, - scope = coreModule.ioScope, - dispatchers = DefaultKotlinDispatchers - ) - ) - override val lifecycle: Lifecycle by lazy { - Lifecycle.Lambda( - onEnable = { - commands.forEach(DefaultCommandRegistry::register) - } - ) - } +class CommandModule( + private val coreModule: CoreModule, + private val apiRemoteModule: ApiRemoteModule +) { + private val commands: List = listOf( + HelloWorldCommand(), + RickMortyCommand( + rickMortyApi = apiRemoteModule.rickMortyApi, + ioScope = coreModule.ioScope, + dispatchers = coreModule.dispatchers + ) + ) + val lifecycle: Lifecycle by lazy { + Lifecycle.Lambda( + onEnable = { + commands.forEach(DefaultCommandRegistry::register) + } + ) } } diff --git a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RickMortyCommand.kt b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RickMortyCommand.kt index 5f14d9e..b7fe9d9 100644 --- a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RickMortyCommand.kt +++ b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/command/rickmorty/RickMortyCommand.kt @@ -9,12 +9,12 @@ import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers class RickMortyCommand( private val rickMortyApi: RickMortyApi, - private val scope: CoroutineScope, + private val ioScope: CoroutineScope, private val dispatchers: KotlinDispatchers ) : Command by DslCommand( alias = "rickmorty", block = { - scope.launch(dispatchers.IO) { + ioScope.launch(dispatchers.IO) { println("Getting character...") println(rickMortyApi.getRandomCharacter(1)) } diff --git a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/di/FabricModule.kt b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/di/FabricModule.kt index 7fd5581..8e40211 100644 --- a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/di/FabricModule.kt +++ b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/di/FabricModule.kt @@ -3,14 +3,9 @@ package ru.astrainteractive.astratemplate.di import net.fabricmc.loader.api.FabricLoader import java.io.File -interface FabricModule { +class FabricModule { val fabricLoader: FabricLoader + get() = FabricLoader.getInstance() val configDir: File - - class Default : FabricModule { - override val fabricLoader: FabricLoader - get() = FabricLoader.getInstance() - override val configDir: File - get() = fabricLoader.configDir.toFile() - } + get() = fabricLoader.configDir.toFile() } diff --git a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt index 954a470..ec639c1 100644 --- a/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt +++ b/instances/fabric/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt @@ -5,67 +5,55 @@ import ru.astrainteractive.astratemplate.api.local.di.ApiLocalModule import ru.astrainteractive.astratemplate.api.remote.di.ApiRemoteModule import ru.astrainteractive.astratemplate.command.di.CommandModule import ru.astrainteractive.astratemplate.core.di.CoreModule +import ru.astrainteractive.klibs.mikro.core.dispatchers.DefaultKotlinDispatchers -interface RootModule { - val lifecycle: Lifecycle - - val fabricModule: FabricModule - - val coreModule: CoreModule - - val apiLocalModule: ApiLocalModule - - val apiRemoteModule: ApiRemoteModule - - val commandModule: CommandModule - - class Default : RootModule { - override val fabricModule: FabricModule by lazy { - FabricModule.Default() - } - - override val coreModule: CoreModule by lazy { - CoreModule( - dataFolder = fabricModule.configDir - ) - } +class RootModule { + val fabricModule: FabricModule by lazy { + FabricModule() + } - override val apiLocalModule: ApiLocalModule by lazy { - ApiLocalModule( - dataFolder = fabricModule.configDir, - configFlow = coreModule.configKrate.cachedStateFlow, - scope = coreModule.ioScope - ) - } + val coreModule: CoreModule by lazy { + CoreModule( + dataFolder = fabricModule.configDir, + dispatchers = DefaultKotlinDispatchers + ) + } - override val apiRemoteModule: ApiRemoteModule by lazy { - ApiRemoteModule() - } + val apiLocalModule: ApiLocalModule by lazy { + ApiLocalModule( + dataFolder = fabricModule.configDir, + configFlow = coreModule.configKrate.cachedStateFlow, + scope = coreModule.ioScope + ) + } - override val commandModule: CommandModule by lazy { - CommandModule.Default( - coreModule = coreModule, - apiRemoteModule = apiRemoteModule - ) - } + val apiRemoteModule: ApiRemoteModule by lazy { + ApiRemoteModule() + } - private val lifecycles: List - get() = listOf( - commandModule.lifecycle - ) + val commandModule: CommandModule by lazy { + CommandModule( + coreModule = coreModule, + apiRemoteModule = apiRemoteModule + ) + } - override val lifecycle: Lifecycle by lazy { - Lifecycle.Lambda( - onEnable = { - lifecycles.forEach(Lifecycle::onEnable) - }, - onDisable = { - lifecycles.forEach(Lifecycle::onDisable) - }, - onReload = { - lifecycles.forEach(Lifecycle::onReload) - } - ) - } + private val lifecycles: List + get() = listOf( + commandModule.lifecycle + ) + + val lifecycle: Lifecycle by lazy { + Lifecycle.Lambda( + onEnable = { + lifecycles.forEach(Lifecycle::onEnable) + }, + onDisable = { + lifecycles.forEach(Lifecycle::onDisable) + }, + onReload = { + lifecycles.forEach(Lifecycle::onReload) + } + ) } } diff --git a/instances/forge/build.gradle.kts b/instances/forge/build.gradle.kts index 4c8b9fa..d261acd 100644 --- a/instances/forge/build.gradle.kts +++ b/instances/forge/build.gradle.kts @@ -1,56 +1,42 @@ @file:Suppress("UnusedPrivateMember") import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import ru.astrainteractive.gradleplugin.model.Developer import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo plugins { kotlin("jvm") alias(libs.plugins.klibs.gradle.java.core) - id("net.minecraftforge.gradle") version ("[6.0,6.2)") + alias(libs.plugins.forgegradle) alias(libs.plugins.gradle.shadow) + alias(libs.plugins.klibs.minecraft.resource.processor) } -val shade by configurations.creating +dependencies { + minecraft( + "net.minecraftforge", + "forge", + "${libs.versions.minecraft.mojang.version.get()}-${libs.versions.minecraft.forgeversion.get()}" + ) + implementation(libs.minecraft.astralibs.core) + implementation(libs.minecraft.astralibs.core.forge) + implementation(libs.minecraft.astralibs.command) -val implementation by configurations.getting { - this.extendsFrom(shade) -} + implementation(libs.klibs.kstorage) + implementation(libs.klibs.mikro.core) -dependencies { - minecraft("net.minecraftforge:forge:1.21.4-54.0.17") - // AstraLibs - shade(libs.minecraft.astralibs.core) - shade(libs.minecraft.astralibs.command) - shade(libs.klibs.kstorage) - // Kotlin - shade(libs.bundles.kotlin) - // Local - shade(projects.modules.apiLocal) - shade(projects.modules.apiRemote) - shade(projects.modules.core) - shade(projects.modules.buildKonfig) + implementation(libs.kotlin.coroutines.core) + implementation(libs.kotlin.serialization.json) + implementation(libs.kotlin.serialization.kaml) + + implementation(projects.modules.apiLocal) + implementation(projects.modules.apiRemote) + implementation(projects.modules.core) + implementation(projects.modules.buildKonfig) } minecraft { - mappings("official", "1.20.1") - runs { - val runProperties = mapOf( - // Recommended logging data for a userdev environment. - Pair("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP"), - // Recommended logging level for the console. - Pair("forge.logging.console.level", "debug") - ) - val server by creating { - properties(runProperties) - workingDirectory(File("./build${File.separator}run")) - mods { - create(requireProjectInfo.name) { - source(sourceSets.getByName("main")) - } - } - } - } + mappings("official", libs.versions.minecraft.mojang.version.get()) + accessTransformer(rootProject.file("build").resolve("accesstransformer.cfg")) } configurations { @@ -65,35 +51,40 @@ configurations { } } -val processResources = project.tasks.withType { - filteringCharset = "UTF-8" - duplicatesStrategy = DuplicatesStrategy.INCLUDE - - from(sourceSets.main.get().resources.srcDirs) { - include("META-INF/mods.toml") - include("mods.toml") - expand( - "modId" to requireProjectInfo.name.lowercase(), - "version" to requireProjectInfo.versionString, - "description" to requireProjectInfo.description, - "displayName" to requireProjectInfo.name, - "authors" to requireProjectInfo.developersList.map(Developer::id).joinToString(",") - ) - } -} - -val destination = File("D:\\Minecraft Servers\\server-docker-forge\\data\\mods") +val destination = File("/home/makeevrsergh/Desktop/server/mods/") .takeIf(File::exists) ?: File(rootDir, "jars") val reobfShadowJar = reobf.create("shadowJar") val shadowJar by tasks.getting(ShadowJar::class) { - mustRunAfter(processResources) - dependsOn(processResources) - configurations = listOf(shade) + mergeServiceFiles() + finalizedBy(reobfShadowJar) + configurations = listOf(project.configurations.shadow.get()) + isReproducibleFileOrder = true + archiveClassifier = null as String? + archiveVersion = requireProjectInfo.versionString + archiveBaseName = "${requireProjectInfo.name}-forge" + destinationDirectory = destination dependencies { exclude(dependency("org.jetbrains:annotations")) + exclude("co/touchlab/stately/**") + exclude("club/minnced/opus/**") + exclude("com/google/**") + exclude("com/sun/**") + exclude("google/protobuf/**") + exclude("io/github/**") + exclude("io/javalin/**") + exclude("jakarta/servlet/**") + exclude("javax/annotation/**") + exclude("javax/servlet/**") + exclude("natives/**") + exclude("nl/altindag/**") + exclude("org/eclipse/**") + exclude("org/bouncycastle/**") + exclude("org/checkerframework/**") + exclude("org/conscrypt/**") + exclude("tomp2p/opuswrapper/**") exclude("DebugProbesKt.bin") exclude("_COROUTINE/**") exclude("META-INF/*.kotlin_module") @@ -101,40 +92,41 @@ val shadowJar by tasks.getting(ShadowJar::class) { exclude("META-INF/gradle-plugins/**") exclude("META-INF/maven/**") exclude("META-INF/proguard/**") - exclude("META-INF/services/**") exclude("META-INF/versions/**") + exclude("META-INF/native/**") + exclude("META-INF/**LICENCE**") } + // Be sure to relocate EXACT PACKAGES!! // For example, relocate org.some.package instead of org // Becuase relocation org will break other non-relocated dependencies such as org.minecraft listOf( + "com.fasterxml", + "net.kyori", + "org.h2", + "com.neovisionaries", + "gnu.trove", + "org.json", + "org.apache", + "org.telegram", + "okhttp3", + "net.dv8tion", "okio", "org.slf4j", "kotlin", "kotlinx", "it.krzeminski", "net.thauvin", - "org.jetbrains.exposed", + "org.jetbrains.exposed.dao", + "org.jetbrains.exposed.exceptions", + "org.jetbrains.exposed.sql", + "org.jetbrains.exposed.jdbc", "org.jetbrains.kotlin", "org.jetbrains.kotlinx", - "com.charleskorn", + "com.charleskorn.kaml", "ru.astrainteractive.klibs", "ru.astrainteractive.astralibs", + "club.minnced.discord", + "club.minnced.opus" ).forEach { pattern -> relocate(pattern, "${requireProjectInfo.group}.shade.$pattern") } - mergeServiceFiles() - manifest { - attributes( - "Specification-Title" to project.name, - "Specification-Vendor" to requireProjectInfo.developersList.first().id, - "Specification-Version" to project.version, - "Implementation-Title" to project.name, - "Implementation-Version" to project.version, - "Implementation-Vendor" to requireProjectInfo.developersList.first().id - ) - } - isReproducibleFileOrder = true - archiveClassifier.set(null as String?) - archiveBaseName.set("${requireProjectInfo.name}-forge") - destinationDirectory.set(destination) - finalizedBy(reobfShadowJar) } diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/ForgeEntryPoint.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/ForgeEntryPoint.kt index 34c70c6..abca934 100644 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/ForgeEntryPoint.kt +++ b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/ForgeEntryPoint.kt @@ -2,50 +2,54 @@ package ru.astrainteractive.astratemplate +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import net.minecraftforge.event.RegisterCommandsEvent import net.minecraftforge.event.server.ServerStartedEvent import net.minecraftforge.event.server.ServerStoppingEvent -import net.minecraftforge.eventbus.api.SubscribeEvent +import net.minecraftforge.eventbus.api.EventPriority import net.minecraftforge.fml.common.Mod -import ru.astrainteractive.astralibs.logging.JUtiltLogger -import ru.astrainteractive.astralibs.logging.Logger -import ru.astrainteractive.astratemplate.command.CommandLoader +import ru.astrainteractive.astralibs.event.flowEvent +import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astratemplate.di.RootModule -import ru.astrainteractive.astratemplate.event.core.ForgeEventBusListener +import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger +import ru.astrainteractive.klibs.mikro.core.logging.Logger import javax.annotation.ParametersAreNonnullByDefault @Mod(BuildKonfig.id) @ParametersAreNonnullByDefault class ForgeEntryPoint : - ForgeEventBusListener, + Lifecycle, Logger by JUtiltLogger("ForgeEntryPoint") { - private val rootModule: RootModule by lazy { RootModule.Default() } + private val rootModule: RootModule = RootModule() - @SubscribeEvent - fun onEnable(e: ServerStartedEvent) { - info { "#onEnable" } + override fun onEnable() { rootModule.lifecycle.onEnable() } - @SubscribeEvent - fun onDisable(e: ServerStoppingEvent) { + override fun onDisable() { info { "#onDisable" } rootModule.lifecycle.onDisable() - unregister() } - @SubscribeEvent - fun onCommandRegister(e: RegisterCommandsEvent) { - info { "#onCommandRegister" } - val commandLoader = CommandLoader() - commandLoader.registerCommands(e) - } - - fun onReload() { + override fun onReload() { rootModule.lifecycle.onReload() } - init { - register() - } + val serverStartedEvent = flowEvent(EventPriority.HIGHEST) + .onEach { + info { "#serverStartedEvent" } + onEnable() + }.launchIn(rootModule.coreModule.ioScope) + + val serverStoppingEvent = flowEvent(EventPriority.HIGHEST) + .onEach { + info { "#serverStoppingEvent" } + onDisable() + }.launchIn(rootModule.coreModule.ioScope) + + val registerCommandsEvent = flowEvent(EventPriority.HIGHEST) + .onEach { e -> + info { "#registerCommandsEvent" } + }.launchIn(rootModule.coreModule.ioScope) } diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/CommandLoader.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/CommandLoader.kt deleted file mode 100644 index 53da54d..0000000 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/CommandLoader.kt +++ /dev/null @@ -1,16 +0,0 @@ -package ru.astrainteractive.astratemplate.command - -import net.minecraftforge.event.RegisterCommandsEvent -import ru.astrainteractive.astralibs.logging.JUtiltLogger -import ru.astrainteractive.astralibs.logging.Logger -import ru.astrainteractive.astratemplate.command.core.DefaultCommandRegistry -import ru.astrainteractive.astratemplate.command.helloworld.HelloWorldCommand - -class CommandLoader : Logger by JUtiltLogger("CommandLoader") { - - fun registerCommands(event: RegisterCommandsEvent) { - info { "#registerCommands" } - val registry = DefaultCommandRegistry(event.dispatcher) - registry.register(HelloWorldCommand()) - } -} diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/Command.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/Command.kt deleted file mode 100644 index e183c17..0000000 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/Command.kt +++ /dev/null @@ -1,9 +0,0 @@ -package ru.astrainteractive.astratemplate.command.core - -import com.mojang.brigadier.context.CommandContext -import net.minecraft.commands.CommandSourceStack - -interface Command { - val alias: String - fun onCommand(commandContext: CommandContext) -} diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/CommandRegistry.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/CommandRegistry.kt deleted file mode 100644 index a23559b..0000000 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/CommandRegistry.kt +++ /dev/null @@ -1,5 +0,0 @@ -package ru.astrainteractive.astratemplate.command.core - -interface CommandRegistry { - fun register(command: Command) -} diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/DefaultCommandRegistry.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/DefaultCommandRegistry.kt deleted file mode 100644 index 6880616..0000000 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/DefaultCommandRegistry.kt +++ /dev/null @@ -1,19 +0,0 @@ -package ru.astrainteractive.astratemplate.command.core - -import com.mojang.brigadier.CommandDispatcher -import net.minecraft.commands.CommandSourceStack -import net.minecraft.commands.Commands - -class DefaultCommandRegistry( - private val dispatcher: CommandDispatcher -) : CommandRegistry { - - override fun register(command: Command) { - dispatcher.register( - Commands.literal(command.alias).executes { commandContext -> - command.onCommand(commandContext) - com.mojang.brigadier.Command.SINGLE_SUCCESS - } - ) - } -} diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/DslCommand.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/DslCommand.kt deleted file mode 100644 index 1db9a0b..0000000 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/core/DslCommand.kt +++ /dev/null @@ -1,13 +0,0 @@ -package ru.astrainteractive.astratemplate.command.core - -import com.mojang.brigadier.context.CommandContext -import net.minecraft.commands.CommandSourceStack - -class DslCommand( - override val alias: String, - private val block: (commandContext: CommandContext) -> Unit -) : Command { - override fun onCommand(commandContext: CommandContext) { - block.invoke(commandContext) - } -} diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/di/CommandModule.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/di/CommandModule.kt new file mode 100644 index 0000000..9c0bb86 --- /dev/null +++ b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/di/CommandModule.kt @@ -0,0 +1,19 @@ +package ru.astrainteractive.astratemplate.command.di + +import ru.astrainteractive.astralibs.command.registrar.ForgeCommandRegistrarContext +import ru.astrainteractive.astralibs.lifecycle.Lifecycle +import ru.astrainteractive.astratemplate.command.helloworld.HelloCommandRegistrar + +class CommandModule( + private val commandRegistrarContext: ForgeCommandRegistrarContext +) { + private val nodes = buildList { + HelloCommandRegistrar().createNode().run(::add) + } + + val lifecycle: Lifecycle = Lifecycle.Lambda( + onEnable = { + nodes.onEach(commandRegistrarContext::registerWhenReady) + } + ) +} diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/helloworld/HelloCommandRegistrar.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/helloworld/HelloCommandRegistrar.kt new file mode 100644 index 0000000..3554c1d --- /dev/null +++ b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/helloworld/HelloCommandRegistrar.kt @@ -0,0 +1,18 @@ +package ru.astrainteractive.astratemplate.command.helloworld + +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import net.minecraft.commands.CommandSourceStack +import net.minecraft.network.chat.Component +import ru.astrainteractive.astralibs.command.util.command +import ru.astrainteractive.astralibs.command.util.runs + +class HelloCommandRegistrar { + fun createNode(): LiteralArgumentBuilder { + return command("helloworld") { + runs { ctx -> + val component = Component.literal("Hello world!") + ctx.source.source.sendSystemMessage(component) + } + } + } +} diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/helloworld/HelloWorldCommand.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/helloworld/HelloWorldCommand.kt deleted file mode 100644 index 540afec..0000000 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/command/helloworld/HelloWorldCommand.kt +++ /dev/null @@ -1,11 +0,0 @@ -package ru.astrainteractive.astratemplate.command.helloworld - -import ru.astrainteractive.astratemplate.command.core.Command -import ru.astrainteractive.astratemplate.command.core.DslCommand - -class HelloWorldCommand : Command by DslCommand( - alias = "helloworld", - block = { - println("Hello from HelloWorldCommand!") - } -) diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/di/RootModule.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/di/RootModule.kt index d9ba012..022c0fa 100644 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/di/RootModule.kt +++ b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/di/RootModule.kt @@ -1,62 +1,73 @@ package ru.astrainteractive.astratemplate.di +import kotlinx.coroutines.CoroutineDispatcher +import net.minecraftforge.fml.loading.FMLPaths +import ru.astrainteractive.astralibs.command.registrar.ForgeCommandRegistrarContext +import ru.astrainteractive.astralibs.coroutine.ForgeMainDispatcher import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astratemplate.api.local.di.ApiLocalModule import ru.astrainteractive.astratemplate.api.remote.di.ApiRemoteModule +import ru.astrainteractive.astratemplate.command.di.CommandModule import ru.astrainteractive.astratemplate.core.di.CoreModule import ru.astrainteractive.astratemplate.event.di.EventModule -import java.io.File +import ru.astrainteractive.klibs.mikro.core.dispatchers.DefaultKotlinDispatchers +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers -interface RootModule { - val lifecycle: Lifecycle +class RootModule { - val coreModule: CoreModule + val coreModule: CoreModule by lazy { + CoreModule( + dataFolder = FMLPaths.CONFIGDIR.get() + .resolve("AstraTemplate") + .toAbsolutePath() + .toFile(), + dispatchers = object : KotlinDispatchers by DefaultKotlinDispatchers { + override val Main: CoroutineDispatcher = ForgeMainDispatcher + } + ) + } - val apiLocalModule: ApiLocalModule + val apiLocalModule: ApiLocalModule by lazy { + ApiLocalModule( + dataFolder = coreModule.dataFolder, + configFlow = coreModule.configKrate.cachedStateFlow, + scope = coreModule.ioScope + ) + } - val apiRemoteModule: ApiRemoteModule + val apiRemoteModule: ApiRemoteModule by lazy { + ApiRemoteModule() + } - val eventsModule: EventModule + val commandModule by lazy { + CommandModule( + commandRegistrarContext = ForgeCommandRegistrarContext( + mainScope = coreModule.mainScope + ) + ) + } - class Default : RootModule { + val eventsModule: EventModule by lazy { + EventModule(coreModule = coreModule) + } - override val coreModule: CoreModule by lazy { - CoreModule( - dataFolder = File("./") - ) - } + private val lifecycles: List + get() = listOf( + eventsModule.lifecycle, + commandModule.lifecycle + ) - override val apiLocalModule: ApiLocalModule by lazy { - ApiLocalModule( - dataFolder = File("./"), - configFlow = coreModule.configKrate.cachedStateFlow, - scope = coreModule.ioScope - ) - } - - override val apiRemoteModule: ApiRemoteModule by lazy { - ApiRemoteModule() - } - - override val eventsModule: EventModule by lazy { - EventModule.Default() - } - - private val lifecycles: List - get() = listOf(eventsModule.lifecycle) - - override val lifecycle: Lifecycle by lazy { - Lifecycle.Lambda( - onEnable = { - lifecycles.forEach(Lifecycle::onEnable) - }, - onDisable = { - lifecycles.forEach(Lifecycle::onDisable) - }, - onReload = { - lifecycles.forEach(Lifecycle::onReload) - } - ) - } + val lifecycle: Lifecycle by lazy { + Lifecycle.Lambda( + onEnable = { + lifecycles.forEach(Lifecycle::onEnable) + }, + onDisable = { + lifecycles.forEach(Lifecycle::onDisable) + }, + onReload = { + lifecycles.forEach(Lifecycle::onReload) + } + ) } } diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/TickEvent.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/TickEvent.kt index 2a9865c..9679a8f 100644 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/TickEvent.kt +++ b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/TickEvent.kt @@ -1,14 +1,18 @@ package ru.astrainteractive.astratemplate.event +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import net.minecraftforge.event.TickEvent -import net.minecraftforge.eventbus.api.SubscribeEvent -import ru.astrainteractive.astratemplate.event.core.ForgeEventBusListener +import ru.astrainteractive.astralibs.event.flowEvent +import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger +import ru.astrainteractive.klibs.mikro.core.logging.Logger -class TickEvent : ForgeEventBusListener { +class TickEvent( + mainScope: CoroutineScope +) : Logger by JUtiltLogger("AstraTemplate-TickEvent") { - @SubscribeEvent - @Suppress("UnusedPrivateMember") - fun onTickEvent(e: TickEvent) { - println("Tick happened!") - } + val serverStartedEvent = flowEvent() + .onEach { info { "#serverStartedEvent" } } + .launchIn(mainScope) } diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/core/ForgeEventBusListener.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/core/ForgeEventBusListener.kt deleted file mode 100644 index 20368d6..0000000 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/core/ForgeEventBusListener.kt +++ /dev/null @@ -1,14 +0,0 @@ -package ru.astrainteractive.astratemplate.event.core - -import net.minecraftforge.common.MinecraftForge - -interface ForgeEventBusListener { - - fun register() { - MinecraftForge.EVENT_BUS.register(this) - } - - fun unregister() { - MinecraftForge.EVENT_BUS.unregister(this) - } -} diff --git a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/di/EventModule.kt b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/di/EventModule.kt index 1c09ef2..992ddf9 100644 --- a/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/di/EventModule.kt +++ b/instances/forge/src/main/java/ru/astrainteractive/astratemplate/event/di/EventModule.kt @@ -1,27 +1,11 @@ package ru.astrainteractive.astratemplate.event.di import ru.astrainteractive.astralibs.lifecycle.Lifecycle +import ru.astrainteractive.astratemplate.core.di.CoreModule import ru.astrainteractive.astratemplate.event.TickEvent -import ru.astrainteractive.astratemplate.event.core.ForgeEventBusListener -interface EventModule { - val lifecycle: Lifecycle - - class Default : EventModule { - private val events: List by lazy { - listOf( - TickEvent() - ) - } - override val lifecycle: Lifecycle by lazy { - Lifecycle.Lambda( - onEnable = { - events.forEach(ForgeEventBusListener::register) - }, - onDisable = { - events.forEach(ForgeEventBusListener::unregister) - } - ) - } - } +class EventModule(coreModule: CoreModule) { + @Suppress("UnusedPrivateProperty") + private val tickEvent = TickEvent(coreModule.mainScope) + val lifecycle: Lifecycle = Lifecycle.Empty } diff --git a/instances/velocity/build.gradle.kts b/instances/velocity/build.gradle.kts index cbdd025..8a7ca3f 100644 --- a/instances/velocity/build.gradle.kts +++ b/instances/velocity/build.gradle.kts @@ -1,51 +1,89 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.kotlin.dsl.named import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo plugins { kotlin("jvm") alias(libs.plugins.gradle.shadow) alias(libs.plugins.gradle.buildconfig) - alias(libs.plugins.klibs.minecraft.shadow) alias(libs.plugins.klibs.minecraft.resource.processor) } dependencies { - implementation(libs.bundles.kotlin) - // AstraLibs + implementation(libs.kotlin.coroutines.core) + implementation(libs.kotlin.serialization.json) + implementation(libs.kotlin.serialization.kaml) implementation(libs.minecraft.astralibs.core) implementation(libs.minecraft.astralibs.command) + implementation(libs.klibs.kstorage) - // Velocity + implementation(libs.klibs.mikro.core) + compileOnly(libs.minecraft.velocity.api) annotationProcessor(libs.minecraft.velocity.api) - // Local + implementation(projects.modules.core) implementation(projects.modules.buildKonfig) } minecraftProcessResource { - velocity() + velocity( + customProperties = mapOf( + "dependencies" to listOf( + libs.driver.h2.get(), + libs.driver.jdbc.get(), + libs.driver.mysql.get(), + ).joinToString("\",\"", "[\"", "\"]") + ) + ) } -astraShadowJar { - requireShadowJarTask { - destination = File("/home/makeevrserg/Desktop/server/data/plugins") - .takeIf { it.exists() } - ?: File(rootDir, "jars") - - val projectInfo = requireProjectInfo - isReproducibleFileOrder = true - mergeServiceFiles() - dependsOn(configurations) - archiveClassifier.set(null as String?) - relocate("org.bstats", projectInfo.group) - - minimize { - exclude(dependency(libs.exposed.jdbc.get())) - exclude(dependency(libs.exposed.dao.get())) - exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib:${libs.versions.kotlin.version.get()}")) +val shadowJar = tasks.named("shadowJar") +shadowJar.configure { + + val projectInfo = requireProjectInfo + isReproducibleFileOrder = true + mergeServiceFiles() + dependsOn(configurations) + archiveClassifier.set(null as String?) + + minimize { + exclude(dependency(libs.exposed.jdbc.get())) + exclude(dependency(libs.exposed.dao.get())) + } + archiveVersion.set(projectInfo.versionString) + archiveBaseName.set("${projectInfo.name}-velocity") + destinationDirectory = rootDir.resolve("build") + .resolve("velocity") + .resolve("plugins") + .takeIf(File::exists) + ?: File(rootDir, "jars").also(File::mkdirs) + + relocate("org.bstats", projectInfo.group) + listOf( + "co.touchlab", + "com.mysql", + "google.protobuf", + "io.github.reactivecircus", + "ch.qos.logback", + "com.charleskorn.kaml", + "com.ibm.icu", + "it.krzeminski.snakeyaml", + "net.thauvin.erik", + "okio", + "org.apache", + "org.intellij", + "org.slf4j", + "org.jetbrains.annotations", + "ru.astrainteractive.klibs", + "ru.astrainteractive.astralibs" + ).forEach { pattern -> relocate(pattern, "${projectInfo.group}.$pattern") } + listOf( + "org.jetbrains.exposed", + "kotlinx", + ).forEach { pattern -> + relocate(pattern, "${projectInfo.group}.$pattern") { + exclude("kotlin/kotlin.kotlin_builtins") } - archiveVersion.set(projectInfo.versionString) - archiveBaseName.set("${projectInfo.name}-velocity") - destinationDirectory.set(destination.get()) } } diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt index 804d1ac..1e8c41e 100644 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt +++ b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt @@ -10,11 +10,11 @@ import com.velocitypowered.api.plugin.Plugin import com.velocitypowered.api.plugin.annotation.DataDirectory import com.velocitypowered.api.proxy.ProxyServer import ru.astrainteractive.astralibs.lifecycle.Lifecycle -import ru.astrainteractive.astralibs.logging.JUtiltLogger -import ru.astrainteractive.astralibs.logging.Logger import ru.astrainteractive.astratemplate.command.api.VelocityCommandRegistryContext import ru.astrainteractive.astratemplate.command.reload.ReloadCommandRegistry -import ru.astrainteractive.astratemplate.di.impl.RootModuleImpl +import ru.astrainteractive.astratemplate.di.RootModule +import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger +import ru.astrainteractive.klibs.mikro.core.logging.Logger import java.nio.file.Path import org.slf4j.Logger as Slf4jLogger @@ -33,8 +33,8 @@ class AstraTemplate @Inject constructor( private val logger: Slf4jLogger, @DataDirectory private val dataDirectory: Path -) : Logger by JUtiltLogger("AstraTemplate") { - private val rootModule = RootModuleImpl() +) : Logger by JUtiltLogger("AstraTemplate").withoutParentHandlers() { + private val rootModule = RootModule() private val lifecycles: List get() = listOf( rootModule.coreModule.lifecycle, diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandContext.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandContext.kt deleted file mode 100644 index cd2ec9f..0000000 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandContext.kt +++ /dev/null @@ -1,10 +0,0 @@ -package ru.astrainteractive.astratemplate.command.api - -import com.velocitypowered.api.command.CommandSource -import ru.astrainteractive.astralibs.command.api.context.CommandContext - -class VelocityCommandContext( - val alias: String, - val source: CommandSource, - val arguments: Array -) : CommandContext diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandRegistry.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandRegistry.kt new file mode 100644 index 0000000..d18d6f7 --- /dev/null +++ b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandRegistry.kt @@ -0,0 +1,22 @@ +package ru.astrainteractive.astratemplate.command.api + +import com.velocitypowered.api.command.SimpleCommand + +fun VelocityCommandRegistryContext.registerCommand( + alias: String, + parse: (SimpleCommand.Invocation) -> Result, + onSuccess: (T) -> Unit, + onFailure: (SimpleCommand.Invocation, Throwable) -> Unit = { _, _ -> } +) { + val commandMeta = this.proxyServer.commandManager + .metaBuilder(alias) + .aliases(alias) + .plugin(this.plugin) + .build() + val velocityCommand = SimpleCommand { ctx -> + parse.invoke(ctx) + .onFailure { throwable -> onFailure.invoke(ctx, throwable) } + .onSuccess { result -> onSuccess.invoke(result) } + } + proxyServer.commandManager.register(commandMeta, velocityCommand) +} diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandRegistryContext.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandRegistryContext.kt index e61a5ac..9cd7b9d 100644 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandRegistryContext.kt +++ b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/api/VelocityCommandRegistryContext.kt @@ -1,10 +1,9 @@ package ru.astrainteractive.astratemplate.command.api import com.velocitypowered.api.proxy.ProxyServer -import ru.astrainteractive.astralibs.command.api.context.CommandContext import ru.astrainteractive.astratemplate.AstraTemplate class VelocityCommandRegistryContext( val proxyServer: ProxyServer, val plugin: AstraTemplate -) : CommandContext +) diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/ReloadCommandRegistry.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/ReloadCommandRegistry.kt index aba2d07..c6aa8b5 100644 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/ReloadCommandRegistry.kt +++ b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/ReloadCommandRegistry.kt @@ -1,14 +1,11 @@ package ru.astrainteractive.astratemplate.command.reload import com.velocitypowered.api.command.CommandSource +import com.velocitypowered.api.command.SimpleCommand import net.kyori.adventure.text.Component -import ru.astrainteractive.astralibs.command.api.error.ErrorHandler import ru.astrainteractive.astralibs.command.api.exception.CommandException -import ru.astrainteractive.astralibs.command.api.executor.CommandExecutor -import ru.astrainteractive.astralibs.command.api.parser.CommandParser -import ru.astrainteractive.astratemplate.command.api.VelocityCommandContext import ru.astrainteractive.astratemplate.command.api.VelocityCommandRegistryContext -import ru.astrainteractive.astratemplate.command.reload.VelocityCommandRegistry.registerCommand +import ru.astrainteractive.astratemplate.command.api.registerCommand import ru.astrainteractive.astratemplate.core.plugin.PluginPermission class ReloadCommandRegistry(private val registryContext: VelocityCommandRegistryContext) { @@ -18,42 +15,38 @@ class ReloadCommandRegistry(private val registryContext: VelocityCommandRegistry data class Success(val source: CommandSource) : Result } - sealed class Error(message: String) : CommandException(message) { - data object WrongUsage : Error("WrongUsage") - data object NoPermission : Error("NoPermission") + sealed class ReloadException(message: String) : CommandException(message) { + class WrongUsage : ReloadException("WrongUsage") + class NoPermission : ReloadException("NoPermission") } } - private inner class CommandExecutorImpl : CommandExecutor { - override fun execute(result: ReloadCommand.Result) { - if (result !is ReloadCommand.Result.Success) return - result.source.sendMessage(Component.text("Success")) - registryContext.plugin.reload() - } + private fun execute(result: ReloadCommand.Result) { + if (result !is ReloadCommand.Result.Success) return + result.source.sendMessage(Component.text("Success")) + registryContext.plugin.reload() } - private inner class CommandParserImpl : CommandParser { - override fun parse(commandContext: VelocityCommandContext): ReloadCommand.Result { - if (!commandContext.source.hasPermission(PluginPermission.Reload.value)) { - throw ReloadCommand.Error.NoPermission + private fun parse(ctx: SimpleCommand.Invocation): Result { + return runCatching { + if (!ctx.source().hasPermission(PluginPermission.Reload.value)) { + throw ReloadCommand.ReloadException.NoPermission() } - if (commandContext.arguments.isNotEmpty()) { - throw ReloadCommand.Error.WrongUsage + if (ctx.arguments().isNotEmpty()) { + throw ReloadCommand.ReloadException.WrongUsage() } - return ReloadCommand.Result.Success(commandContext.source) + ReloadCommand.Result.Success(ctx.source()) } } - private inner class ErrorHandlerImpl : ErrorHandler { - override fun handle(commandContext: VelocityCommandContext, throwable: Throwable) { - when (throwable) { - ReloadCommand.Error.NoPermission -> { - commandContext.source.sendMessage(Component.text("No permission")) - } + private fun handle(ctx: SimpleCommand.Invocation, throwable: Throwable) { + when (throwable) { + is ReloadCommand.ReloadException.NoPermission -> { + ctx.source().sendMessage(Component.text("No permission")) + } - ReloadCommand.Error.WrongUsage -> { - commandContext.source.sendMessage(Component.text("Wrong usage")) - } + is ReloadCommand.ReloadException.WrongUsage -> { + ctx.source().sendMessage(Component.text("Wrong usage")) } } } @@ -61,9 +54,9 @@ class ReloadCommandRegistry(private val registryContext: VelocityCommandRegistry fun register() { registryContext.registerCommand( alias = "reload", - commandParser = CommandParserImpl(), - commandExecutor = CommandExecutorImpl(), - errorHandler = ErrorHandlerImpl() + parse = ::parse, + onSuccess = ::execute, + onFailure = ::handle ) } } diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/VelocityCommandRegistry.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/VelocityCommandRegistry.kt deleted file mode 100644 index 34e22a2..0000000 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/command/reload/VelocityCommandRegistry.kt +++ /dev/null @@ -1,37 +0,0 @@ -package ru.astrainteractive.astratemplate.command.reload - -import com.velocitypowered.api.command.SimpleCommand -import ru.astrainteractive.astralibs.command.api.error.ErrorHandler -import ru.astrainteractive.astralibs.command.api.executor.CommandExecutor -import ru.astrainteractive.astralibs.command.api.parser.CommandParser -import ru.astrainteractive.astratemplate.command.api.VelocityCommandContext -import ru.astrainteractive.astratemplate.command.api.VelocityCommandRegistryContext - -object VelocityCommandRegistry { - fun VelocityCommandRegistryContext.registerCommand( - alias: String, - commandParser: CommandParser, - commandExecutor: CommandExecutor, - errorHandler: ErrorHandler - ) { - val commandMeta = this.proxyServer.commandManager - .metaBuilder(alias) - .aliases(alias) - .plugin(this.plugin) - .build() - val velocityCommand = SimpleCommand { invocation -> - val commandContext = VelocityCommandContext( - alias = invocation.alias(), - source = invocation.source(), - arguments = invocation.arguments() - ) - try { - val result = commandParser.parse(commandContext) - commandExecutor.execute(result) - } catch (throwable: Throwable) { - errorHandler.handle(commandContext, throwable) - } - } - proxyServer.commandManager.register(commandMeta, velocityCommand) - } -} diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt index 67fd24d..d2351a1 100644 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt +++ b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/RootModule.kt @@ -1,8 +1,15 @@ package ru.astrainteractive.astratemplate.di import ru.astrainteractive.astratemplate.core.di.CoreModule +import ru.astrainteractive.klibs.mikro.core.dispatchers.DefaultKotlinDispatchers -interface RootModule { - val velocityModule: VelocityModule - val coreModule: CoreModule +class RootModule { + val velocityModule = VelocityModule() + + val coreModule: CoreModule by lazy { + CoreModule( + dataFolder = velocityModule.dataDirectory.toFile(), + dispatchers = DefaultKotlinDispatchers + ) + } } diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/VelocityModule.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/VelocityModule.kt index cec90a8..1bf152e 100644 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/VelocityModule.kt +++ b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/VelocityModule.kt @@ -6,10 +6,10 @@ import org.slf4j.Logger import ru.astrainteractive.astratemplate.AstraTemplate import java.nio.file.Path -interface VelocityModule { - val injector: Injector - val server: ProxyServer - val plugin: AstraTemplate - val logger: Logger - val dataDirectory: Path +class VelocityModule { + lateinit var injector: Injector + lateinit var server: ProxyServer + lateinit var plugin: AstraTemplate + lateinit var logger: Logger + lateinit var dataDirectory: Path } diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/impl/RootModuleImpl.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/impl/RootModuleImpl.kt deleted file mode 100644 index bc5d822..0000000 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/impl/RootModuleImpl.kt +++ /dev/null @@ -1,13 +0,0 @@ -package ru.astrainteractive.astratemplate.di.impl - -import ru.astrainteractive.astratemplate.core.di.CoreModule -import ru.astrainteractive.astratemplate.di.RootModule - -class RootModuleImpl : RootModule { - - override val velocityModule = VelocityModuleImpl() - - override val coreModule: CoreModule by lazy { - CoreModule(velocityModule.dataDirectory.toFile()) - } -} diff --git a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/impl/VelocityModuleImpl.kt b/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/impl/VelocityModuleImpl.kt deleted file mode 100644 index 0db82f5..0000000 --- a/instances/velocity/src/main/kotlin/ru/astrainteractive/astratemplate/di/impl/VelocityModuleImpl.kt +++ /dev/null @@ -1,16 +0,0 @@ -package ru.astrainteractive.astratemplate.di.impl - -import com.google.inject.Injector -import com.velocitypowered.api.proxy.ProxyServer -import org.slf4j.Logger -import ru.astrainteractive.astratemplate.AstraTemplate -import ru.astrainteractive.astratemplate.di.VelocityModule -import java.nio.file.Path - -class VelocityModuleImpl : VelocityModule { - override lateinit var injector: Injector - override lateinit var server: ProxyServer - override lateinit var plugin: AstraTemplate - override lateinit var logger: Logger - override lateinit var dataDirectory: Path -} diff --git a/instances/velocity/src/main/resources/config.yml b/instances/velocity/src/main/resources/config.yml deleted file mode 100644 index e8436a3..0000000 --- a/instances/velocity/src/main/resources/config.yml +++ /dev/null @@ -1,13 +0,0 @@ -# First line description for config1 -# Second line description for config2 -config1: "NONE" -# Some description for config2 -config2: 0 -config3: false -section: - # Description for value1 - value1: "NONE" - value2: -1 -list: [] -# Description for list -another_list: [] \ No newline at end of file diff --git a/instances/velocity/src/main/resources/translations.yml b/instances/velocity/src/main/resources/translations.yml deleted file mode 100644 index 3806567..0000000 --- a/instances/velocity/src/main/resources/translations.yml +++ /dev/null @@ -1,23 +0,0 @@ -database: - success: "dbd1Успешно подключено к базе данных" - fail: "&#db2c18Нет подключения к базе данных" -menu: - title: "dbd1Меню" - add_player: "dbd1Добавить игрока" - first_page: "&#dbbb18Вы на первой странице" - last_page: "&#dbbb18Вы на последней странице" - prev_page: "dbd1Пред. страницы" - next_page: "dbd1След. страница" - back: "dbd1Назад" - close: "dbd1Закрыть)" -custom: - block_placed: "dbd1Блок поставлен!" - no_player_name: "&#db2c18Вы не ввели имя игрока!" - damaged: "&#db2c18Вас продамажил игрок %player%!" - damage_hint: "" -general: - prefix: "dbd1[EmpireItems]" - reload: "&#dbbb18Перезагрузка плагина" - reload_complete: "*f596Перезагрузка успешно завершена" - no_permission: "&#db2c18У вас нет прав!" - getByByCheck: "&#db2c18getByByChecфывыфвk" \ No newline at end of file diff --git a/instances/velocity/src/main/resources/velocity-plugin.json b/instances/velocity/src/main/resources/velocity-plugin.json index 8636b02..576630e 100644 --- a/instances/velocity/src/main/resources/velocity-plugin.json +++ b/instances/velocity/src/main/resources/velocity-plugin.json @@ -6,6 +6,8 @@ "authors": [ "${authors}" ], - "dependencies": [], + "dependencies": [ + "${dependencies}" + ], "main": "${main}" } \ No newline at end of file diff --git a/modules/api-local/build.gradle.kts b/modules/api-local/build.gradle.kts index 98eaf1d..267b141 100644 --- a/modules/api-local/build.gradle.kts +++ b/modules/api-local/build.gradle.kts @@ -3,17 +3,17 @@ plugins { } dependencies { - // Kotlin - implementation(libs.bundles.kotlin) - // AstraLibs + implementation(libs.kotlin.coroutines.core) + implementation(libs.kotlin.serialization.json) + implementation(libs.kotlin.serialization.kaml) + implementation(libs.minecraft.astralibs.core) - implementation(libs.minecraft.astralibs.exposed) - // mikro + implementation(libs.klibs.kstorage) - // Exposed - implementation(libs.bundles.exposed) - // klibs implementation(libs.klibs.mikro.core) - // Local + implementation(libs.klibs.mikro.extensions) + + implementation(libs.exposed.core) + implementation(projects.modules.core) } diff --git a/modules/api-local/src/main/kotlin/ru/astrainteractive/astratemplate/api/local/di/ApiLocalModule.kt b/modules/api-local/src/main/kotlin/ru/astrainteractive/astratemplate/api/local/di/ApiLocalModule.kt index 4113351..0b6a420 100644 --- a/modules/api-local/src/main/kotlin/ru/astrainteractive/astratemplate/api/local/di/ApiLocalModule.kt +++ b/modules/api-local/src/main/kotlin/ru/astrainteractive/astratemplate/api/local/di/ApiLocalModule.kt @@ -13,8 +13,6 @@ import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger import org.jetbrains.exposed.sql.addLogger import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transaction -import ru.astrainteractive.astralibs.exposed.model.DatabaseConfiguration -import ru.astrainteractive.astralibs.exposed.model.connect import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astratemplate.api.local.dao.LocalDao import ru.astrainteractive.astratemplate.api.local.dao.LocalDaoImpl @@ -22,6 +20,8 @@ import ru.astrainteractive.astratemplate.api.local.entity.UserRatingTable import ru.astrainteractive.astratemplate.api.local.entity.UserTable import ru.astrainteractive.astratemplate.core.plugin.PluginConfiguration import ru.astrainteractive.klibs.mikro.core.coroutines.mapCached +import ru.astrainteractive.klibs.mikro.exposed.model.DatabaseConfiguration +import ru.astrainteractive.klibs.mikro.exposed.util.connect import java.io.File class ApiLocalModule( @@ -29,14 +29,15 @@ class ApiLocalModule( configFlow: Flow, scope: CoroutineScope ) { - private val databaseFlow = configFlow .map { it.database } .distinctUntilChanged() .mapCached(scope) { config, previous: Database? -> previous?.connector?.invoke()?.close() previous?.run(TransactionManager::closeAndUnregister) - val database = DatabaseConfiguration.H2("users_db").connect(dataFolder) + val database = dataFolder.resolve("users_db").absolutePath + .let(DatabaseConfiguration::H2) + .connect() TransactionManager.manager.defaultIsolationLevel = java.sql.Connection.TRANSACTION_SERIALIZABLE transaction(database) { addLogger(Slf4jSqlDebugLogger) diff --git a/modules/api-remote/build.gradle.kts b/modules/api-remote/build.gradle.kts index d3623c6..c1abea4 100644 --- a/modules/api-remote/build.gradle.kts +++ b/modules/api-remote/build.gradle.kts @@ -4,6 +4,7 @@ plugins { } dependencies { - // Kotlin - implementation(libs.bundles.kotlin) + implementation(libs.kotlin.coroutines.core) + implementation(libs.kotlin.serialization.json) + implementation(libs.kotlin.serialization.kaml) } diff --git a/modules/build-konfig/build.gradle.kts b/modules/build-konfig/build.gradle.kts index 4634a7c..278f4df 100644 --- a/modules/build-konfig/build.gradle.kts +++ b/modules/build-konfig/build.gradle.kts @@ -1,6 +1,5 @@ import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo - plugins { kotlin("jvm") alias(libs.plugins.gradle.buildconfig) diff --git a/modules/core/build.gradle.kts b/modules/core/build.gradle.kts index 3791e92..9de3469 100644 --- a/modules/core/build.gradle.kts +++ b/modules/core/build.gradle.kts @@ -4,13 +4,13 @@ plugins { } dependencies { - // Kotlin - implementation(libs.bundles.kotlin) - // AstraLibs + implementation(libs.kotlin.coroutines.core) + implementation(libs.kotlin.serialization.json) + implementation(libs.kotlin.serialization.kaml) + implementation(libs.minecraft.astralibs.core) - implementation(libs.minecraft.astralibs.exposed) - implementation(libs.klibs.kstorage) - // Test - testImplementation(libs.bundles.testing.kotlin) - testImplementation(libs.tests.kotlin.test) + + implementation(libs.klibs.mikro.core) + implementation(libs.klibs.mikro.extensions) + api(libs.klibs.kstorage) } diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/di/CoreModule.kt b/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/di/CoreModule.kt index 2e73d8e..508195e 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/di/CoreModule.kt +++ b/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/di/CoreModule.kt @@ -1,22 +1,29 @@ package ru.astrainteractive.astratemplate.core.di -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.cancel -import ru.astrainteractive.astralibs.async.CoroutineFeature +import ru.astrainteractive.astralibs.async.withTimings import ru.astrainteractive.astralibs.lifecycle.Lifecycle -import ru.astrainteractive.astralibs.serialization.StringFormatExt.parseOrWriteIntoDefault -import ru.astrainteractive.astralibs.serialization.YamlStringFormat +import ru.astrainteractive.astralibs.util.YamlStringFormat +import ru.astrainteractive.astralibs.util.parseOrWriteIntoDefault import ru.astrainteractive.astratemplate.core.plugin.PluginConfiguration import ru.astrainteractive.astratemplate.core.plugin.PluginTranslation import ru.astrainteractive.klibs.kstorage.api.impl.DefaultMutableKrate import ru.astrainteractive.klibs.kstorage.util.asCachedKrate import ru.astrainteractive.klibs.kstorage.util.asStateFlowKrate +import ru.astrainteractive.klibs.mikro.core.coroutines.CoroutineFeature +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers import java.io.File -class CoreModule(dataFolder: File) { +class CoreModule( + val dataFolder: File, + val dispatchers: KotlinDispatchers +) { val yamlStringFormat = YamlStringFormat() - val ioScope = CoroutineFeature.Default(Dispatchers.IO) + val ioScope = CoroutineFeature.IO.withTimings() + val mainScope = CoroutineFeature + .Default(dispatchers.Main) + .withTimings() val translationKrate = DefaultMutableKrate( factory = ::PluginTranslation, diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginConfiguration.kt b/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginConfiguration.kt index a73d6fc..f99b311 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginConfiguration.kt +++ b/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginConfiguration.kt @@ -3,11 +3,8 @@ package ru.astrainteractive.astratemplate.core.plugin import com.charleskorn.kaml.YamlComment import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import ru.astrainteractive.astralibs.exposed.model.DatabaseConfiguration +import ru.astrainteractive.klibs.mikro.exposed.model.DatabaseConfiguration -/** - * Example config file with kotlinx.serialization - */ @Serializable data class PluginConfiguration( @YamlComment("First line description for config1", "Second line description for config2") diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginPermission.kt b/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginPermission.kt index 3cc07c8..6f70e86 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginPermission.kt +++ b/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginPermission.kt @@ -2,9 +2,6 @@ package ru.astrainteractive.astratemplate.core.plugin import ru.astrainteractive.astralibs.permission.Permission -/** - * Permissions sealed itnerface - */ sealed class PluginPermission(override val value: String) : Permission { data object Reload : PluginPermission("astra_template.reload") data object Damage : PluginPermission("astra_template.damage") diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginTranslation.kt b/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginTranslation.kt index eb8cc4d..4769307 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginTranslation.kt +++ b/modules/core/src/main/kotlin/ru/astrainteractive/astratemplate/core/plugin/PluginTranslation.kt @@ -9,7 +9,7 @@ import ru.astrainteractive.astralibs.string.replace /** * All translation stored here - * Each translation have default value so it's not necesarry to fetch it from resources + * Each translation have default value so it's not necessary to fetch it from resources */ @Serializable class PluginTranslation(