Skip to main content

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(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)]
6pub struct ClientboundSetPlayerTeam {
7    pub name: String,
8    pub method: Method,
9}
10
11#[derive(AzBuf, Clone, Debug, PartialEq)]
12pub enum Method {
13    Add((Parameters, PlayerList)),
14    Remove,
15    Change(Parameters),
16    Join(PlayerList),
17    Leave(PlayerList),
18}
19
20#[derive(AzBuf, Clone, Debug, PartialEq)]
21pub struct Parameters {
22    pub display_name: FormattedText,
23    pub player_prefix: FormattedText,
24    pub player_suffix: FormattedText,
25    pub nametag_visibility: NameTagVisibility,
26    pub collision_rule: CollisionRule,
27    pub color: Option<ChatFormatting>,
28    pub options: u8,
29}
30
31#[derive(AzBuf, Clone, Copy, Debug, PartialEq)]
32pub enum CollisionRule {
33    Always,
34    Never,
35    PushOtherTeams,
36    PushOwnTeam,
37}
38
39#[derive(AzBuf, Clone, Copy, Debug, PartialEq)]
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::AzBuf;
54
55    use crate::packets::game::ClientboundSetPlayerTeam;
56
57    #[test]
58    fn read_set_player_team() {
59        // from hypixel
60        #[rustfmt::skip]
61        let contents = [12, 97, 56, 49, 56, 53, 51, 54, 100, 50, 98, 52, 52, 0, 10, 8, 0, 5, 99, 111, 108, 111, 114, 0, 5, 119, 104, 105, 116, 101, 8, 0, 4, 116, 101, 120, 116, 0, 12, 97, 56, 49, 56, 53, 51, 54, 100, 50, 98, 52, 52, 0, 10, 8, 0, 4, 116, 101, 120, 116, 0, 16, 194, 167, 97, 91, 86, 73, 80, 194, 167, 54, 43, 194, 167, 97, 93, 32, 0, 10, 8, 0, 4, 116, 101, 120, 116, 0, 0, 0, 0, 1, 1, 10, 3, 3, 10, 72, 97, 109, 97, 75, 105, 108, 108, 101, 114, 6, 90, 120, 121, 49, 111, 78, 10, 116, 97, 109, 97, 108, 101, 115, 102, 97, 109];
62        let mut buf = Cursor::new(contents.as_slice());
63        let _packet = ClientboundSetPlayerTeam::azalea_read(&mut buf).unwrap();
64
65        assert_eq!(buf.position(), contents.len() as u64);
66    }
67}