Crates.io | minecraft-chat |
lib.rs | minecraft-chat |
version | 0.1.0 |
source | src |
created_at | 2019-12-22 15:28:49.952281 |
updated_at | 2019-12-22 15:28:49.952281 |
description | Tiny library for minecraft chat messages. |
homepage | https://github.com/eihwaz/minecraft-chat |
repository | https://github.com/eihwaz/minecraft-chat |
max_upload_size | |
id | 191487 |
size | 23,367 |
Minecraft chat are represented as json object. It's used in different packets. Information about format can be found at https://wiki.vg/Chat.
Add this to your Cargo.toml
:
[dependencies]
minecraft-chat = "0.1"
use minecraft_chat::{MessageBuilder, Payload, Color};
let message = MessageBuilder::builder(Payload::text("Hello"))
.color(Color::Yellow)
.bold(true)
.then(Payload::text("world"))
.color(Color::Green)
.bold(true)
.italic(true)
.then(Payload::text("!"))
.color(Color::Blue)
.build();
println!("{}", message.to_json().unwrap());
use minecraft_chat::{MessageBuilder, Color, Payload, Message};
let json = r#"
{
"bold":true,
"color":"yellow",
"text":"Hello",
"extra":[
{
"bold":true,
"italic":true,
"color":"green",
"text":"world"
},
{
"color":"blue",
"text":"!"
}
]
}
"#;
let expected_message = MessageBuilder::builder(Payload::text("Hello"))
.color(Color::Yellow)
.bold(true)
.then(Payload::text("world"))
.color(Color::Green)
.bold(true)
.italic(true)
.then(Payload::text("!"))
.color(Color::Blue)
.build();
assert_eq!(expected_message, Message::from_json(json).unwrap());