summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSho Sakuma <me@m1sk9.dev>2026-01-10 12:24:25 +0900
committerSho Sakuma <me@m1sk9.dev>2026-01-10 12:24:25 +0900
commitbff58ba4a1e539b7542651239682eadddbc99823 (patch)
treefb2cbbb60302b8f54d112329ee33e61826377a79
parent32afea88982a98d9f7fe61471e92b1f5f881c76f (diff)
downloadLunaticChat-bff58ba4a1e539b7542651239682eadddbc99823.tar.gz
LunaticChat-bff58ba4a1e539b7542651239682eadddbc99823.tar.bz2
LunaticChat-bff58ba4a1e539b7542651239682eadddbc99823.zip
feat: Add feature toggle
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt54
-rw-r--r--platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/config/ConfigManager.kt10
2 files changed, 34 insertions, 30 deletions
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt
index 141c620..67bedc7 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/LunaticChat.kt
@@ -23,7 +23,7 @@ class LunaticChat :
lateinit var directMessageHandler: DirectMessageHandler
private lateinit var commandRegistry: CommandRegistry
- private lateinit var romajiConverter: RomanjiConverter
+ private var romajiConverter: RomanjiConverter? = null
override fun onEnable() {
saveDefaultConfig()
@@ -34,32 +34,37 @@ class LunaticChat :
logger.info("Debug: $lunaticChatConfiguration")
}
- val cache =
- ConversionCache(
- cacheFile = dataFolder.resolve("conversion_cache.json").toPath(),
- maxEntries = lunaticChatConfiguration.features.japaneseConversion.cacheMaxEntries,
- plugin = this,
- logger = logger,
- )
- cache.loadFromDisk()
+ if (lunaticChatConfiguration.features.japaneseConversion.enabled) {
+ val cache =
+ ConversionCache(
+ cacheFile = dataFolder.resolve(lunaticChatConfiguration.features.japaneseConversion.cacheFilePath).toPath(),
+ maxEntries = lunaticChatConfiguration.features.japaneseConversion.cacheMaxEntries,
+ plugin = this,
+ logger = logger,
+ )
+ cache.loadFromDisk()
- val httpClient = HttpClient(CIO)
- val apiClient =
- GoogleIMEClient(
- timeout = lunaticChatConfiguration.features.japaneseConversion.apiTimeout.milliseconds,
- httpClient = httpClient,
+ val httpClient = HttpClient(CIO)
+ val apiClient =
+ GoogleIMEClient(
+ timeout = lunaticChatConfiguration.features.japaneseConversion.apiTimeout.milliseconds,
+ httpClient = httpClient,
+ )
+ romajiConverter = RomanjiConverter(cache, apiClient, logger)
+
+ val saveInterval = lunaticChatConfiguration.features.japaneseConversion.cacheSaveIntervalSeconds * 20L
+ server.scheduler.runTaskTimerAsynchronously(
+ this,
+ Runnable {
+ cache.saveToDisk()
+ },
+ saveInterval,
+ saveInterval,
)
- romajiConverter = RomanjiConverter(cache, apiClient, logger)
- val saveInterval = lunaticChatConfiguration.features.japaneseConversion.cacheSaveIntervalSeconds * 20L
- server.scheduler.runTaskTimerAsynchronously(
- this,
- Runnable {
- cache.saveToDisk()
- },
- saveInterval,
- saveInterval,
- )
+ server.pluginManager.registerEvents(PlayerChatListener(romajiConverter!!), this)
+ logger.info("Japanese conversion feature enabled.")
+ }
directMessageHandler = DirectMessageHandler()
@@ -77,7 +82,6 @@ class LunaticChat :
server.pluginManager.registerEvents(SpyPermissionManager, this)
server.pluginManager.registerEvents(PlayerPresenceListener(this), this)
- server.pluginManager.registerEvents(PlayerChatListener(romajiConverter), this)
logger.info("LunaticChat enabled.")
}
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/config/ConfigManager.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/config/ConfigManager.kt
index d138914..9dc5771 100644
--- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/config/ConfigManager.kt
+++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/config/ConfigManager.kt
@@ -25,23 +25,23 @@ object ConfigManager {
japaneseConversion =
JapaneseConversionFeatureConfig(
enabled = configFile.getBoolean("features.japaneseConversion.enabled", false),
- cacheMaxEntries = configFile.getInt("features.japaneseConversion.cacheMaxEntries", 500),
+ cacheMaxEntries = configFile.getInt("features.japaneseConversion.cache.maxEntries", 500),
cacheSaveIntervalSeconds =
configFile.getInt(
- "features.japaneseConversion.cacheSaveIntervalSeconds",
+ "features.japaneseConversion.cache.saveIntervalSeconds",
300,
),
cacheFilePath =
configFile.getString(
- "features.japaneseConversion.cacheFilePath",
+ "features.japaneseConversion.cache.filePath",
"conversion_cache.json",
)!!,
apiTimeout =
configFile.getLong(
- "features.japaneseConversion.apiTimeout",
+ "features.japaneseConversion.api.timeout",
3000,
),
- apiRetryAttempts = configFile.getInt("features.japaneseConversion.apiRetryAttempts", 2),
+ apiRetryAttempts = configFile.getInt("features.japaneseConversion.api.retryAttempts", 2),
),
),
messageFormat =