diff --git a/KotlinCore/build.gradle.kts b/KotlinCore/build.gradle.kts
index 5d00f0f6..0c610074 100644
--- a/KotlinCore/build.gradle.kts
+++ b/KotlinCore/build.gradle.kts
@@ -32,4 +32,6 @@ tasks.shadowJar {
dependencies {
compileOnly(libs.paperapi21)
+ compileOnly(libs.nms21)
+ compileOnly(project(":SpigotCore"))
}
diff --git a/KotlinCore/src/de/steamwar/kotlin/KotlinCore.kt b/KotlinCore/src/de/steamwar/kotlin/KotlinCore.kt
index e821ade4..89aa1b34 100644
--- a/KotlinCore/src/de/steamwar/kotlin/KotlinCore.kt
+++ b/KotlinCore/src/de/steamwar/kotlin/KotlinCore.kt
@@ -19,6 +19,7 @@
package de.steamwar.kotlin
+import de.steamwar.kotlin.message.LanguageListener
import org.bukkit.plugin.java.JavaPlugin
class KotlinCore : JavaPlugin() {
@@ -32,6 +33,7 @@ class KotlinCore : JavaPlugin() {
}
override fun onEnable() {
+ server.pluginManager.registerEvents(LanguageListener, this)
}
override fun onDisable() {
diff --git a/KotlinCore/src/de/steamwar/kotlin/message/ComponentMessage.kt b/KotlinCore/src/de/steamwar/kotlin/message/ComponentMessage.kt
new file mode 100644
index 00000000..85d41b3b
--- /dev/null
+++ b/KotlinCore/src/de/steamwar/kotlin/message/ComponentMessage.kt
@@ -0,0 +1,36 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2024 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.kotlin.message
+
+import net.kyori.adventure.key.Key
+import net.kyori.adventure.translation.GlobalTranslator
+import net.kyori.adventure.translation.Translator
+import java.text.MessageFormat
+import java.util.*
+
+class ComponentMessage(private val resourceBundleName: String, private val classLoader: ClassLoader) : Translator {
+ init {
+ GlobalTranslator.translator().addSource(this)
+ }
+
+ override fun name(): Key = Key.key("steamwar", resourceBundleName)
+
+ override fun translate(key: String, locale: Locale): MessageFormat = MessageFormat(ResourceBundle.getBundle(resourceBundleName, locale, classLoader).getString(key), locale)
+}
diff --git a/KotlinCore/src/de/steamwar/kotlin/message/LanguageListener.kt b/KotlinCore/src/de/steamwar/kotlin/message/LanguageListener.kt
new file mode 100644
index 00000000..0824b416
--- /dev/null
+++ b/KotlinCore/src/de/steamwar/kotlin/message/LanguageListener.kt
@@ -0,0 +1,49 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2024 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.kotlin.message
+
+import de.steamwar.kotlin.KotlinCore
+import de.steamwar.sql.SteamwarUser
+import org.bukkit.Bukkit
+import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer
+import org.bukkit.event.EventHandler
+import org.bukkit.event.EventPriority
+import org.bukkit.event.Listener
+import org.bukkit.event.player.PlayerJoinEvent
+import org.bukkit.event.player.PlayerLocaleChangeEvent
+
+object LanguageListener: Listener {
+
+ @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
+ fun onPlayerJoin(event: PlayerJoinEvent) {
+ val user = SteamwarUser.get(event.player.uniqueId)
+ val player = event.player as CraftPlayer
+ player.handle.`adventure$locale` = user.locale
+ }
+
+ @EventHandler
+ fun onPlayerConfig(event: PlayerLocaleChangeEvent) {
+ Bukkit.getScheduler().runTask(KotlinCore.plugin, Runnable {
+ val user = SteamwarUser.get(event.player.uniqueId)
+ val player = event.player as CraftPlayer
+ player.handle.`adventure$locale` = user.locale
+ })
+ }
+}
\ No newline at end of file
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 2379d8bd..a13a1974 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -130,6 +130,7 @@ dependencyResolutionManagement {
library("nms18", "de.steamwar:spigot:1.18")
library("nms19", "de.steamwar:spigot:1.19")
library("nms20", "de.steamwar:spigot:1.20")
+ library("nms21", "de.steamwar:spigot:1.21")
library("axiom", "de.steamwar:axiompaper:RELEASE")
library("worldedit12", "de.steamwar:worldedit:1.12")