azalea_protocol/packets/game/
c_set_player_team.rs

1use azalea_buf::AzBuf;
2use azalea_chat::{FormattedText, style::ChatFormatting};
3use azalea_protocol_macros::ClientboundGamePacket;
4
5#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
6pub struct ClientboundSetPlayerTeam {
7    pub name: String,
8    pub method: Method,
9}
10
11#[derive(Clone, Debug, AzBuf)]
12pub enum Method {
13    Add((Parameters, PlayerList)),
14    Remove,
15    Change(Parameters),
16    Join(PlayerList),
17    Leave(PlayerList),
18}
19
20#[derive(Clone, Debug, AzBuf)]
21pub struct Parameters {
22    pub display_name: FormattedText,
23    pub options: u8,
24    pub nametag_visibility: NameTagVisibility,
25    pub collision_rule: CollisionRule,
26    pub color: ChatFormatting,
27    pub player_prefix: FormattedText,
28    pub player_suffix: FormattedText,
29}
30
31#[derive(Clone, Copy, Debug, AzBuf)]
32pub enum CollisionRule {
33    Always,
34    Never,
35    PushOtherTeams,
36    PushOwnTeam,
37}
38
39#[derive(Clone, Copy, Debug, AzBuf)]
40pub enum NameTagVisibility {
41    Always,
42    Never,
43    HideForOtherTeams,
44    HideForOwnTeam,
45}
46
47type PlayerList = Vec<String>;
48
49#[cfg(test)]
50mod tests {
51    use std::io::Cursor;
52
53    use azalea_buf::AzaleaRead;
54
55    use crate::packets::game::ClientboundSetPlayerTeam;
56
57    #[test]
58    fn test_read_set_player_team() {
59        let contents = [
60            16, 99, 111, 108, 108, 105, 100, 101, 82, 117, 108, 101, 95, 57, 52, 53, 54, 0, 8, 0,
61            16, 99, 111, 108, 108, 105, 100, 101, 82, 117, 108, 101, 95, 57, 52, 53, 54, 1, 0, 1,
62            21, 8, 0, 0, 8, 0, 0, 0,
63        ];
64        let mut buf = Cursor::new(contents.as_slice());
65        let packet = ClientboundSetPlayerTeam::azalea_read(&mut buf).unwrap();
66        println!("{packet:?}");
67
68        assert_eq!(buf.position(), contents.len() as u64);
69    }
70}