mirror of
https://gitlab.bixilon.de/bixilon/pixlyzer.git
synced 2025-09-28 06:31:08 -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
|
||||||
import de.bixilon.pixlyzer.util.Util.JSON_MAP_TYPE
|
import de.bixilon.pixlyzer.util.Util.JSON_MAP_TYPE
|
||||||
import de.bixilon.pixlyzer.util.Util.compound
|
import de.bixilon.pixlyzer.util.Util.compound
|
||||||
|
import de.bixilon.pixlyzer.util.Util.mapCast
|
||||||
import de.bixilon.pixlyzer.util.Util.nullCast
|
import de.bixilon.pixlyzer.util.Util.nullCast
|
||||||
import net.minecraft.text.Decoration
|
import net.minecraft.text.Decoration
|
||||||
import net.minecraft.text.Decoration.Parameter
|
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) {
|
if (this is Decoration) {
|
||||||
return this.serialize()
|
return this.serialize()
|
||||||
}
|
}
|
||||||
return getField(this::class.java, "decoration")?.nullCast<Optional<Decoration>>()?.get()?.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(
|
return mapOf(
|
||||||
"translation_key" to translationKey,
|
"translation_key" to translationKey,
|
||||||
"parameters" to parameters.serialize(),
|
"parameters" to parameters.serialize(),
|
||||||
@ -67,8 +68,11 @@ object MessageTypeGenerator : Generator(
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
fun MutableMap<String, Any>.trimStyle(): Map<String, Any> {
|
fun MutableMap<String, Any>.trimStyle(): Map<String, Any>? {
|
||||||
removeIf("empty") { it == true }
|
if (this["empty"] == true) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
remove("empty")
|
||||||
removeIf("underlined") { it == false }
|
removeIf("underlined") { it == false }
|
||||||
removeIf("strikethrough") { it == false }
|
removeIf("strikethrough") { it == false }
|
||||||
removeIf("bold") { it == false }
|
removeIf("bold") { it == false }
|
||||||
@ -76,6 +80,15 @@ object MessageTypeGenerator : Generator(
|
|||||||
removeIf("obfuscated") { it == false }
|
removeIf("obfuscated") { it == false }
|
||||||
removeIf("font") { it == DEFAULT_FONT }
|
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
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user