minecraft_pinger/java/
config.rs1use crate::config::{PingConfig, DEFAULT_PROTOCOL_VERSION, PingConfigBuilder};
2
3#[derive(Clone)]
4pub struct JavaPingConfig {
5 common: PingConfig,
6 protocol_version: i32,
7 hostname: Option<String>,
8}
9
10impl JavaPingConfig {
11 pub fn builder() -> JavaPingConfigBuilder {
12 JavaPingConfigBuilder::new()
13 }
14
15 pub fn from(config: &PingConfigBuilder) -> JavaPingConfigBuilder {
16 JavaPingConfigBuilder::from(config)
17 }
18
19 pub fn protocol_version(&self) -> i32 {
20 self.protocol_version
21 }
22
23 pub fn common(&self) -> &PingConfig {
24 &self.common
25 }
26
27 pub fn hostname(&self) -> &Option<String> {
28 &self.hostname
29 }
30}
31
32impl Default for JavaPingConfig {
33 fn default() -> Self {
34 Self::builder().build()
35 }
36}
37
38pub struct JavaPingConfigBuilder {
39 common: PingConfigBuilder,
40 protocol_version: i32,
41 hostname: Option<String>,
42}
43
44impl JavaPingConfigBuilder {
45 pub fn new() -> Self {
46 JavaPingConfigBuilder {
47 common: PingConfigBuilder::new(),
48 protocol_version: DEFAULT_PROTOCOL_VERSION,
49 hostname: None
50 }
51 }
52
53 pub fn from(config: &PingConfigBuilder) -> Self {
54 JavaPingConfigBuilder {
55 common: config.clone(),
56 protocol_version: DEFAULT_PROTOCOL_VERSION,
57 hostname: None
58 }
59 }
60
61 pub fn set_protocol_version(mut self, protocol_version: i32) -> Self {
62 self.protocol_version = protocol_version;
63 self
64 }
65
66 pub fn set_hostname(mut self, hostname: Option<String>) -> Self {
67 self.hostname = hostname;
68 self
69 }
70
71 pub fn build(self) -> JavaPingConfig {
72 JavaPingConfig {
73 common: self.common.build(),
74 hostname: self.hostname,
75 protocol_version: self.protocol_version
76 }
77 }
78}