Skip to content

Commit 0544a84

Browse files
authored
Merge pull request #78 from Astra-Interactive/fix/fixes
## Changes - Add database migration - Add files migrations for krates - Up dependencies - Fix shadow dependencies - Add logging for player death
2 parents 2d788f5 + 0524700 commit 0544a84

20 files changed

Lines changed: 398 additions & 81 deletions

File tree

.gitignore

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
1-
# root
1+
**/build
2+
**/runs
3+
.DS_Store
24
.gradle
35
.idea
46
.kotlin
5-
astra.properties
67
local.properties
7-
build
8-
jars
9-
# build-logic
10-
build-logic/.gradle
11-
build-logic/plugins/convention/build
12-
# fabric
13-
fabric/build
14-
# forge
15-
forge/build
16-
# modules
17-
modules/api-local/build
18-
modules/api-remote/build
19-
modules/dto/build
20-
# plugin
21-
plugin/build
22-
# velocity
23-
velocity/build
24-
**/junit_jvm_args.txt
25-
**/junit_test_args.txt
8+
*.jar

gradle/libs.versions.toml

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
[versions]
22
cache4k = "0.14.0"
3-
discordsrv = "1.30.3"
3+
discordsrv = "1.30.4"
44
driver-h2 = "2.4.240"
5-
driver-jdbc = "3.51.1.0"
6-
driver-mariadb = "3.5.6"
5+
driver-jdbc = "3.51.2.0"
6+
driver-mariadb = "3.5.7"
77
driver-mysql = "8.0.33"
88
exposed = "0.61.0"
99
forgegradle = "[6.0,6.2)"
10-
gradle-buildconfig = "6.0.6"
11-
gradle-ftp = "0.1.2"
12-
gradle-shadow = "9.3.0"
10+
gradle-buildconfig = "6.0.7"
11+
gradle-ftp = "0.1.3"
12+
gradle-shadow = "9.2.2"
1313
gson = "2.13.2"
1414
guava = "33.5.0-jre"
15-
jda = "6.1.3"
15+
jda = "6.3.1"
1616
jda-webhook = "0.8.4"
1717
klibs-gradleplugin = "1.13.2"
1818
klibs-kdi = "1.4.8"
19-
klibs-kstorage = "4.4.1"
20-
klibs-mikro = "1.16.1"
21-
kotlin-benchmark = "0.4.15"
19+
klibs-kstorage = "4.5.0"
20+
klibs-mikro = "1.20.0"
21+
kotlin-benchmark = "0.4.16"
2222
kotlin-coroutines = "1.10.2"
2323
kotlin-datetime = "0.7.1-0.6.x-compat"
24-
kotlin-json = "1.9.0"
25-
kotlin-serialization = "1.9.0"
24+
kotlin-json = "1.10.0"
25+
kotlin-serialization = "1.10.0"
2626
kotlin-serialization-kaml = "0.104.0"
2727
kotlin-version = "2.2.0"
28-
ktor = "3.3.3"
28+
ktor = "3.4.0"
2929
minecraft-astralibs = "3.31.2"
30-
minecraft-bstats = "3.1.0"
30+
minecraft-bstats = "3.2.1"
3131
minecraft-bungee = "1.21-R0.5-SNAPSHOT"
3232
minecraft-essentialsx = "2.21.2"
3333
minecraft-fabric-api = "0.139.5+"
3434
minecraft-fabric-kotlin = "1.13.7+"
3535
minecraft-fabric-loader = "0.18.2"
3636
minecraft-fabric-loom = "1.14.6"
37-
minecraft-kyori = "4.25.0"
37+
minecraft-kyori = "4.26.1"
3838
minecraft-luckperms = "5.5"
3939
minecraft-mcprotocollib = "1.21.7-SNAPSHOT"
4040
minecraft-mockbukkit = "4.33.2"
41-
minecraft-mojang-version = "1.21.1"
41+
minecraft-mojang-version = "1.20.1"
4242
minecraft-neoforgeversion = "21.1.129"
43-
minecraft-packetevents = "2.11.0"
44-
minecraft-papi = "2.11.7"
43+
minecraft-packetevents = "2.11.2"
44+
minecraft-papi = "2.12.2"
4545
minecraft-protocollib = "5.3.0"
4646
minecraft-spigot = "1.21.9-R0.1-SNAPSHOT"
4747
minecraft-towny = "0.102.0.0"
4848
minecraft-vault = "1.7.1"
4949
minecraft-velocity = "4.0.0-SNAPSHOT"
50-
minecraft-neoforgegradle = "7.1.11"
51-
telegrambots = "9.2.0"
52-
tests-junit-bom = "6.0.1"
53-
tests-junit-jupiter-api = "6.0.1"
54-
tests-mockito = "5.21.0"
55-
tests-org-testing = "7.11.0"
50+
minecraft-neoforgegradle = "7.1.20"
51+
minecraft-forgeversion = "47.2.20"
52+
minecraft-brigadier = "1.0.500"
53+
telegrambots = "9.4.0"
54+
tests-junit-bom = "6.0.3"
55+
tests-junit-jupiter-api = "6.0.3"
56+
tests-mockito = "5.22.0"
57+
tests-org-testing = "7.12.0"
5658
tests-turbine = "1.2.1"
59+
jmh-core = "1.37"
5760

