minecraft-chat
============
[![crates.io](https://img.shields.io/crates/v/minecraft-chat.svg)](https://crates.io/crates/minecraft-chat)
[![Build Status](https://travis-ci.com/eihwaz/minecraft-chat.svg?branch=master)](https://travis-ci.com/eihwaz/minecraft-chat)
[![codecov](https://codecov.io/gh/eihwaz/minecraft-chat/branch/master/graph/badge.svg)](https://codecov.io/gh/eihwaz/minecraft-chat)
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`:
```toml
[dependencies]
minecraft-chat = "0.1"
```
```rust
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());
```
```rust
use minecraft_chat::{MessageBuilder, Color, Payload, Message};
let json = r#"
{
"bold":true,
"color":"yellow",
"text":"Hello",
"extra":[
]
}
"#;
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());
```