mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-08 14:59:16 -04:00
fix nbt chat insertion with translations + tests
This mainly affects 1.20+ and weird data thanks to nbt
This commit is contained in:
parent
48358f2d1b
commit
80ab673cfd
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
* Copyright (C) 2020-2024 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -58,7 +58,7 @@ class BaseComponent : ChatComponent, Iterable<ChatComponent> {
|
||||
val clickEvent = json["clickEvent", "click_event"]?.toJsonObject()?.let { click -> ClickEvents.build(click, restricted) } ?: parent?.clickEvent
|
||||
val hoverEvent = json["hoverEvent", "hover_event"]?.toJsonObject()?.let { hover -> HoverEvents.build(hover, restricted) } ?: parent?.hoverEvent
|
||||
|
||||
val text = json["text"]?.nullCast<String>() ?: ""
|
||||
val text = json["text", ""]?.nullCast<String>() ?: ""
|
||||
|
||||
val component = TextComponent(
|
||||
message = text,
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
* Copyright (C) 2020-2024 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -55,6 +55,7 @@ import de.bixilon.minosoft.protocol.protocol.buffers.InByteBuffer
|
||||
import de.bixilon.minosoft.protocol.protocol.encryption.CryptManager
|
||||
import de.bixilon.minosoft.recipes.Ingredient
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import de.bixilon.minosoft.util.json.Jackson
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@ -116,6 +117,9 @@ class PlayInByteBuffer : InByteBuffer {
|
||||
return readChatComponent()
|
||||
}
|
||||
val nbt = readNBT()
|
||||
if (DebugOptions.LOG_RAW_CHAT) {
|
||||
Log.log(LogMessageType.CHAT_IN, LogLevels.VERBOSE) { TextComponent(Jackson.MAPPER.writeValueAsString(nbt)) }
|
||||
}
|
||||
return ChatComponent.of(nbt, connection.language, null, restricted = true)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
* Copyright (C) 2020-2024 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -287,14 +287,33 @@ internal class ChatComponentTest {
|
||||
val hover = EntityHoverEvent("0d2dc333-f629-4b59-bdf9-074f58b99c06".toUUID(), minecraft("item"), name = TextComponent("item.item.slimeball"))
|
||||
|
||||
val expected = BaseComponent(
|
||||
TextComponent("[").color(ChatColors.GRAY).italic(),
|
||||
TextComponent("Bixilon").color(ChatColors.GRAY).italic(),
|
||||
TextComponent(": ").color(ChatColors.GRAY).italic(),
|
||||
TextComponent("[").color(ChatColors.GRAY).italic(),
|
||||
TextComponent("Bixilon").color(ChatColors.GRAY).italic(),
|
||||
TextComponent(": ").color(ChatColors.GRAY).italic(),
|
||||
BaseComponent(
|
||||
TextComponent("Killed ").color(ChatColors.GRAY).italic(),
|
||||
TextComponent("item.item.slimeball").color(ChatColors.GRAY).italic().hoverEvent(hover),
|
||||
),
|
||||
TextComponent("]").color(ChatColors.GRAY).italic(),
|
||||
TextComponent("]").color(ChatColors.GRAY).italic(),
|
||||
)
|
||||
assertEquals(text, expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `nbt solo text`() {
|
||||
val language = LanguageFile("en_US", Namespaces.MINECRAFT, mutableMapOf(
|
||||
"chat.type.admin" to "[%s: %s]"
|
||||
))
|
||||
val text = ChatComponent.of("""{"with":[{"color":"red","extra":[{"color":"red","text":"[Admins] "},{"":"Bixilon"},{"":""}],"insertion":"Bixilon"," text":""},{"text":"test"}],"color":"gray","italic":1,"translate":"chat.type.admin"}""", translator = language)
|
||||
val expected = BaseComponent(
|
||||
TextComponent("[").color(ChatColors.GRAY).italic(),
|
||||
BaseComponent(
|
||||
TextComponent("[Admins] ").color(ChatColors.RED).italic(),
|
||||
TextComponent("Bixilon").color(ChatColors.RED).italic(),
|
||||
),
|
||||
TextComponent(": ").color(ChatColors.GRAY).italic(),
|
||||
TextComponent("test").color(ChatColors.GRAY).italic(),
|
||||
TextComponent("]").color(ChatColors.GRAY).italic(),
|
||||
)
|
||||
assertEquals(text, expected)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user