tab list: correctly read text as nbt + tests

This commit is contained in:
Moritz Zwerger 2023-12-08 18:50:54 +01:00
parent a2971c3a0c
commit 25a5becbbd
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,42 @@
/*
* Minosoft
* Copyright (C) 2020-2023 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 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.tab
import de.bixilon.kutil.uuid.UUIDUtil.toUUID
import de.bixilon.minosoft.data.entities.entities.player.additional.AdditionalDataUpdate
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.protocol.packets.s2c.play.PacketReadingTestUtil
import org.testng.Assert.assertEquals
import org.testng.annotations.Test
@Test(groups = ["packet"])
class TabListS2CPTest {
fun `greev_eu 1_15_2`() {
val packet = PacketReadingTestUtil.read("tab/greev_eu_1_15_2", "1.15.2", constructor = ::TabListS2CP)
assertEquals(packet.entries["24f0d4a2-1787-4761-aeef-39c90824e746".toUUID()], AdditionalDataUpdate(hasDisplayName = true, displayName = TextComponent(" thewating ").color(ChatColors.GREEN)))
}
fun `greev_eu 1_20_2`() {
val packet = PacketReadingTestUtil.read("tab/greev_eu_1_20_2", "1.20.2", constructor = ::TabListS2CP)
assertEquals(packet.entries["24f0d4a2-1787-4761-aeef-39c90824e746".toUUID()], AdditionalDataUpdate(hasDisplayName = true, displayName = TextComponent(" thewating ").color(ChatColors.GREEN)))
}
fun `greev_eu 1_20_4`() {
val packet = PacketReadingTestUtil.read("tab/greev_eu_1_20_4", "1.20.4", constructor = ::TabListS2CP)
assertEquals(packet.entries["24f0d4a2-1787-4761-aeef-39c90824e746".toUUID()], AdditionalDataUpdate(hasDisplayName = true, displayName = TextComponent(" thewating ").color(ChatColors.GREEN)))
}
}

View File

@ -0,0 +1 @@
$ðÔ¢‡Ga®ï9É$çF<{"extra":[{"color":"green","text":" thewating "}],"text":""}

View File

@ -0,0 +1 @@
$ðÔ¢‡Ga®ï9É$çF<{"extra":[{"color":"green","text":" thewating "}],"text":""}

View File

@ -19,7 +19,7 @@ import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
object DisplayNameAction : AbstractAction {
override fun read(buffer: PlayInByteBuffer, entry: AdditionalDataUpdate) {
entry.displayName = buffer.readOptional { buffer.readChatComponent() }
entry.displayName = buffer.readOptional { buffer.readNbtChatComponent() }
entry.hasDisplayName = entry.displayName != null
}
}