mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
profiles: language
This commit is contained in:
parent
c50db6eb56
commit
d71efa9fb1
@ -15,7 +15,9 @@ package de.bixilon.minosoft
|
||||
|
||||
import de.bixilon.minosoft.config.Configuration
|
||||
import de.bixilon.minosoft.config.profile.GlobalProfileManager
|
||||
import de.bixilon.minosoft.config.profile.change.listener.SimpleChangeListener.Companion.listen
|
||||
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.data.accounts.Account
|
||||
import de.bixilon.minosoft.data.assets.JarAssetsManager
|
||||
import de.bixilon.minosoft.data.assets.Resources
|
||||
@ -106,9 +108,12 @@ object Minosoft {
|
||||
Log.log(LogMessageType.PROFILES, LogLevels.INFO) { "Profiles loaded!" }
|
||||
})
|
||||
|
||||
taskWorker += Task(identifier = StartupTasks.LOAD_LANGUAGE_FILES, dependencies = arrayOf(StartupTasks.LOAD_CONFIG), executor = {
|
||||
Log.log(LogMessageType.OTHER, LogLevels.VERBOSE) { "Loading language files (${config.config.general.language})" }
|
||||
LANGUAGE_MANAGER.translators[ProtocolDefinition.MINOSOFT_NAMESPACE] = load(config.config.general.language, null, ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "language/"))
|
||||
taskWorker += Task(identifier = StartupTasks.LOAD_LANGUAGE_FILES, dependencies = arrayOf(StartupTasks.LOAD_PROFILES), executor = {
|
||||
val language = ErosProfileManager.selected.general.language
|
||||
Log.log(LogMessageType.OTHER, LogLevels.VERBOSE) { "Loading language files (${language})" }
|
||||
ErosProfileManager.selected.general::language.listen(this, true) {
|
||||
LANGUAGE_MANAGER.translators[ProtocolDefinition.MINOSOFT_NAMESPACE] = load(it, null, ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "language/"))
|
||||
}
|
||||
Log.log(LogMessageType.OTHER, LogLevels.VERBOSE) { "Language files loaded!" }
|
||||
})
|
||||
|
||||
|
@ -22,6 +22,5 @@ data class GeneralConfig(
|
||||
var version: Int = Configuration.LATEST_CONFIG_VERSION,
|
||||
@Json(name = "log") var log: MutableMap<LogMessageType, LogLevels> = LogMessageType.DEFAULT_LOG_MAP.toMutableMap(),
|
||||
@Json(name = "reduce_protocol_log") var reduceProtocolLog: Boolean = true,
|
||||
var language: String = "en_US",
|
||||
@Json(name = "ignore_x_start_on_first_thread_warning") var ignoreXStartOnFirstThreadWarning: Boolean = false,
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ object ComponentParser : CommandParser() {
|
||||
|
||||
override fun parse(connection: PlayConnection, properties: ParserProperties?, stringReader: CommandStringReader): Any {
|
||||
try {
|
||||
return ChatComponent.of(stringReader.readJson().asJsonObject, connection.version.language, null)
|
||||
return ChatComponent.of(stringReader.readJson().asJsonObject, connection.language, null)
|
||||
} catch (exception: Exception) {
|
||||
stringReader.skip(-1)
|
||||
throw InvalidComponentCommandParseException(stringReader, stringReader.read().toString(), exception)
|
||||
|
@ -27,7 +27,7 @@ class SignBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
|
||||
for (i in 0 until ProtocolDefinition.SIGN_LINES) {
|
||||
val tag = nbt["Text$i"].nullCast<String>() ?: continue
|
||||
|
||||
lines[i] = ChatComponent.of(tag, translator = connection.version.language)
|
||||
lines[i] = ChatComponent.of(tag, translator = connection.language)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ class EntityMetaData(
|
||||
}
|
||||
|
||||
fun getChatComponent(field: EntityMetaDataFields): ChatComponent? {
|
||||
return get<Any?>(field)?.let { ChatComponent.of(it, connection.version.language) }
|
||||
return get<Any?>(field)?.let { ChatComponent.of(it, connection.language) }
|
||||
}
|
||||
|
||||
fun getString(field: EntityMetaDataFields): String? {
|
||||
|
@ -138,7 +138,7 @@ class ItemStack(
|
||||
customDisplayName: ChatComponent? = this.customDisplayName,
|
||||
unbreakable: Boolean = this.unbreakable,
|
||||
durability: Int = this.durability,
|
||||
nbt: MutableMap<String, Any> = this.nbt.synchronizedDeepCopy()!!,
|
||||
nbt: MutableMap<String, Any> = this.nbt.synchronizedDeepCopy(),
|
||||
container: Container? = this.container,
|
||||
hideFlags: Int = this.hideFlags,
|
||||
dyedColor: RGBColor? = this.dyedColor,
|
||||
@ -184,12 +184,12 @@ class ItemStack(
|
||||
|
||||
nbt.getAndRemove(DISPLAY_TAG)?.compoundCast()?.let {
|
||||
it.getAndRemove(DISPLAY_MAME_TAG).nullCast<String>()?.let { nameTag ->
|
||||
customDisplayName = ChatComponent.of(nameTag, translator = connection?.version?.language)
|
||||
customDisplayName = ChatComponent.of(nameTag, translator = connection?.language)
|
||||
}
|
||||
|
||||
it.getAndRemove(DISPLAY_LORE_TAG)?.listCast<String>()?.let { loreTag ->
|
||||
for (lore in loreTag) {
|
||||
this.lore.add(ChatComponent.of(lore, translator = connection?.version?.language))
|
||||
this.lore.add(ChatComponent.of(lore, translator = connection?.language))
|
||||
}
|
||||
}
|
||||
it.getAndRemove(DISPLAY_COLOR_TAG)?.toInt()?.asRGBColor().let { color -> this.dyedColor = color }
|
||||
@ -280,7 +280,7 @@ class ItemStack(
|
||||
get() {
|
||||
customDisplayName?.let { return it }
|
||||
item.translationKey?.let {
|
||||
connection?.version?.language?.translate(it)?.let { translatedName ->
|
||||
connection?.language?.translate(it)?.let { translatedName ->
|
||||
translatedName.applyDefaultColor(rarity.color)
|
||||
return translatedName
|
||||
}
|
||||
|
@ -19,10 +19,12 @@ import de.bixilon.minosoft.data.registries.versions.Version
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.TextComponent
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
||||
import de.bixilon.minosoft.util.KUtil.fullName
|
||||
import de.bixilon.minosoft.util.KUtil.synchronizedListOf
|
||||
import de.bixilon.minosoft.util.KUtil.tryCatch
|
||||
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.asCompound
|
||||
import java.io.FileNotFoundException
|
||||
import java.util.*
|
||||
|
||||
class LanguageManager(
|
||||
private val languages: MutableList<Language> = synchronizedListOf(),
|
||||
@ -50,7 +52,7 @@ class LanguageManager(
|
||||
companion object {
|
||||
|
||||
|
||||
fun load(language: String, version: Version?, path: ResourceLocation = ResourceLocation("lang/")): LanguageManager {
|
||||
fun load(language: Locale, version: Version?, path: ResourceLocation = ResourceLocation("lang/")): LanguageManager {
|
||||
val assetsManager = version?.assetsManager ?: Minosoft.MINOSOFT_ASSETS_MANAGER
|
||||
|
||||
fun loadMinecraftLanguage(language: String): Language {
|
||||
@ -77,8 +79,8 @@ class LanguageManager(
|
||||
|
||||
val languages: MutableList<Language> = mutableListOf()
|
||||
|
||||
if (language != "en_US") {
|
||||
tryCatch(FileNotFoundException::class.java, executor = { languages += loadMinecraftLanguage(language) })
|
||||
if (language != Locale.US) {
|
||||
tryCatch(FileNotFoundException::class.java, executor = { languages += loadMinecraftLanguage(language.fullName) })
|
||||
}
|
||||
languages += loadMinecraftLanguage("en_US")
|
||||
|
||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.language
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.TextComponent
|
||||
import java.util.*
|
||||
|
||||
class MultiLanguageManager(
|
||||
val translators: MutableMap<String, Translator> = mutableMapOf(),
|
||||
@ -27,8 +28,12 @@ class MultiLanguageManager(
|
||||
}
|
||||
|
||||
override fun translate(key: ResourceLocation?, parent: TextComponent?, vararg data: Any?): ChatComponent {
|
||||
key ?: return ChatComponent.of("$key: ${data.contentToString()}")
|
||||
key ?: return ChatComponent.of("null: ${data.contentToString()}")
|
||||
|
||||
return translators[key.namespace]?.translate(key, parent, *data) ?: ChatComponent.of("$key: ${data.contentToString()}")
|
||||
}
|
||||
|
||||
fun loadLanguage(language: Locale) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,8 @@ package de.bixilon.minosoft.data.registries.versions
|
||||
|
||||
import com.google.common.collect.HashBiMap
|
||||
import de.bixilon.mbf.MBFBinaryReader
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.data.assets.MinecraftAssetsManager
|
||||
import de.bixilon.minosoft.data.assets.Resources
|
||||
import de.bixilon.minosoft.data.language.LanguageManager
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketTypes.C2S
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketTypes.S2C
|
||||
@ -45,7 +43,6 @@ data class Version(
|
||||
var isLoaded = false
|
||||
val registries: Registries = Registries()
|
||||
lateinit var assetsManager: MinecraftAssetsManager
|
||||
lateinit var language: LanguageManager
|
||||
|
||||
fun getPacketById(state: ProtocolStates, command: Int): S2C? {
|
||||
return s2CPacketMapping[state]?.inverse()?.get(command)
|
||||
@ -65,12 +62,10 @@ data class Version(
|
||||
}
|
||||
if (!isFlattened() && versionId != ProtocolDefinition.PRE_FLATTENING_VERSION_ID) {
|
||||
assetsManager = Versions.PRE_FLATTENING_VERSION.assetsManager
|
||||
language = Versions.PRE_FLATTENING_VERSION.language
|
||||
return
|
||||
}
|
||||
assetsManager = MinecraftAssetsManager(Resources.getAssetVersionByVersion(this), Resources.getPixLyzerDataHashByVersion(this))
|
||||
assetsManager.downloadAllAssets(latch)
|
||||
language = LanguageManager.load(Minosoft.config.config.general.language, this)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@ -141,13 +136,13 @@ data class Version(
|
||||
if (super.equals(other)) {
|
||||
return true
|
||||
}
|
||||
if (other == null) {
|
||||
if (other !is Version) {
|
||||
return false
|
||||
}
|
||||
return if (hashCode() != other.hashCode()) {
|
||||
false
|
||||
} else {
|
||||
name == name
|
||||
this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.accounts.Account
|
||||
import de.bixilon.minosoft.data.assets.MultiAssetsManager
|
||||
import de.bixilon.minosoft.data.bossbar.BossbarManager
|
||||
import de.bixilon.minosoft.data.commands.CommandRootNode
|
||||
import de.bixilon.minosoft.data.language.LanguageManager
|
||||
import de.bixilon.minosoft.data.physics.CollisionDetector
|
||||
import de.bixilon.minosoft.data.player.LocalPlayerEntity
|
||||
import de.bixilon.minosoft.data.player.tab.TabList
|
||||
@ -84,6 +85,7 @@ class PlayConnection(
|
||||
lateinit var assetsManager: MultiAssetsManager
|
||||
private set
|
||||
val tags: MutableMap<ResourceLocation, Map<ResourceLocation, Tag<Any>>> = synchronizedMapOf()
|
||||
lateinit var language: LanguageManager
|
||||
|
||||
var commandRootNode: CommandRootNode? = null
|
||||
|
||||
@ -215,6 +217,7 @@ class PlayConnection(
|
||||
fireEvent(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.PRE))
|
||||
version.load(latch) // ToDo: show gui loader
|
||||
assetsManager = MultiAssetsManager(version.assetsManager, Minosoft.MINOSOFT_ASSETS_MANAGER)
|
||||
language = LanguageManager.load(profiles.connection.language ?: profiles.eros.general.language, version)
|
||||
registries.parentRegistries = version.registries
|
||||
fireEvent(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.POST))
|
||||
player = LocalPlayerEntity(account, this)
|
||||
|
@ -14,8 +14,10 @@
|
||||
package de.bixilon.minosoft.protocol.network.connection.play.clientsettings
|
||||
|
||||
import de.bixilon.minosoft.config.profile.change.listener.SimpleChangeListener.Companion.listen
|
||||
import de.bixilon.minosoft.data.language.LanguageManager
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.c2s.play.ClientSettingsC2SP
|
||||
import de.bixilon.minosoft.util.KUtil.fullName
|
||||
|
||||
class ClientSettingsManager(
|
||||
private val connection: PlayConnection,
|
||||
@ -64,12 +66,13 @@ class ClientSettingsManager(
|
||||
return
|
||||
}
|
||||
this.language = language
|
||||
connection.language = LanguageManager.load(language, connection.version)
|
||||
sendClientSettings()
|
||||
}
|
||||
|
||||
fun sendClientSettings() {
|
||||
connection.sendPacket(ClientSettingsC2SP(
|
||||
locale = language.toString(),
|
||||
locale = language.fullName,
|
||||
chatColors = connection.profiles.hud.chat.chatColors,
|
||||
viewDistance = connection.profiles.block.viewDistance,
|
||||
chatMode = connection.profiles.hud.chat.chatMode,
|
||||
|
@ -69,7 +69,7 @@ class PlayInByteBuffer : InByteBuffer {
|
||||
}
|
||||
|
||||
override fun readChatComponent(): ChatComponent {
|
||||
return ChatComponent.of(readString(), connection.version.language, null)
|
||||
return ChatComponent.of(readString(), connection.language, null)
|
||||
}
|
||||
|
||||
fun readParticle(): ParticleData {
|
||||
|
@ -555,4 +555,7 @@ object KUtil {
|
||||
throw IOException("Could not move $tempFile to $destination!")
|
||||
}
|
||||
}
|
||||
|
||||
val Locale.fullName: String
|
||||
get() = language + "_" + country.ifEmpty { language.uppercase() }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user