aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-01-14 03:18:38 +0000
committermat <git@matdoes.dev>2025-01-14 03:18:38 +0000
commit2dcfbe96c3024f9e1d32473d58130efa518c91cf (patch)
treefb3eba8d165d80ab47dc83b41adab124e32dad8a /azalea-chat/src
parenta86d011d4ae869128dd404535f8d377c3a5e4c18 (diff)
downloadazalea-drasl-2dcfbe96c3024f9e1d32473d58130efa518c91cf.tar.xz
fix wrong ServerLinkKind and serialize hex colors correctly in nbt
Diffstat (limited to 'azalea-chat/src')
-rwxr-xr-xazalea-chat/src/style.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs
index fd2a58dd..57fe76a0 100755
--- a/azalea-chat/src/style.rs
+++ b/azalea-chat/src/style.rs
@@ -18,22 +18,14 @@ impl Serialize for TextColor {
where
S: Serializer,
{
- serializer.serialize_str(
- &self
- .name
- .as_ref()
- .map(|n| n.to_ascii_lowercase())
- .unwrap_or_else(|| self.format()),
- )
+ serializer.serialize_str(&self.serialize())
}
}
#[cfg(feature = "simdnbt")]
impl simdnbt::ToNbtTag for TextColor {
fn to_nbt_tag(self) -> simdnbt::owned::NbtTag {
- self.name
- .map(|n| NbtTag::String(n.to_ascii_lowercase().into()))
- .unwrap_or_else(|| NbtTag::Int(self.value as i32))
+ NbtTag::String(self.serialize().into())
}
}
@@ -274,18 +266,22 @@ impl TextColor {
Self { value, name }
}
- pub fn format(&self) -> String {
+ fn serialize(&self) -> String {
+ if let Some(name) = &self.name {
+ name.clone()
+ } else {
+ self.format_value()
+ }
+ }
+
+ pub fn format_value(&self) -> String {
format!("#{:06X}", self.value)
}
}
impl fmt::Display for TextColor {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- if let Some(name) = &self.name {
- write!(f, "{}", name.clone())
- } else {
- write!(f, "{}", self.format())
- }
+ write!(f, "{}", self.serialize())
}
}