mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-10 07:48:29 -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
|
* 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.
|
* 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 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 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(
|
val component = TextComponent(
|
||||||
message = text,
|
message = text,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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.protocol.protocol.encryption.CryptManager
|
||||||
import de.bixilon.minosoft.recipes.Ingredient
|
import de.bixilon.minosoft.recipes.Ingredient
|
||||||
import de.bixilon.minosoft.util.KUtil
|
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.Log
|
||||||
import de.bixilon.minosoft.util.logging.LogLevels
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||||
@ -116,6 +117,9 @@ class PlayInByteBuffer : InByteBuffer {
|
|||||||
return readChatComponent()
|
return readChatComponent()
|
||||||
}
|
}
|
||||||
val nbt = readNBT()
|
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)
|
return ChatComponent.of(nbt, connection.language, null, restricted = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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.
|
||||||
*
|
*
|
||||||
@ -299,6 +299,25 @@ internal class ChatComponentTest {
|
|||||||
assertEquals(text, expected)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
private fun assertEquals(expected: ChatComponent, actual: ChatComponent) {
|
private fun assertEquals(expected: ChatComponent, actual: ChatComponent) {
|
||||||
when (expected) {
|
when (expected) {
|
||||||
is BaseComponent -> {
|
is BaseComponent -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user