forked from SteamWar/SteamWar
Add ComponentMessage, for TranslatableComponents in Paper >1.20
This commit is contained in:
@@ -32,4 +32,6 @@ tasks.shadowJar {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly(libs.paperapi21)
|
compileOnly(libs.paperapi21)
|
||||||
|
compileOnly(libs.nms21)
|
||||||
|
compileOnly(project(":SpigotCore"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.kotlin
|
package de.steamwar.kotlin
|
||||||
|
|
||||||
|
import de.steamwar.kotlin.message.LanguageListener
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
||||||
class KotlinCore : JavaPlugin() {
|
class KotlinCore : JavaPlugin() {
|
||||||
@@ -32,6 +33,7 @@ class KotlinCore : JavaPlugin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
|
server.pluginManager.registerEvents(LanguageListener, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDisable() {
|
override fun onDisable() {
|
||||||
|
|||||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -130,6 +130,7 @@ dependencyResolutionManagement {
|
|||||||
library("nms18", "de.steamwar:spigot:1.18")
|
library("nms18", "de.steamwar:spigot:1.18")
|
||||||
library("nms19", "de.steamwar:spigot:1.19")
|
library("nms19", "de.steamwar:spigot:1.19")
|
||||||
library("nms20", "de.steamwar:spigot:1.20")
|
library("nms20", "de.steamwar:spigot:1.20")
|
||||||
|
library("nms21", "de.steamwar:spigot:1.21")
|
||||||
|
|
||||||
library("axiom", "de.steamwar:axiompaper:RELEASE")
|
library("axiom", "de.steamwar:axiompaper:RELEASE")
|
||||||
library("worldedit12", "de.steamwar:worldedit:1.12")
|
library("worldedit12", "de.steamwar:worldedit:1.12")
|
||||||
|
|||||||
Reference in New Issue
Block a user