5861
[libraries]
5962
cache4k = { module = "io.github.reactivecircus.cache4k:cache4k-jvm", version.ref = "cache4k" }
@@ -66,7 +69,6 @@ exposed-core = { module = "org.jetbrains.exposed:exposed-core", version.ref = "e
6669
exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exposed" }
6770
exposed-java-time = { module = "org.jetbrains.exposed:exposed-java-time", version.ref = "exposed" }
6871
exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" }
69-
gradle-shadow = { module = "gradle.plugin.com.github.johnrengelman:shadow", version.ref = "gradle-shadow" }
7072
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
7173
guava = { module = "com.google.guava:guava", version.ref = "guava" }
7274
jda = { module = "net.dv8tion:JDA", version.ref = "jda" }
@@ -126,6 +128,7 @@ minecraft-spigot-core = { module = "org.spigotmc:spigot", version.ref = "minecra
126128
minecraft-towny = { module = "com.palmergames.bukkit.towny:towny", version.ref = "minecraft-towny" }
127129
minecraft-vaultapi = { module = "com.github.MilkBowl:VaultAPI", version.ref = "minecraft-vault" }
128130
minecraft-velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "minecraft-velocity" }
131+
minecraft-brigadier = { module = "com.mojang:brigadier", version.ref = "minecraft-brigadier" }
129132
telegrambots-client = { module = "org.telegram:telegrambots-client", version.ref = "telegrambots" }
130133
telegrambots-extensions = { module = "org.telegram:telegrambots-extensions", version.ref = "telegrambots" }
131134
telegrambots-longpolling = { module = "org.telegram:telegrambots-longpolling", version.ref = "telegrambots" }
@@ -137,7 +140,7 @@ tests-kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" }
137140
tests-mockito = { module = "org.mockito:mockito-core", version.ref = "tests-mockito" }
138141
tests-org-testing = { module = "org.testng:testng", version.ref = "tests-org-testing" }
139142
tests-turbine = { module = "app.cash.turbine:turbine", version.ref = "tests-turbine" }
140-
143+
jmh-core = { module = "org.openjdk.jmh:jmh-core", version.ref = "jmh-core" }
141144
[plugins]
142145
gradle-buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "gradle-buildconfig" }
143146
gradle-fabric-loom = { id = "fabric-loom", version.ref = "minecraft-fabric-loom" }

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

