valence_server/
brand.rs

1use valence_protocol::packets::play::CustomPayloadS2c;
2use valence_protocol::{ident, Bounded, Encode, VarInt, WritePacket};
3
4pub trait SetBrand {
5    /// Sets the brand of the server.
6    ///
7    /// The Brand is displayed to the client in the F3 screen
8    /// and is often used to display the server name.
9    /// Any valid &str can be used.
10    ///
11    /// However, the legacy formatting codes are used,
12    /// which means that while color and other formatting can technically be
13    /// used, it needs to use the § character, which needs to be encoded as
14    /// 0xC2, 0xA7.
15    fn set_brand(&mut self, brand: &str);
16}
17
18impl<T: WritePacket> SetBrand for T {
19    fn set_brand(&mut self, brand: &str) {
20        let mut buf = vec![];
21        let _ = VarInt(brand.len() as i32).encode(&mut buf);
22        buf.extend_from_slice(brand.as_bytes());
23        self.write_packet(&CustomPayloadS2c {
24            channel: ident!("minecraft:brand").into(),
25            data: Bounded(buf.as_slice().into()),
26        });
27    }
28}