Skip to content

Commit c8f58e2

Browse files
committed
[FIX] Fix okHttpClient close, commands
1 parent f8a2992 commit c8f58e2

39 files changed

Lines changed: 632 additions & 466 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ klibs.java.ktarget=21
1313
# Project
1414
klibs.project.name=MessageBridge
1515
klibs.project.group=ru.astrainteractive.messagebridge
16-
klibs.project.version.string=0.23.0
16+
klibs.project.version.string=0.24.0
1717
klibs.project.description=Bridge for TG and Discord
1818
klibs.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com
1919
klibs.project.url=https://empireprojekt.ru

instances/bukkit/src/main/kotlin/ru/astrainteractive/messagebridge/di/RootModule.kt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package ru.astrainteractive.messagebridge.di
22

3-
import kotlinx.coroutines.Dispatchers
43
import kotlinx.coroutines.GlobalScope
54
import kotlinx.coroutines.launch
65
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
76
import ru.astrainteractive.astralibs.command.api.brigadier.command.PaperMultiplatformCommands
87
import ru.astrainteractive.astralibs.command.api.registrar.PaperCommandRegistrarContext
98
import ru.astrainteractive.astralibs.coroutines.DefaultBukkitDispatchers
10-
import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer
119
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
1210
import ru.astrainteractive.astralibs.server.bridge.BukkitPlatformServer
13-
import ru.astrainteractive.klibs.kstorage.api.asCachedKrate
14-
import ru.astrainteractive.klibs.kstorage.api.impl.DefaultMutableKrate
1511
import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger
1612
import ru.astrainteractive.klibs.mikro.core.logging.Logger
1713
import ru.astrainteractive.messagebridge.MessageBridge
@@ -37,20 +33,21 @@ class RootModule(
3733
val coreModule = CoreModule(
3834
dataFolder = bukkitCoreModule.plugin.dataFolder,
3935
dispatchers = DefaultBukkitDispatchers(bukkitCoreModule.plugin),
40-
platformServer = BukkitPlatformServer()
36+
platformServer = BukkitPlatformServer(),
37+
commandRegistrarContextFactory = { mainScope ->
38+
PaperCommandRegistrarContext(
39+
mainScope = mainScope,
40+
plugin = plugin
41+
)
42+
}
4143
)
4244

4345
val linkModule = LinkModule.Default(coreModule, BukkitLuckPermsProvider)
4446

45-
val kyoriKrate = DefaultMutableKrate<KyoriComponentSerializer>(
46-
factory = { KyoriComponentSerializer.Legacy },
47-
loader = { null }
48-
).asCachedKrate()
49-
5047
val bukkitMessengerModule = BukkitMessengerModule(
5148
coreModule = coreModule,
5249
bukkitCoreModule = bukkitCoreModule,
53-
kyoriKrate = kyoriKrate,
50+
kyoriKrate = coreModule.kyoriKrate,
5451
linkingDao = linkModule.linkingDao
5552
)
5653

@@ -70,12 +67,8 @@ class RootModule(
7067
CommandModule(
7168
coreModule = coreModule,
7269
linkModule = linkModule,
73-
kyoriKrate = kyoriKrate,
7470
lifecyclePlugin = plugin,
75-
commandRegistrarContext = PaperCommandRegistrarContext(
76-
mainScope = coreModule.mainScope,
77-
plugin = plugin
78-
),
71+
commandRegistrarContext = coreModule.commandRegistrarContext,
7972
multiplatformCommand = MultiplatformCommand(PaperMultiplatformCommands())
8073
)
8174
}
@@ -91,7 +84,7 @@ class RootModule(
9184

9285
val lifecycle = Lifecycle.Lambda(
9386
onEnable = {
94-
GlobalScope.launch(Dispatchers.IO) {
87+
GlobalScope.launch(coreModule.dispatchers.IO) {
9588
BEventChannel.consume(ServerOpenBEvent)
9689
}
9790
lifecycles.forEach(Lifecycle::onEnable)
@@ -100,7 +93,7 @@ class RootModule(
10093
lifecycles.forEach(Lifecycle::onReload)
10194
},
10295
onDisable = {
103-
GlobalScope.launch(Dispatchers.IO) {
96+
GlobalScope.launch(coreModule.dispatchers.IO) {
10497
BEventChannel.consume(ServerClosedBEvent)
10598
}
10699
lifecycles.forEach(Lifecycle::onDisable)

instances/forge/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies {
4747
shadow(projects.modules.messenger.discord)
4848
shadow(projects.modules.messenger.forge)
4949
shadow(projects.modules.messenger.telegram)
50+
shadow(projects.modules.command)
5051
}
5152

5253
minecraftProcessResource {

instances/forge/src/main/kotlin/ru/astrainteractive/messagebridge/ForgeEntryPoint.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ForgeEntryPoint :
1414
ForgeLifecycleServer(),
1515
Logger by JUtiltLogger("ForgeEntryPoint"),
1616
Lifecycle {
17-
private val rootModule by lazy { RootModule() }
17+
private val rootModule = RootModule(this)
1818

1919
override fun onEnable() {
2020
rootModule.lifecycle.onEnable()

instances/forge/src/main/kotlin/ru/astrainteractive/messagebridge/di/RootModule.kt

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package ru.astrainteractive.messagebridge.di
22

3-
import kotlinx.coroutines.Dispatchers
43
import kotlinx.coroutines.GlobalScope
54
import kotlinx.coroutines.launch
65
import net.minecraftforge.fml.loading.FMLPaths
6+
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
7+
import ru.astrainteractive.astralibs.command.brigadier.command.MinecraftMultiplatformCommands
8+
import ru.astrainteractive.astralibs.command.registrar.ForgeCommandRegistrarContext
79
import ru.astrainteractive.astralibs.coroutines.MinecraftDispatchers
10+
import ru.astrainteractive.astralibs.lifecycle.ForgeLifecycleServer
811
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
912
import ru.astrainteractive.astralibs.server.bridge.MinecraftPlatformServer
1013
import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger
1114
import ru.astrainteractive.klibs.mikro.core.logging.Logger
15+
import ru.astrainteractive.messagebridge.commands.di.CommandModule
1216
import ru.astrainteractive.messagebridge.core.di.CoreModule
1317
import ru.astrainteractive.messagebridge.forge.core.api.ForgeLuckPermsProvider
1418
import ru.astrainteractive.messagebridge.forge.core.api.ForgeOnlinePlayersProvider
@@ -21,16 +25,27 @@ import ru.astrainteractive.messagebridge.messenger.forge.di.ForgeMessengerModule
2125
import ru.astrainteractive.messagebridge.messenger.telegram.di.TelegramMessengerModule
2226
import java.io.File
2327

24-
class RootModule : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withoutParentHandlers() {
25-
val coreModule by lazy {
26-
CoreModule(
27-
dataFolder = FMLPaths.CONFIGDIR.get()
28-
.resolve("MessageBridge")
29-
.toAbsolutePath()
30-
.toFile()
31-
.also(File::mkdirs),
32-
dispatchers = MinecraftDispatchers(),
33-
platformServer = MinecraftPlatformServer
28+
class RootModule(
29+
forgeLifecycleServer: ForgeLifecycleServer
30+
) : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withoutParentHandlers() {
31+
val coreModule = CoreModule(
32+
dataFolder = FMLPaths.CONFIGDIR.get()
33+
.resolve("MessageBridge")
34+
.toAbsolutePath()
35+
.toFile()
36+
.also(File::mkdirs),
37+
dispatchers = MinecraftDispatchers(),
38+
platformServer = MinecraftPlatformServer,
39+
commandRegistrarContextFactory = ::ForgeCommandRegistrarContext
40+
)
41+
42+
val commandModule by lazy {
43+
CommandModule(
44+
coreModule = coreModule,
45+
linkModule = linkModule,
46+
lifecyclePlugin = forgeLifecycleServer,
47+
commandRegistrarContext = coreModule.commandRegistrarContext,
48+
multiplatformCommand = MultiplatformCommand(MinecraftMultiplatformCommands())
3449
)
3550
}
3651

@@ -67,15 +82,15 @@ class RootModule : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withou
6782
private val lifecycles: List<Lifecycle>
6883
get() = listOf(
6984
coreModule.lifecycle,
70-
// event
85+
commandModule.lifecycle,
7186
jdaEventModule.lifecycle,
7287
tgEventModule.lifecycle,
7388
forgeMessengerModule.lifecycle
7489
)
7590

7691
val lifecycle = Lifecycle.Lambda(
7792
onEnable = {
78-
GlobalScope.launch(Dispatchers.IO) {
93+
GlobalScope.launch(coreModule.dispatchers.IO) {
7994
BEventChannel.consume(ServerOpenBEvent)
8095
}
8196
lifecycles.forEach(Lifecycle::onEnable)
@@ -84,7 +99,7 @@ class RootModule : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withou
8499
lifecycles.forEach(Lifecycle::onReload)
85100
},
86101
onDisable = {
87-
GlobalScope.launch(Dispatchers.IO) {
102+
GlobalScope.launch(coreModule.dispatchers.IO) {
88103
BEventChannel.consume(ServerClosedBEvent)
89104
}
90105
lifecycles.forEach(Lifecycle::onDisable)

instances/neoforge/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dependencies {
4040
shadow(projects.modules.messenger.discord)
4141
shadow(projects.modules.messenger.neoforge)
4242
shadow(projects.modules.messenger.telegram)
43+
shadow(projects.modules.command)
4344
}
4445

4546
minecraftProcessResource {

instances/neoforge/src/main/kotlin/ru/astrainteractive/messagebridge/NeoForgeEntryPoint.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class NeoForgeEntryPoint :
1414
ForgeLifecycleServer(),
1515
Logger by JUtiltLogger("NeoForgeEntryPoint"),
1616
Lifecycle {
17-
private val rootModule by lazy { RootModule() }
17+
private val rootModule = RootModule(this)
1818

1919
override fun onEnable() {
2020
rootModule.lifecycle.onEnable()

instances/neoforge/src/main/kotlin/ru/astrainteractive/messagebridge/di/RootModule.kt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package ru.astrainteractive.messagebridge.di
22

3-
import kotlinx.coroutines.Dispatchers
43
import kotlinx.coroutines.GlobalScope
54
import kotlinx.coroutines.launch
65
import net.neoforged.fml.loading.FMLPaths
6+
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
7+
import ru.astrainteractive.astralibs.command.brigadier.command.MinecraftMultiplatformCommands
8+
import ru.astrainteractive.astralibs.command.registrar.NeoForgeCommandRegistrarContext
79
import ru.astrainteractive.astralibs.coroutines.MinecraftDispatchers
10+
import ru.astrainteractive.astralibs.lifecycle.ForgeLifecycleServer
811
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
912
import ru.astrainteractive.astralibs.server.bridge.MinecraftPlatformServer
1013
import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger
1114
import ru.astrainteractive.klibs.mikro.core.logging.Logger
15+
import ru.astrainteractive.messagebridge.commands.di.CommandModule
1216
import ru.astrainteractive.messagebridge.core.di.CoreModule
1317
import ru.astrainteractive.messagebridge.forge.core.api.NeoForgeLuckPermsProvider
1418
import ru.astrainteractive.messagebridge.forge.core.api.NeoForgeOnlinePlayersProvider
@@ -21,7 +25,9 @@ import ru.astrainteractive.messagebridge.messenger.forge.di.NeoForgeMessengerMod
2125
import ru.astrainteractive.messagebridge.messenger.telegram.di.TelegramMessengerModule
2226
import java.io.File
2327

24-
class RootModule : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withoutParentHandlers() {
28+
class RootModule(
29+
forgeLifecycleServer: ForgeLifecycleServer
30+
) : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withoutParentHandlers() {
2531
val coreModule by lazy {
2632
CoreModule(
2733
dataFolder = FMLPaths.CONFIGDIR.get()
@@ -30,7 +36,8 @@ class RootModule : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withou
3036
.toFile()
3137
.also(File::mkdirs),
3238
dispatchers = MinecraftDispatchers(),
33-
platformServer = MinecraftPlatformServer
39+
platformServer = MinecraftPlatformServer,
40+
commandRegistrarContextFactory = ::NeoForgeCommandRegistrarContext
3441
)
3542
}
3643

@@ -47,6 +54,15 @@ class RootModule : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withou
4754
coreModule = coreModule,
4855
)
4956
}
57+
val commandModule by lazy {
58+
CommandModule(
59+
coreModule = coreModule,
60+
linkModule = linkModule,
61+
lifecyclePlugin = forgeLifecycleServer,
62+
commandRegistrarContext = coreModule.commandRegistrarContext,
63+
multiplatformCommand = MultiplatformCommand(MinecraftMultiplatformCommands())
64+
)
65+
}
5066

5167
val jdaEventModule by lazy {
5268
JdaMessengerModule(
@@ -67,15 +83,15 @@ class RootModule : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withou
6783
private val lifecycles: List<Lifecycle>
6884
get() = listOf(
6985
coreModule.lifecycle,
70-
// event
86+
commandModule.lifecycle,
7187
jdaEventModule.lifecycle,
7288
tgEventModule.lifecycle,
7389
neoForgeMessengerModule.lifecycle
7490
)
7591

7692
val lifecycle = Lifecycle.Lambda(
7793
onEnable = {
78-
GlobalScope.launch(Dispatchers.IO) {
94+
GlobalScope.launch(coreModule.dispatchers.IO) {
7995
BEventChannel.consume(ServerOpenBEvent)
8096
}
8197
lifecycles.forEach(Lifecycle::onEnable)
@@ -84,7 +100,7 @@ class RootModule : Logger by JUtiltLogger("MessageBridge-RootModuleImpl").withou
84100
lifecycles.forEach(Lifecycle::onReload)
85101
},
86102
onDisable = {
87-
GlobalScope.launch(Dispatchers.IO) {
103+
GlobalScope.launch(coreModule.dispatchers.IO) {
88104
BEventChannel.consume(ServerClosedBEvent)
89105
}
90106
lifecycles.forEach(Lifecycle::onDisable)

modules/command/src/main/kotlin/ru/astrainteractive/messagebridge/commands/di/CommandModule.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package ru.astrainteractive.messagebridge.commands.di
22

33
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
44
import ru.astrainteractive.astralibs.command.api.registrar.CommandRegistrarContext
5-
import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer
65
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
7-
import ru.astrainteractive.klibs.kstorage.api.CachedKrate
86
import ru.astrainteractive.messagebridge.commands.link.LinkCommandExecutor
97
import ru.astrainteractive.messagebridge.commands.link.LinkLiteralArgumentBuilder
108
import ru.astrainteractive.messagebridge.commands.reload.ReloadLiteralArgumentBuilder
@@ -17,15 +15,14 @@ class CommandModule(
1715
lifecyclePlugin: Lifecycle,
1816
coreModule: CoreModule,
1917
linkModule: LinkModule,
20-
kyoriKrate: CachedKrate<KyoriComponentSerializer>,
2118
private val commandRegistrarContext: CommandRegistrarContext,
2219
private val multiplatformCommand: MultiplatformCommand
2320
) {
2421
private val nodes = listOf(
2522
ReloadLiteralArgumentBuilder(
2623
plugin = lifecyclePlugin,
2724
translationKrate = coreModule.translationKrate,
28-
kyoriKrate = kyoriKrate,
25+
kyoriKrate = coreModule.kyoriKrate,
2926
multiplatformCommand = multiplatformCommand
3027
).create(),
3128
LinkLiteralArgumentBuilder(
@@ -34,7 +31,7 @@ class CommandModule(
3431
codeApi = linkModule.codeApi,
3532
linkingDao = linkModule.linkingDao,
3633
translationKrate = coreModule.translationKrate,
37-
kyoriKrate = kyoriKrate
34+
kyoriKrate = coreModule.kyoriKrate
3835
),
3936
multiplatformCommand = multiplatformCommand,
4037
platformServer = coreModule.platformServer
@@ -44,7 +41,7 @@ class CommandModule(
4441
ioScope = coreModule.ioScope,
4542
linkingDao = linkModule.linkingDao,
4643
translationKrate = coreModule.translationKrate,
47-
kyoriKrate = kyoriKrate
44+
kyoriKrate = coreModule.kyoriKrate
4845
),
4946
multiplatformCommand = multiplatformCommand,
5047
platformServer = coreModule.platformServer

modules/core/api/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ dependencies {
1414
implementation(libs.kotlin.serialization.json)
1515
implementation(libs.kotlin.serialization.kaml)
1616
implementation(libs.minecraft.astralibs.core)
17-
implementation(libs.minecraft.astralibs.core.bukkit)
17+
implementation(libs.minecraft.astralibs.command)
1818
}

0 commit comments

Comments
 (0)