chunkedge_server/
title.rs1use chunkedge_protocol::encode::WritePacket;
2use chunkedge_protocol::packets::play::{
3 ClearTitlesS2c, SetActionBarTextS2c, SetSubtitleTextS2c, SetTitleTextS2c, SetTitlesAnimationS2c,
4};
5use chunkedge_protocol::text::IntoText;
6use chunkedge_protocol::IntoTextComponent;
7
8pub trait SetTitle {
9 fn set_title<'a>(&mut self, text: impl IntoText<'a>);
16
17 fn set_subtitle<'a>(&mut self, text: impl IntoText<'a>);
18
19 fn set_action_bar<'a>(&mut self, text: impl IntoText<'a>);
20
21 fn set_title_times(&mut self, fade_in: i32, stay: i32, fade_out: i32);
25
26 fn clear_title(&mut self);
27
28 fn reset_title(&mut self);
29}
30
31impl<T: WritePacket> SetTitle for T {
32 fn set_title<'a>(&mut self, text: impl IntoText<'a>) {
33 self.write_packet(&SetTitleTextS2c {
34 title_text: text.into_cow_text_component(),
35 });
36 }
37
38 fn set_subtitle<'a>(&mut self, text: impl IntoText<'a>) {
39 self.write_packet(&SetSubtitleTextS2c {
40 subtitle_text: text.into_cow_text_component(),
41 });
42 }
43
44 fn set_action_bar<'a>(&mut self, text: impl IntoText<'a>) {
45 self.write_packet(&SetActionBarTextS2c {
46 action_bar_text: text.into_cow_text_component(),
47 });
48 }
49
50 fn set_title_times(&mut self, fade_in: i32, stay: i32, fade_out: i32) {
51 self.write_packet(&SetTitlesAnimationS2c {
52 fade_in,
53 stay,
54 fade_out,
55 });
56 }
57
58 fn clear_title(&mut self) {
59 self.write_packet(&ClearTitlesS2c { reset: false });
60 }
61
62 fn reset_title(&mut self) {
63 self.write_packet(&ClearTitlesS2c { reset: true });
64 }
65}