Skip to content

Commit ed58d0b

Browse files
authored
Merge pull request #85 from Astra-Interactive/improvements
## Summary - Updated commands api - Updated shadow - Updated modules structure
2 parents bfdde95 + a8b4c33 commit ed58d0b

File tree

73 files changed

+1037
-1137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1037
-1137
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ modules/api-local/build
1111
modules/api-remote/build
1212
modules/dto/build
1313
# instances
14-
instances/fabric
15-
instances/forge
16-
instances/plugin
17-
instances/velocity
14+
instances/fabric/build
15+
instances/forge/build
16+
instances/plugin/build
17+
instances/velocity/build

build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ plugins {
44
`java-library`
55
alias(libs.plugins.kotlin.jvm) apply false
66
alias(libs.plugins.kotlin.serialization) apply false
7-
alias(libs.plugins.minecraft.fabric.loom) apply false
87
alias(libs.plugins.gradle.buildconfig) apply false
9-
alias(libs.plugins.gradle.shadow) apply false
108

119
// klibs - core
1210
alias(libs.plugins.klibs.gradle.detekt) apply false
@@ -16,7 +14,6 @@ plugins {
1614
alias(libs.plugins.klibs.gradle.java.core) apply false
1715
alias(libs.plugins.klibs.gradle.publication) apply false
1816
alias(libs.plugins.klibs.gradle.rootinfo) apply false
19-
alias(libs.plugins.klibs.minecraft.shadow) apply false
2017
alias(libs.plugins.klibs.minecraft.resource.processor) apply false
2118
}
2219

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ makeevrserg.java.ktarget=21
99
# Project
1010
makeevrserg.project.name=AstraTemplate
1111
makeevrserg.project.group=ru.astrainteractive.astratemplate
12-
makeevrserg.project.version.string=7.8.0
12+
makeevrserg.project.version.string=8.0.0-alpha01
1313
makeevrserg.project.description=Template plugin for EmpireProjekt
1414
makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com
1515
makeevrserg.project.url=https://github.com/Astra-Interactive/AstraTemplate

gradle/libs.versions.toml

Lines changed: 139 additions & 121 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

instances/bukkit/build.gradle.kts

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import org.gradle.kotlin.dsl.named
13
import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo
24

5+
36
plugins {
47
kotlin("jvm")
58
alias(libs.plugins.klibs.gradle.java.core)
6-
alias(libs.plugins.klibs.minecraft.shadow)
79
alias(libs.plugins.klibs.minecraft.resource.processor)
10+
alias(libs.plugins.gradle.shadow)
811
}
912

1013
dependencies {
1114
// Kotlin
12-
implementation(libs.bundles.kotlin)
15+
implementation(libs.kotlin.coroutines.core)
16+
implementation(libs.kotlin.serialization.json)
17+
implementation(libs.kotlin.serialization.kaml)
1318
// AstraLibs
1419
implementation(libs.minecraft.astralibs.core)
1520
implementation(libs.minecraft.astralibs.command)
@@ -28,29 +33,63 @@ dependencies {
2833
}
2934

3035
minecraftProcessResource {
31-
bukkit()
36+
bukkit(
37+
customProperties = mapOf(
38+
"libraries" to listOf(
39+
libs.driver.h2.get(),
40+
libs.driver.jdbc.get(),
41+
libs.driver.mysql.get(),
42+
).joinToString("\",\"", "[\"", "\"]")
43+
)
44+
)
3245
}
3346

34-
astraShadowJar {
35-
requireShadowJarTask {
36-
destination = File("/home/makeevrserg/Desktop/git/AstraTemplate/build/bukkit/plugins/")
37-
.takeIf { it.exists() }
38-
?: File(rootDir, "jars")
39-
40-
val projectInfo = requireProjectInfo
41-
isReproducibleFileOrder = true
42-
mergeServiceFiles()
43-
dependsOn(configurations)
44-
archiveClassifier.set(null as String?)
45-
relocate("org.bstats", projectInfo.group)
46-
47-
minimize {
48-
exclude(dependency(libs.exposed.jdbc.get()))
49-
exclude(dependency(libs.exposed.dao.get()))
50-
exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib:${libs.versions.kotlin.version.get()}"))
47+
val shadowJar = tasks.named<ShadowJar>("shadowJar")
48+
shadowJar.configure {
49+
50+
val projectInfo = requireProjectInfo
51+
isReproducibleFileOrder = true
52+
mergeServiceFiles()
53+
dependsOn(configurations)
54+
archiveClassifier.set(null as String?)
55+
56+
minimize {
57+
exclude(dependency(libs.exposed.jdbc.get()))
58+
exclude(dependency(libs.exposed.dao.get()))
59+
}
60+
archiveVersion.set(projectInfo.versionString)
61+
archiveBaseName.set("${projectInfo.name}-bukkit")
62+
destinationDirectory = rootDir.resolve("build")
63+
.resolve("bukkit")
64+
.resolve("plugins")
65+
.takeIf(File::exists)
66+
?: File(rootDir, "jars").also(File::mkdirs)
67+
68+
relocate("org.bstats", projectInfo.group)
69+
listOf(
70+
"co.touchlab",
71+
"com.mysql",
72+
"google.protobuf",
73+
"io.github.reactivecircus",
74+
"ch.qos.logback",
75+
"com.charleskorn.kaml",
76+
"com.ibm.icu",
77+
"it.krzeminski.snakeyaml",
78+
"net.thauvin.erik",
79+
"okio",
80+
"org.apache",
81+
"org.intellij",
82+
"org.slf4j",
83+
"org.jetbrains.annotations",
84+
"ru.astrainteractive.klibs",
85+
"ru.astrainteractive.astralibs"
86+
).forEach { pattern -> relocate(pattern, "${projectInfo.group}.$pattern") }
87+
listOf(
88+
"org.jetbrains.exposed",
89+
"kotlinx",
90+
).forEach { pattern ->
91+
relocate(pattern, "${projectInfo.group}.$pattern") {
92+
exclude("kotlin/kotlin.kotlin_builtins")
5193
}
52-
archiveVersion.set(projectInfo.versionString)
53-
archiveBaseName.set("${projectInfo.name}-bukkit")
54-
destinationDirectory.set(destination.get())
5594
}
5695
}

instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/AstraTemplate.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package ru.astrainteractive.astratemplate
22

3-
import org.bukkit.plugin.java.JavaPlugin
4-
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
5-
import ru.astrainteractive.astralibs.logging.JUtiltLogger
6-
import ru.astrainteractive.astralibs.logging.Logger
3+
import ru.astrainteractive.astralibs.lifecycle.LifecyclePlugin
74
import ru.astrainteractive.astratemplate.di.RootModule
5+
import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger
6+
import ru.astrainteractive.klibs.mikro.core.logging.Logger
87

98
/**
109
* Initial class for your plugin
1110
*/
1211

1312
class AstraTemplate :
14-
JavaPlugin(),
15-
Logger by JUtiltLogger("AstraTemplate"),
16-
Lifecycle {
13+
LifecyclePlugin(),
14+
Logger by JUtiltLogger("AstraTemplate") {
1715
private val rootModule = RootModule(this)
1816

1917
/**

instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommand.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal interface AddItemCommand {
1212
)
1313

1414
sealed class Error(message: String) : CommandException(message) {
15-
data object SenderNotPlayer : Error("SenderNotPlayer")
16-
data object ItemNotfound : Error("ItemNotfound")
15+
class SenderNotPlayer : Error("SenderNotPlayer")
16+
class ItemNotfound : Error("ItemNotfound")
1717
}
1818
}

instances/bukkit/src/main/kotlin/ru/astrainteractive/astratemplate/command/additem/AddItemCommandParser.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,56 @@
11
package ru.astrainteractive.astratemplate.command.additem
22

3+
import com.mojang.brigadier.arguments.IntegerArgumentType
4+
import com.mojang.brigadier.arguments.StringArgumentType
5+
import com.mojang.brigadier.tree.LiteralCommandNode
6+
import io.papermc.paper.command.brigadier.CommandSourceStack
37
import org.bukkit.Bukkit
48
import org.bukkit.Material
5-
import org.bukkit.plugin.java.JavaPlugin
6-
import ru.astrainteractive.astralibs.command.api.context.BukkitCommandContext
7-
import ru.astrainteractive.astralibs.command.api.error.ErrorHandler
8-
import ru.astrainteractive.astralibs.command.api.util.PluginExt.setCommandExecutor
9+
import ru.astrainteractive.astralibs.command.api.argumenttype.ArgumentConverter
10+
import ru.astrainteractive.astralibs.command.api.exception.NoPlayerException
11+
import ru.astrainteractive.astralibs.command.api.util.argument
12+
import ru.astrainteractive.astralibs.command.api.util.command
13+
import ru.astrainteractive.astralibs.command.api.util.requireArgument
14+
import ru.astrainteractive.astralibs.command.api.util.runs
915
import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer
1016
import ru.astrainteractive.astralibs.kyori.unwrap
11-
import ru.astrainteractive.astralibs.util.withEntry
17+
import ru.astrainteractive.astratemplate.command.errorhandler.DefaultErrorHandler
1218
import ru.astrainteractive.klibs.kstorage.api.CachedKrate
1319

1420
internal class AddItemCommandRegistry(
15-
private val plugin: JavaPlugin,
16-
private val errorHandler: ErrorHandler<BukkitCommandContext>,
17-
kyoriKrate: CachedKrate<KyoriComponentSerializer>
21+
kyoriKrate: CachedKrate<KyoriComponentSerializer>,
22+
private val errorHandler: DefaultErrorHandler,
23+
private val executor: AddItemExecutor
1824
) : KyoriComponentSerializer by kyoriKrate.unwrap() {
19-
private val alias = "add"
20-
21-
private fun tabCompleter(plugin: JavaPlugin) {
22-
plugin.getCommand(alias)?.setTabCompleter { sender, command, label, args ->
23-
when (args.size) {
24-
2 -> Material.entries.map { it.name }.withEntry(args.last())
25-
3 -> IntRange(1, 64).map { it.toString() }.withEntry(args.last())
26-
else -> Bukkit.getOnlinePlayers().map { it.name }.withEntry(args.last())
27-
}
25+
private object MaterialArgumentConverter : ArgumentConverter<Material> {
26+
override fun transform(argument: String): Material {
27+
return Material.getMaterial(argument) ?: throw AddItemCommand.Error.ItemNotfound()
2828
}
2929
}
3030

31-
fun register() {
32-
tabCompleter(plugin)
33-
plugin.setCommandExecutor(
34-
alias = alias,
35-
commandParser = AddItemCommandParser(),
36-
commandExecutor = AddItemExecutor(),
37-
errorHandler = errorHandler
38-
)
31+
fun createNode(): LiteralCommandNode<CommandSourceStack> {
32+
return command("add") {
33+
argument("player", StringArgumentType.word()) { playerArg ->
34+
argument("material", StringArgumentType.word()) { materialArg ->
35+
argument("amount", IntegerArgumentType.integer(1, 64)) { amountArg ->
36+
runs(errorHandler::handle) { ctx ->
37+
val playerName = ctx.requireArgument(playerArg)
38+
val player = Bukkit.getPlayerExact(playerName) ?: throw NoPlayerException(playerName)
39+
40+
val material = ctx.requireArgument(materialArg, MaterialArgumentConverter)
41+
42+
val amount = ctx.requireArgument(amountArg)
43+
executor.execute(
44+
AddItemCommand.Result(
45+
player = player,
46+
amount = amount,
47+
item = material
48+
)
49+
)
50+
}
51+
}
52+
}
53+
}
54+
}.build()
3955
}
4056
}

0 commit comments

Comments
 (0)