mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
text: BaseComponent outsource with translation formatting
This commit is contained in:
parent
73d68e89aa
commit
7307a22000
@ -14,6 +14,8 @@
|
|||||||
package de.bixilon.minosoft.data.text
|
package de.bixilon.minosoft.data.text
|
||||||
|
|
||||||
import de.bixilon.kutil.cast.CastUtil.nullCast
|
import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||||
|
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||||
|
import de.bixilon.kutil.json.JsonObject
|
||||||
import de.bixilon.kutil.json.JsonUtil.toJsonList
|
import de.bixilon.kutil.json.JsonUtil.toJsonList
|
||||||
import de.bixilon.kutil.json.JsonUtil.toJsonObject
|
import de.bixilon.kutil.json.JsonUtil.toJsonObject
|
||||||
import de.bixilon.kutil.primitive.BooleanUtil.toBoolean
|
import de.bixilon.kutil.primitive.BooleanUtil.toBoolean
|
||||||
@ -90,15 +92,9 @@ class BaseComponent : ChatComponent {
|
|||||||
parseExtra()
|
parseExtra()
|
||||||
|
|
||||||
json["translate"]?.toString()?.let {
|
json["translate"]?.toString()?.let {
|
||||||
val with: MutableList<Any> = mutableListOf()
|
val with: Array<ChatComponent> = json.with(translator, component, restrictedMode) ?: emptyArray()
|
||||||
json["with"].toJsonList()?.let { withArray ->
|
|
||||||
for (part in withArray) {
|
|
||||||
if (part == null) continue
|
|
||||||
with += ChatComponent.of(raw = part, translator, component, restricted = restrictedMode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val fallback = json["fallback"]?.toString()
|
val fallback = json["fallback"]?.toString()
|
||||||
this += translator?.forceTranslate(it.toResourceLocation(), component, restrictedMode, fallback, *with.toTypedArray()) ?: ChatComponent.of(json["with"], translator, component, restrictedMode)
|
this += translator?.forceTranslate(it.toResourceLocation(), component, restrictedMode, fallback, data = with.unsafeCast()) ?: ChatComponent.of(json["with"], translator, component, restrictedMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,4 +272,15 @@ class BaseComponent : ChatComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun JsonObject.with(translator: Translator?, parent: TextComponent, restricted: Boolean): Array<ChatComponent>? {
|
||||||
|
val with = this["with"]?.toJsonList() ?: return null
|
||||||
|
val parts: MutableList<ChatComponent> = mutableListOf()
|
||||||
|
for (part in with) {
|
||||||
|
if (part == null) continue
|
||||||
|
parts += ChatComponent.of(raw = part, translator, parent, restricted = restricted)
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.toTypedArray()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user