diff --git a/protocol/src/format.rs b/protocol/src/format.rs index 6b4ba38..1b1bad9 100644 --- a/protocol/src/format.rs +++ b/protocol/src/format.rs @@ -22,6 +22,20 @@ pub enum Component { } impl Component { + + pub fn from_string(str: &str) -> Self { + let mut component; + match serde_json::from_str::(str) { + Ok(value) => component = Component::from_value(&value), + // Sometimes mojang sends a literal string, so we should interpret it literally + Err(_) => { + component = Component::Text(TextComponent::new(str)); + convert_legacy(&mut component); + }, + } + return component; + } + pub fn from_value(v: &serde_json::Value) -> Self { let mut modifier = Modifier::from_value(v); if let Some(val) = v.as_string() { diff --git a/protocol/src/nbt/mod.rs b/protocol/src/nbt/mod.rs index 5883c9e..ecd9495 100644 --- a/protocol/src/nbt/mod.rs +++ b/protocol/src/nbt/mod.rs @@ -20,7 +20,7 @@ use super::protocol::Serializable; use super::protocol; use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt}; -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum Tag { End, Byte(i8), @@ -36,7 +36,7 @@ pub enum Tag { IntArray(Vec), } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct NamedTag(pub String, pub Tag); impl Tag {