mirror of
https://gitlab.bixilon.de/bixilon/pixlyzer.git
synced 2025-09-27 14:10:01 -04:00
message types: trim style even more
This commit is contained in:
parent
f1ac63a5ca
commit
370fda6eb8
@ -6,6 +6,7 @@ import de.bixilon.pixlyzer.util.ReflectionUtil.getField
|
||||
import de.bixilon.pixlyzer.util.Util
|
||||
import de.bixilon.pixlyzer.util.Util.JSON_MAP_TYPE
|
||||
import de.bixilon.pixlyzer.util.Util.compound
|
||||
import de.bixilon.pixlyzer.util.Util.mapCast
|
||||
import de.bixilon.pixlyzer.util.Util.nullCast
|
||||
import net.minecraft.text.Decoration
|
||||
import net.minecraft.text.Decoration.Parameter
|
||||
@ -42,14 +43,14 @@ object MessageTypeGenerator : Generator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun Any.serializeChat(): Map<String, Any>? {
|
||||
private fun Any.serializeChat(): Map<String, Any?>? {
|
||||
if (this is Decoration) {
|
||||
return this.serialize()
|
||||
}
|
||||
return getField(this::class.java, "decoration")?.nullCast<Optional<Decoration>>()?.get()?.serialize()
|
||||
}
|
||||
|
||||
fun Decoration.serialize(): Map<String, Any> {
|
||||
fun Decoration.serialize(): Map<String, Any?> {
|
||||
return mapOf(
|
||||
"translation_key" to translationKey,
|
||||
"parameters" to parameters.serialize(),
|
||||
@ -67,8 +68,11 @@ object MessageTypeGenerator : Generator(
|
||||
return output
|
||||
}
|
||||
|
||||
fun MutableMap<String, Any>.trimStyle(): Map<String, Any> {
|
||||
removeIf("empty") { it == true }
|
||||
fun MutableMap<String, Any>.trimStyle(): Map<String, Any>? {
|
||||
if (this["empty"] == true) {
|
||||
return null
|
||||
}
|
||||
remove("empty")
|
||||
removeIf("underlined") { it == false }
|
||||
removeIf("strikethrough") { it == false }
|
||||
removeIf("bold") { it == false }
|
||||
@ -76,6 +80,15 @@ object MessageTypeGenerator : Generator(
|
||||
removeIf("obfuscated") { it == false }
|
||||
removeIf("font") { it == DEFAULT_FONT }
|
||||
|
||||
this.remove("color")?.mapCast()?.let { color ->
|
||||
val name = color["name"]
|
||||
if (name != null) {
|
||||
this["color"] = name
|
||||
return@let
|
||||
}
|
||||
this["color"] = color["hexCode"]!!
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user