minecraft-chat 0.1.0

Tiny library for minecraft chat messages.
Documentation
  • Coverage
  • 1.15%
    1 out of 87 items documented1 out of 36 items with examples
  • Size
  • Source code size: 23.36 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.88 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 27s Average build duration of successful builds.
  • all releases: 27s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • vagola

minecraft-chat

crates.io Build Status codecov

Minecraft chat are represented as json object. It's used in different packets. Information about format can be found at https://wiki.vg/Chat.

Usage

Add this to your Cargo.toml:

[dependencies]

minecraft-chat = "0.1"

Example

Serialize

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());

Deserialize

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());