mirror of
https://github.com/amalthea-mc/spigot-tg-bridge.git
synced 2024-11-09 12:11:06 +00:00
Fix updating config.yml after /tgbridge_reload
This commit is contained in:
parent
013a6b2f96
commit
d6404d3be2
@ -1,4 +1,5 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
@ -26,7 +27,7 @@ val cfg: Map<String, String> = Yaml()
|
||||
.load(FileInputStream("$projectDir/src/main/resources/plugin.yml"))
|
||||
val pluginVersion = cfg.get("version")
|
||||
val spigotApiVersion = cfg.get("api-version")
|
||||
val exposedVersion = "0.31.1"
|
||||
val retrofitVersion = "2.7.1"
|
||||
version = pluginVersion as Any
|
||||
|
||||
repositories {
|
||||
@ -38,10 +39,6 @@ repositories {
|
||||
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
}
|
||||
|
||||
val retrofitVersion = "2.7.1"
|
||||
val plugDir = "MinecraftServers/spigot_1.17/plugins/"
|
||||
val homeDir = System.getProperty("user.home")
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
compileOnly("org.spigotmc:spigot-api:$spigotApiVersion-R0.1-SNAPSHOT")
|
||||
@ -62,12 +59,21 @@ tasks {
|
||||
)
|
||||
}
|
||||
register<Copy>("copyArtifacts") {
|
||||
from("shadowJar")
|
||||
into(File(homeDir, plugDir))
|
||||
val dest = File(
|
||||
System.getProperty("user.home"),
|
||||
"MinecraftServers/spigot_1.17/plugins/",
|
||||
)
|
||||
from(shadowJar)
|
||||
into(dest)
|
||||
}
|
||||
register("pack") {
|
||||
description = "[For development only!] Build project and copy .jar into servers directory"
|
||||
dependsOn("shadowJar")
|
||||
finalizedBy("copyArtifacts")
|
||||
}
|
||||
withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,10 +67,9 @@ class Plugin : JavaPlugin() {
|
||||
}
|
||||
|
||||
fun reload() {
|
||||
config?.let { config ->
|
||||
config = Configuration(this).also { config ->
|
||||
if (!config.isEnabled) return
|
||||
logger.info(C.INFO.reloading)
|
||||
this.config = Configuration(this)
|
||||
eventHandler?.let { HandlerList.unregisterAll(it) }
|
||||
tgBot?.run { stop() }
|
||||
tgBot = TgBot(this, config).also { bot ->
|
||||
|
@ -4,7 +4,9 @@ import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.channels.consumeEach
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.OkHttpClient
|
||||
@ -93,20 +95,15 @@ class TgBot(
|
||||
}
|
||||
}
|
||||
}
|
||||
updateChan.close()
|
||||
}
|
||||
|
||||
private fun initHandler() = scope.launch {
|
||||
loop@ while (true) {
|
||||
updateChan.consumeEach {
|
||||
try {
|
||||
handleUpdate(updateChan.receive())
|
||||
handleUpdate(it)
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is CancellationException -> break@loop
|
||||
else -> {
|
||||
e.printStackTrace()
|
||||
continue@loop
|
||||
}
|
||||
}
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,7 +114,8 @@ class TgBot(
|
||||
return
|
||||
update.message?.text?.let {
|
||||
commandRegex.matchEntire(it)?.groupValues?.let {
|
||||
commandMap[it[1]]?.let { it(update) }
|
||||
val (command) = it
|
||||
commandMap.get(command)?.let { it(update) }
|
||||
} ?: run {
|
||||
onTextHandler(update)
|
||||
}
|
||||
@ -127,7 +125,7 @@ class TgBot(
|
||||
fun stop() {
|
||||
runBlocking {
|
||||
pollJob.cancelAndJoin()
|
||||
handlerJob.cancelAndJoin()
|
||||
handlerJob.join()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user