aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src/click_event.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-09-26 06:16:33 +0800
committermat <git@matdoes.dev>2025-09-25 19:20:09 -0300
commit730297cf561d42fd9132eb201d1aec0d3d7c7e00 (patch)
treed26f63b8a4553cc1b07c41a5b1a06aba773e60c4 /azalea-chat/src/click_event.rs
parent8927a0fe65f5f89b4459956f19989f27f1e0981c (diff)
downloadazalea-drasl-730297cf561d42fd9132eb201d1aec0d3d7c7e00.tar.xz
fix compile error with new serde version, and update deps
Diffstat (limited to 'azalea-chat/src/click_event.rs')
-rw-r--r--azalea-chat/src/click_event.rs47
1 files changed, 46 insertions, 1 deletions
diff --git a/azalea-chat/src/click_event.rs b/azalea-chat/src/click_event.rs
index dddaff74..a61e2561 100644
--- a/azalea-chat/src/click_event.rs
+++ b/azalea-chat/src/click_event.rs
@@ -1,6 +1,6 @@
use serde::Serialize;
#[cfg(feature = "simdnbt")]
-use simdnbt::owned::Nbt;
+use simdnbt::owned::{Nbt, NbtCompound, NbtTag};
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(rename_all = "snake_case", tag = "action")]
@@ -31,3 +31,48 @@ pub enum ClickEvent {
payload: Nbt,
},
}
+
+#[cfg(feature = "simdnbt")]
+impl simdnbt::Serialize for ClickEvent {
+ fn to_compound(self) -> NbtCompound {
+ let mut compound = NbtCompound::new();
+ let mut action = |s: &str| {
+ compound.insert("action", s);
+ };
+ match self {
+ ClickEvent::OpenUrl { url } => {
+ action("open_url");
+ compound.insert("url", url);
+ }
+ ClickEvent::OpenFile { path } => {
+ action("open_file");
+ compound.insert("path", path);
+ }
+ ClickEvent::RunCommand { command } => {
+ action("run_command");
+ compound.insert("command", command);
+ }
+ ClickEvent::SuggestCommand { command } => {
+ action("suggest_command");
+ compound.insert("command", command);
+ }
+ ClickEvent::ShowDialog => {
+ action("show_dialog");
+ }
+ ClickEvent::ChangePage { page } => {
+ action("change_page");
+ compound.insert("page", NbtTag::Int(page));
+ }
+ ClickEvent::CopyToClipboard { value } => {
+ action("copy_to_clipboard");
+ compound.insert("value", value);
+ }
+ ClickEvent::Custom { id, payload } => {
+ action("custom");
+ compound.insert("id", id);
+ compound.insert("payload", (**payload).clone());
+ }
+ }
+ compound
+ }
+}