instances/bukkit/build.gradle.kts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,45 @@ shadowJar.configure {
6262
.takeIf(File::exists)
6363
?: File(rootDir, "jars").also(File::mkdirs)
6464

65+
dependencies {
66+
// Dependencies
67+
exclude("mozilla/**")
68+
exclude("javax/**")
69+
exclude("it/unimi/dsi/**")
70+
exclude("ch/qos/logback/**")
71+
exclude("org/intellij/lang/annotations/**")
72+
exclude("org/jetbrains/annotations/**")
73+
exclude("org/slf4j/**")
74+
exclude("org/apache/xmlgraphics/**")
75+
exclude("org/apache/batik/**")
76+
exclude("org/apache/commons/logging/**")
77+
exclude("com/ibm/icu/**")
78+
// Root
79+
exclude("_COROUTINE/**")
80+
exclude("DebugProbesKt.bin")
81+
exclude("jetty-dir.css")
82+
exclude("license/**")
83+
exclude("licenses/**")
84+
exclude("**LICENCE**")
85+
exclude("**LICENSE**")
86+
// META
87+
exclude("META-INF/**.md")
88+
exclude("META-INF/**.MD")
89+
exclude("META-INF/**.txt**")
90+
exclude("META-INF/**LICENCE**")
91+
exclude("META-INF/com.android.tools/**")
92+
exclude("META-INF/gradle-plugins/**")
93+
exclude("META-INF/imports/**")
94+
exclude("META-INF/kotlin-reflection.kotlin_module")
95+
exclude("META-INF/license/**")
96+
exclude("META-INF/maven/**")
97+
exclude("META-INF/native-image/**")
98+
exclude("META-INF/native/**")
99+
exclude("META-INF/proguard/**")
100+
exclude("META-INF/rewrite/**")
101+
exclude("META-INF/services/kotlin.reflect.**")
102+
exclude("META-INF/versions/**")
103+
}
65104
relocate("org.bstats", projectInfo.group)
66105
listOf(
67106
"ch.qos.logback",
@@ -72,13 +111,11 @@ shadowJar.configure {
72111
"okio",
73112
"org.apache",
74113
"org.intellij",
75-
"org.slf4j",
76114
"org.jetbrains.annotations",
77115
"ru.astrainteractive.klibs",
78116
"ru.astrainteractive.astralibs"
79117
).forEach { pattern -> relocate(pattern, "${projectInfo.group}.$pattern") }
80118
listOf(
81-
"org.jetbrains.exposed",
82119
"kotlinx",
83120
).forEach { pattern ->
84121
relocate(pattern, "${projectInfo.group}.$pattern") {

instances/neoforge/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ plugins {
1111
alias(libs.plugins.gradle.shadow)
1212
}
1313

14+
repositories {
15+
mavenLocal()
16+
}
17+
1418
dependencies {
1519
// Kotlin
1620
shadow(libs.kotlin.coroutines.core)

modules/command-bukkit/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies {
1212
implementation(libs.minecraft.astralibs.command)
1313
implementation(libs.minecraft.astralibs.command.bukkit)
1414

15-
implementation(libs.minecraft.paper.api)
15+
compileOnly(libs.minecraft.paper.api)
1616

1717
implementation(libs.klibs.mikro.core)
1818
implementation(projects.modules.core)

modules/command-bukkit/src/main/kotlin/ru/astrainteractive/soulkeeper/command/soulkrate/SoulKrateCommandRegistrar.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger
1919
import ru.astrainteractive.klibs.mikro.core.logging.Logger
2020
import ru.astrainteractive.soulkeeper.core.plugin.PluginPermission
2121
import ru.astrainteractive.soulkeeper.core.serialization.ItemStackSerializer
22-
import ru.astrainteractive.soulkeeper.core.serialization.ItemStackSerializer.decodeFromString
2322
import ru.astrainteractive.soulkeeper.module.souls.database.model.StringFormatObject
2423
import ru.astrainteractive.soulkeeper.module.souls.krate.PlayerSoulKrate
2524
import java.io.File

modules/dao/src/main/kotlin/ru/astrainteractive/soulkeeper/module/souls/dao/SoulsDaoImpl.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ru.astrainteractive.soulkeeper.module.souls.dao
22

3-
import kotlinx.coroutines.Dispatchers
43
import kotlinx.coroutines.flow.Flow
54
import kotlinx.coroutines.flow.MutableSharedFlow
65
import kotlinx.coroutines.flow.asSharedFlow
@@ -21,6 +20,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
2120
import org.jetbrains.exposed.sql.update
2221
import ru.astrainteractive.astralibs.server.location.Location
2322
import ru.astrainteractive.astralibs.server.location.dist
23+
import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers
2424
import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger
2525
import ru.astrainteractive.klibs.mikro.core.logging.Logger
2626
import ru.astrainteractive.soulkeeper.module.souls.database.model.DatabaseSoul
@@ -33,18 +33,19 @@ import java.util.*
3333
@Suppress("TooManyFunctions")
3434
internal class SoulsDaoImpl(
3535
private val databaseFlow: Flow<Database>,
36+
private val dispatchers: KotlinDispatchers
3637
) : SoulsDao, Logger by JUtiltLogger("SoulKeeper-SoulsDaoImpl") {
3738
private val mutex = Mutex()
3839
private suspend fun <T> safeRun(
3940
tag: String,
4041
block: suspend () -> T
4142
): Result<T> = runCatching {
42-
withContext(Dispatchers.IO) {
43+
withContext(dispatchers.IO) {
4344
mutex.withLock {
4445
block.invoke()
4546
}
4647
}
47-
}.onFailure { error { "#$tag error: ${it.message}. ${it.cause}" } }
48+
}.onFailure { t -> error { "#$tag error: ${t.message}. ${t.cause}" } }
4849

4950
private val soulsChangedSharedFlow = MutableSharedFlow<Unit>()
5051

@@ -57,7 +58,7 @@ internal class SoulsDaoImpl(
5758
id = it[SoulTable.id].value,
5859
ownerUUID = UUID.fromString(it[SoulTable.ownerUUID]),
5960
ownerLastName = it[SoulTable.ownerLastName],
60-
createdAt = it[SoulTable.created_at] ?: it[SoulTable.broken_created_at],
61+
createdAt = it[SoulTable.created_at],
6162
isFree = it[SoulTable.isFree],
6263
exp = it[SoulTable.exp],
6364
hasItems = true, // todo
@@ -73,7 +74,6 @@ internal class SoulsDaoImpl(
7374
override suspend fun getSouls(): Result<List<DatabaseSoul>> = safeRun("getSouls") {
7475
transaction(databaseFlow.first()) {
7576
SoulTable.selectAll()
76-
.orderBy(SoulTable.broken_created_at to SortOrder.DESC)
7777
.orderBy(SoulTable.created_at to SortOrder.DESC)
7878
.map(::toDatabaseSoul)
7979
}
@@ -84,7 +84,6 @@ internal class SoulsDaoImpl(
8484
SoulTable
8585
.selectAll()
8686
.limit(1)
87-
.orderBy(SoulTable.broken_created_at to SortOrder.DESC)
8887
.orderBy(SoulTable.created_at to SortOrder.DESC)
8988
.map(::toDatabaseSoul)
9089
.first()
@@ -108,7 +107,6 @@ internal class SoulsDaoImpl(
108107
val soulId = SoulTable.insertAndGetId {
109108
it[SoulTable.ownerUUID] = soul.ownerUUID.toString()
110109
it[SoulTable.ownerLastName] = soul.ownerLastName
111-
it[SoulTable.broken_created_at] = soul.createdAt
112110
it[SoulTable.created_at] = soul.createdAt
113111
it[SoulTable.isFree] = soul.isFree
114112
it[SoulTable.locationWorld] = soul.location.worldName

modules/dao/src/main/kotlin/ru/astrainteractive/soulkeeper/module/souls/database/table/SoulTable.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package ru.astrainteractive.soulkeeper.module.souls.database.table
22

33
import org.jetbrains.exposed.dao.id.LongIdTable
4-
import org.jetbrains.exposed.sql.javatime.timestamp
54
import ru.astrainteractive.soulkeeper.module.souls.database.coulmn.KJavaInstantColumnType
65

76
internal object SoulTable : LongIdTable(name = "SOUL") {
87
val ownerUUID = text("owner_uuid")
98
val ownerLastName = text("owner_last_name")
109

11-
@Deprecated("Timestamp is broken")
12-
val broken_created_at = timestamp("created_at")
13-
14-
val created_at = registerColumn("created_at_millis", KJavaInstantColumnType()).nullable()
10+
val created_at = registerColumn("created_at_millis", KJavaInstantColumnType())
1511

1612
val isFree = bool("is_free")
1713
val exp = integer("exp")

modules/dao/src/main/kotlin/ru/astrainteractive/soulkeeper/module/souls/di/SoulsDaoModule.kt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import ru.astrainteractive.soulkeeper.module.souls.dao.SoulsDao
2424
import ru.astrainteractive.soulkeeper.module.souls.dao.SoulsDaoImpl
2525
import ru.astrainteractive.soulkeeper.module.souls.database.table.SoulItemsTable
2626
import ru.astrainteractive.soulkeeper.module.souls.database.table.SoulTable
27-
import ru.astrainteractive.soulkeeper.module.souls.migration.H2ToSqliteMigration
27+
import ru.astrainteractive.soulkeeper.module.souls.migration.core.DatabaseMigrator
28+
import ru.astrainteractive.soulkeeper.module.souls.migration.core.FileMigration
29+
import ru.astrainteractive.soulkeeper.module.souls.migration.database.DropBrokenCreatedAtMigration
30+
import ru.astrainteractive.soulkeeper.module.souls.migration.database.MakeCreatedAtNonNullMigration
31+
import ru.astrainteractive.soulkeeper.module.souls.migration.file.H2ToSqliteMigration
32+
import ru.astrainteractive.soulkeeper.module.souls.migration.file.KrateFolderMigration
2833
import java.io.File
2934

3035
interface SoulsDaoModule {
@@ -35,18 +40,37 @@ interface SoulsDaoModule {
3540
val soulsDao: SoulsDao
3641

3742
class Default(
38-
dataFolder: File,
39-
ioScope: CoroutineScope,
40-
dispatchers: KotlinDispatchers
43+
private val dataFolder: File,
44+
private val ioScope: CoroutineScope,
45+
private val dispatchers: KotlinDispatchers
4146
) : SoulsDaoModule, Logger by JUtiltLogger("SoulsDaoModule") {
47+
private val fileMigrations: List<FileMigration>
48+
get() = listOf(
49+
H2ToSqliteMigration(dataFolder, dispatchers),
50+
KrateFolderMigration(
51+
dataFolder = dataFolder,
52+
kratesFolder = dataFolder.resolve(".deaths")
53+
)
54+
)
55+
private val databaseMigrator: DatabaseMigrator
56+
get() = DatabaseMigrator(
57+
migrations = listOf(
58+
DropBrokenCreatedAtMigration(),
59+
MakeCreatedAtNonNullMigration(),
60+
),
61+
latestDbVersion = 2
62+
)
63+
4264
override val databaseFlow: Flow<Database> = flow {
43-
H2ToSqliteMigration(dataFolder).migrate()
65+
fileMigrations.forEach { migration -> migration.migrate() }
4466
if (!dataFolder.exists()) dataFolder.mkdirs()
4567
val database = dataFolder.resolve("souls_v3")
4668
.absolutePath
4769
.let(DatabaseConfiguration::SQLite)
4870
.connect()
4971
TransactionManager.manager.defaultIsolationLevel = java.sql.Connection.TRANSACTION_SERIALIZABLE
72+
databaseMigrator.migrate(database)
73+
5074
transaction(database) {
5175
SchemaUtils.create(SoulTable)
5276
SchemaUtils.create(SoulItemsTable)
@@ -62,6 +86,7 @@ interface SoulsDaoModule {
6286

6387
override val soulsDao: SoulsDao = SoulsDaoImpl(
6488
databaseFlow = databaseFlow,
89+
dispatchers = dispatchers
6590
)
6691

6792
override val lifecycle: Lifecycle = Lifecycle.Lambda(

0 commit comments

Comments
 (0)