aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src/click_event.rs
diff options
context:
space:
mode:
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
+ }
+}