lateinit var service: WatchService
override fun onEnable() {
DebugSetting.reload()
service = configFolderPath.fileSystem.newWatchService()
configFolderPath.register(
service,
arrayOf(StandardWatchEventKinds.ENTRY_MODIFY),
SensitivityWatchEventModifier.LOW
)
launch {
while (isActive) {
val key = runInterruptible(Dispatchers.IO, service::take)
for (event in key.pollEvents()) {
val path = event.context() as? Path ?: continue
if (path.extension != "yml") continue
when (val name = path.nameWithoutExtension) {
DebugSetting.saveName -> launch {
logger.info { "$name reload for ${event.kind().name()} - ${event.count()}." }
try {
DebugSetting.reload()
} catch (cause: Throwable) {
logger.warning({ "$name reload failure." }, cause)
}
}
else -> Unit
}
}
key.reset()
}
}
}
override fun onDisable() {
service.close()
}