Skip to content

Commit 2dcfbe9

Browse files
committed
fix wrong ServerLinkKind and serialize hex colors correctly in nbt
1 parent a86d011 commit 2dcfbe9

File tree

6 files changed

+44
-23
lines changed

6 files changed

+44
-23
lines changed

azalea-chat/src/style.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,14 @@ impl Serialize for TextColor {
1818
where
1919
S: Serializer,
2020
{
21-
serializer.serialize_str(
22-
&self
23-
.name
24-
.as_ref()
25-
.map(|n| n.to_ascii_lowercase())
26-
.unwrap_or_else(|| self.format()),
27-
)
21+
serializer.serialize_str(&self.serialize())
2822
}
2923
}
3024

3125
#[cfg(feature = "simdnbt")]
3226
impl simdnbt::ToNbtTag for TextColor {
3327
fn to_nbt_tag(self) -> simdnbt::owned::NbtTag {
34-
self.name
35-
.map(|n| NbtTag::String(n.to_ascii_lowercase().into()))
36-
.unwrap_or_else(|| NbtTag::Int(self.value as i32))
28+
NbtTag::String(self.serialize().into())
3729
}
3830
}
3931

@@ -274,18 +266,22 @@ impl TextColor {
274266
Self { value, name }
275267
}
276268

277-
pub fn format(&self) -> String {
269+
fn serialize(&self) -> String {
270+
if let Some(name) = &self.name {
271+
name.clone()
272+
} else {
273+
self.format_value()
274+
}
275+
}
276+
277+
pub fn format_value(&self) -> String {
278278
format!("#{:06X}", self.value)
279279
}
280280
}
281281

282282
impl fmt::Display for TextColor {
283283
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
284-
if let Some(name) = &self.name {
285-
write!(f, "{}", name.clone())
286-
} else {
287-
write!(f, "{}", self.format())
288-
}
284+
write!(f, "{}", self.serialize())
289285
}
290286
}
291287

azalea-client/src/packet_handling/configuration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ pub fn send_packet_events(
4747
)) {
4848
Ok(packet) => packet,
4949
Err(err) => {
50-
error!("failed to read packet: {:?}", err);
51-
debug!("packet bytes: {:?}", raw_packet);
50+
error!("failed to read packet: {err:?}");
51+
debug!("packet bytes: {raw_packet:?}");
5252
continue;
5353
}
5454
};

azalea-client/src/packet_handling/game.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ pub fn send_packet_events(
165165
{
166166
Ok(packet) => packet,
167167
Err(err) => {
168-
error!("failed to read packet: {:?}", err);
169-
debug!("packet bytes: {:?}", raw_packet);
168+
error!("failed to read packet: {err:?}");
169+
debug!("packet bytes: {raw_packet:?}");
170170
continue;
171171
}
172172
};

azalea-protocol/src/common/server_links.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub struct ServerLinkEntry {
99

1010
#[derive(Clone, Debug, AzBuf)]
1111
pub enum ServerLinkKind {
12-
Known(KnownLinkKind),
1312
Component(FormattedText),
13+
Known(KnownLinkKind),
1414
}
1515

1616
#[derive(Clone, Copy, Debug, AzBuf)]

azalea-protocol/src/packets/game/c_container_set_content.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ mod tests {
1919
use azalea_buf::AzaleaRead;
2020

2121
use super::ClientboundContainerSetContent;
22-
use crate::packets::ProtocolPacket;
2322

2423
#[test]
2524
fn test_read_write_container_set_content() {
@@ -29,7 +28,7 @@ mod tests {
2928
0, 0, 0, 0, 0, 0, 0, 1, 196, 6, 0, 0, 0,
3029
];
3130
let mut buf = Cursor::new(contents.as_slice());
32-
let packet = ClientboundContainerSetContent::read(&mut buf).unwrap();
31+
let packet = ClientboundContainerSetContent::azalea_read(&mut buf).unwrap();
3332
println!("{:?}", packet);
3433

3534
assert_eq!(buf.position(), contents.len() as u64);

azalea-protocol/src/packets/game/c_server_links.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,29 @@ use crate::common::server_links::ServerLinkEntry;
77
pub struct ClientboundServerLinks {
88
pub links: Vec<ServerLinkEntry>,
99
}
10+
11+
#[cfg(test)]
12+
mod tests {
13+
use std::io::Cursor;
14+
15+
use azalea_buf::AzaleaRead;
16+
17+
use super::*;
18+
19+
#[test]
20+
fn test_read_server_links() {
21+
tracing_subscriber::fmt::try_init().ok();
22+
let contents = [
23+
1, 0, 10, 8, 0, 5, 99, 111, 108, 111, 114, 0, 7, 35, 48, 48, 70, 66, 57, 65, 8, 0, 4,
24+
116, 101, 120, 116, 0, 15, 65, 98, 111, 117, 116, 32, 86, 101, 108, 111, 99, 105, 116,
25+
97, 98, 0, 40, 104, 116, 116, 112, 115, 58, 47, 47, 119, 105, 108, 108, 105, 97, 109,
26+
50, 55, 56, 46, 110, 101, 116, 47, 112, 114, 111, 106, 101, 99, 116, 47, 118, 101, 108,
27+
111, 99, 105, 116, 97, 98,
28+
];
29+
let mut buf = Cursor::new(contents.as_slice());
30+
let packet = ClientboundServerLinks::azalea_read(&mut buf).unwrap();
31+
println!("{:?}", packet);
32+
33+
assert_eq!(buf.position(), contents.len() as u64);
34+
}
35+
}

0 commit comments

Comments
 (0)