1use valence_protocol::packets::play::CustomPayloadS2c;
2use valence_protocol::{ident, Bounded, Encode, VarInt, WritePacket};
34pub 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.
15fn set_brand(&mut self, brand: &str);
16}
1718impl<T: WritePacket> SetBrand for T {
19fn set_brand(&mut self, brand: &str) {
20let mut buf = vec![];
21let _ = VarInt(brand.len() as i32).encode(&mut buf);
22 buf.extend_from_slice(brand.as_bytes());
23self.write_packet(&CustomPayloadS2c {
24 channel: ident!("minecraft:brand").into(),
25 data: Bounded(buf.as_slice().into()),
26 });
27 }
28}