Skip to content

Commit

Permalink
refactor: config
Browse files Browse the repository at this point in the history
  • Loading branch information
Itsusinn committed Jan 7, 2022
1 parent 9bacdd8 commit 2eb02dc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gradle
extract/
run/

# gradle
.gradle/
build/
out/
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/org/meowcat/mesagisto/farbic/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ data class Config(
val enable: Boolean = false,
val channel: String = "your-channel",
val nats: String = "nats://itsusinn.site:4222",
val cipher: String = "aes",
val cipher: CipherConfig = CipherConfig(),
var idBase: Int = 0
)
@Serializable
data class CipherConfig(
val enable: Boolean = true,
val key: String = "default-key",
@SerialName("refuse-plain")
val refusePlain: Boolean = true
)
11 changes: 10 additions & 1 deletion src/main/kotlin/org/meowcat/mesagisto/farbic/Mod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import net.minecraft.text.LiteralText
import net.minecraft.text.Text
import org.apache.logging.log4j.LogManager
import org.meowcat.mesagisto.client.Logger
import org.meowcat.mesagisto.client.MesagistoConfig
import org.meowcat.mesagisto.farbic.handlers.send
import java.util.* // ktlint-disable no-wildcard-imports
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.io.path.Path

object Mod : ModInitializer, CoroutineScope {
internal val LOGGER = LogManager.getLogger()
private val LOGGER = LogManager.getLogger()
lateinit var server: MinecraftServer
override val coroutineContext = EmptyCoroutineContext

Expand All @@ -28,6 +29,7 @@ object Mod : ModInitializer, CoroutineScope {

override fun onInitialize() {
Logger.bridgeToLog4j(LOGGER)

if (!CONFIG.enable) {
Logger.info { "信使插件未启用" }
return
Expand All @@ -39,6 +41,13 @@ object Mod : ModInitializer, CoroutineScope {
ServerLifecycleEvents.SERVER_STOPPING.register {
configKeeper.save()
}
MesagistoConfig.builder {
name = "farbic"
natsAddress = CONFIG.nats
cipherEnable = CONFIG.cipher.enable
cipherKey = CONFIG.cipher.key
cipherRefusePlain = CONFIG.cipher.refusePlain
}.apply()
}

fun onServerChat(
Expand Down

0 comments on commit 2eb02dc

Please sign in to comment.