pub struct Client(/* private fields */);Implementations§
Source§impl Client
impl Client
pub async fn new(uri: impl AsRef<str>, config: ClientConfig) -> Result<Self>
Sourcepub async fn close(&self) -> Result<()>
pub async fn close(&self) -> Result<()>
Calling Self::close means:
- Closing the underlying connection.
- Any and all internal client communication
- Closing every subscription stream
The Client is not guaranteed to be 100% closed after this function returns.
It may take a little while, use Self::wait_for_connection to make sure before, let’s say reconnecting.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Returns if the underlying socket is actively connected.
Sourcepub async fn wait_for_connection(
&self,
state: bool,
timeout_duration: Duration,
) -> Result<()>
pub async fn wait_for_connection( &self, state: bool, timeout_duration: Duration, ) -> Result<()>
Returns when the Self::is_connected is equal to state
If Self::is_connected already matches state, it instantly returns
§Example
// waits for the underlying connection to be ready & connected
client.wait_for_connection(true, Duration::from_secs(5)).await;
// waits for the connection to disconnect
client.wait_for_connection(false, Duration::from_secs(5)).await;Sourcepub fn on_reconnect(
&self,
) -> impl Stream<Item = StdResult<Self, BroadcastStreamRecvError>>
pub fn on_reconnect( &self, ) -> impl Stream<Item = StdResult<Self, BroadcastStreamRecvError>>
Sourcepub fn on_disconnect(
&self,
) -> impl Stream<Item = StdResult<Self, BroadcastStreamRecvError>>
pub fn on_disconnect( &self, ) -> impl Stream<Item = StdResult<Self, BroadcastStreamRecvError>>
Source§impl Client
impl Client
Sourcepub async fn allowlist_set(&self, players: Vec<Player>) -> Result<Vec<Player>>
pub async fn allowlist_set(&self, players: Vec<Player>) -> Result<Vec<Player>>
Set the allowlist
Sourcepub async fn allowlist_add(&self, add: Vec<Player>) -> Result<Vec<Player>>
pub async fn allowlist_add(&self, add: Vec<Player>) -> Result<Vec<Player>>
Add players to allowlist
Sourcepub async fn allowlist_remove(&self, remove: Vec<Player>) -> Result<Vec<Player>>
pub async fn allowlist_remove(&self, remove: Vec<Player>) -> Result<Vec<Player>>
Remove players from allowlist
Sourcepub async fn allowlist_clear(&self) -> Result<Vec<Player>>
pub async fn allowlist_clear(&self) -> Result<Vec<Player>>
Clear all players in allowlist
Sourcepub async fn bans_add(&self, add: Vec<UserBan>) -> Result<Vec<UserBan>>
pub async fn bans_add(&self, add: Vec<UserBan>) -> Result<Vec<UserBan>>
Add players to ban list
Sourcepub async fn bans_remove(&self, remove: Vec<Player>) -> Result<Vec<UserBan>>
pub async fn bans_remove(&self, remove: Vec<Player>) -> Result<Vec<UserBan>>
Remove players from ban list
Sourcepub async fn bans_clear(&self) -> Result<Vec<UserBan>>
pub async fn bans_clear(&self) -> Result<Vec<UserBan>>
Clear all players in ban list
Sourcepub async fn ip_bans_add(&self, add: Vec<IncomingIpBan>) -> Result<Vec<IpBan>>
pub async fn ip_bans_add(&self, add: Vec<IncomingIpBan>) -> Result<Vec<IpBan>>
Add ip to ban list
Sourcepub async fn ip_bans_remove(&self, ip: Vec<String>) -> Result<Vec<IpBan>>
pub async fn ip_bans_remove(&self, ip: Vec<String>) -> Result<Vec<IpBan>>
Remove ip from ban list
Sourcepub async fn ip_bans_clear(&self) -> Result<Vec<IpBan>>
pub async fn ip_bans_clear(&self) -> Result<Vec<IpBan>>
Clear all ips in ban list
Sourcepub async fn players_kick(&self, kick: Vec<KickPlayer>) -> Result<Vec<Player>>
pub async fn players_kick(&self, kick: Vec<KickPlayer>) -> Result<Vec<Player>>
Kick players
Sourcepub async fn operators_set(
&self,
operators: Vec<Operator>,
) -> Result<Vec<Operator>>
pub async fn operators_set( &self, operators: Vec<Operator>, ) -> Result<Vec<Operator>>
Set all oped players
Sourcepub async fn operators_remove(
&self,
remove: Vec<Player>,
) -> Result<Vec<Operator>>
pub async fn operators_remove( &self, remove: Vec<Player>, ) -> Result<Vec<Operator>>
Deop players
Sourcepub async fn operators_clear(&self) -> Result<Vec<Operator>>
pub async fn operators_clear(&self) -> Result<Vec<Operator>>
Deop all players
Sourcepub async fn server_status(&self) -> Result<ServerState>
pub async fn server_status(&self) -> Result<ServerState>
Get server status
Sourcepub async fn server_save(&self, flush: bool) -> Result<bool>
pub async fn server_save(&self, flush: bool) -> Result<bool>
Save server state
Sourcepub async fn server_stop(&self) -> Result<bool>
pub async fn server_stop(&self) -> Result<bool>
Stop server
Sourcepub async fn server_system_message(
&self,
message: SystemMessage,
) -> Result<bool>
pub async fn server_system_message( &self, message: SystemMessage, ) -> Result<bool>
Send a system message
Sourcepub async fn serversettings_autosave(&self) -> Result<bool>
pub async fn serversettings_autosave(&self) -> Result<bool>
Get whether automatic world saving is enabled on the server
Sourcepub async fn serversettings_autosave_set(&self, enable: bool) -> Result<bool>
pub async fn serversettings_autosave_set(&self, enable: bool) -> Result<bool>
Enable or disable automatic world saving on the server
Sourcepub async fn serversettings_difficulty(&self) -> Result<Difficulty>
pub async fn serversettings_difficulty(&self) -> Result<Difficulty>
Get the current difficulty level of the server
Sourcepub async fn serversettings_difficulty_set(
&self,
difficulty: Difficulty,
) -> Result<Difficulty>
pub async fn serversettings_difficulty_set( &self, difficulty: Difficulty, ) -> Result<Difficulty>
Set the difficulty level of the server
Sourcepub async fn serversettings_enforce_allowlist(&self) -> Result<bool>
pub async fn serversettings_enforce_allowlist(&self) -> Result<bool>
Get whether allowlist enforcement is enabled (kicks players immediately when removed from allowlist)
Sourcepub async fn serversettings_enforce_allowlist_set(
&self,
enforce: bool,
) -> Result<bool>
pub async fn serversettings_enforce_allowlist_set( &self, enforce: bool, ) -> Result<bool>
Enable or disable allowlist enforcement (when enabled, players are kicked immediately upon removal from allowlist)
Sourcepub async fn serversettings_use_allowlist(&self) -> Result<bool>
pub async fn serversettings_use_allowlist(&self) -> Result<bool>
Get whether the allowlist is enabled on the server
Sourcepub async fn serversettings_use_allowlist_set(&self, _use: bool) -> Result<bool>
pub async fn serversettings_use_allowlist_set(&self, _use: bool) -> Result<bool>
Enable or disable the allowlist on the server (controls whether only allowlisted players can join)
Sourcepub async fn serversettings_max_players(&self) -> Result<i32>
pub async fn serversettings_max_players(&self) -> Result<i32>
Get the maximum number of players allowed to connect to the server
Sourcepub async fn serversettings_max_players_set(&self, max: i32) -> Result<i32>
pub async fn serversettings_max_players_set(&self, max: i32) -> Result<i32>
Set the maximum number of players allowed to connect to the server
Sourcepub async fn serversettings_pause_when_empty_seconds(&self) -> Result<i32>
pub async fn serversettings_pause_when_empty_seconds(&self) -> Result<i32>
Get the number of seconds before the game is automatically paused when no players are online
Sourcepub async fn serversettings_pause_when_empty_seconds_set(
&self,
seconds: i32,
) -> Result<i32>
pub async fn serversettings_pause_when_empty_seconds_set( &self, seconds: i32, ) -> Result<i32>
Set the number of seconds before the game is automatically paused when no players are online
Sourcepub async fn serversettings_player_idle_timeout(&self) -> Result<i32>
pub async fn serversettings_player_idle_timeout(&self) -> Result<i32>
Get the number of seconds before idle players are automatically kicked from the server
Sourcepub async fn serversettings_player_idle_timeout_set(
&self,
seconds: i32,
) -> Result<i32>
pub async fn serversettings_player_idle_timeout_set( &self, seconds: i32, ) -> Result<i32>
Set the number of seconds before idle players are automatically kicked from the server
Sourcepub async fn serversettings_allow_flight(&self) -> Result<bool>
pub async fn serversettings_allow_flight(&self) -> Result<bool>
Get whether flight is allowed for players in Survival mode
Sourcepub async fn serversettings_allow_flight_set(&self, allow: bool) -> Result<bool>
pub async fn serversettings_allow_flight_set(&self, allow: bool) -> Result<bool>
Allow or disallow flight for players in Survival mode
Sourcepub async fn serversettings_motd(&self) -> Result<String>
pub async fn serversettings_motd(&self) -> Result<String>
Get the server’s message of the day displayed to players
Sourcepub async fn serversettings_motd_set(&self, message: String) -> Result<String>
pub async fn serversettings_motd_set(&self, message: String) -> Result<String>
Set the server’s message of the day displayed to players
Sourcepub async fn serversettings_spawn_protection_radius(&self) -> Result<i32>
pub async fn serversettings_spawn_protection_radius(&self) -> Result<i32>
Get the spawn protection radius in blocks (only operators can edit within this area)
Sourcepub async fn serversettings_spawn_protection_radius_set(
&self,
radius: i32,
) -> Result<i32>
pub async fn serversettings_spawn_protection_radius_set( &self, radius: i32, ) -> Result<i32>
Set the spawn protection radius in blocks (only operators can edit within this area)
Sourcepub async fn serversettings_force_game_mode(&self) -> Result<bool>
pub async fn serversettings_force_game_mode(&self) -> Result<bool>
Get whether players are forced to use the server’s default game mode
Sourcepub async fn serversettings_force_game_mode_set(
&self,
force: bool,
) -> Result<bool>
pub async fn serversettings_force_game_mode_set( &self, force: bool, ) -> Result<bool>
Enable or disable forcing players to use the server’s default game mode
Sourcepub async fn serversettings_game_mode(&self) -> Result<GameType>
pub async fn serversettings_game_mode(&self) -> Result<GameType>
Get the server’s default game mode
Sourcepub async fn serversettings_game_mode_set(
&self,
mode: GameType,
) -> Result<GameType>
pub async fn serversettings_game_mode_set( &self, mode: GameType, ) -> Result<GameType>
Set the server’s default game mode
Sourcepub async fn serversettings_view_distance(&self) -> Result<i32>
pub async fn serversettings_view_distance(&self) -> Result<i32>
Get the server’s view distance in chunks
Sourcepub async fn serversettings_view_distance_set(
&self,
distance: i32,
) -> Result<i32>
pub async fn serversettings_view_distance_set( &self, distance: i32, ) -> Result<i32>
Set the server’s view distance in chunks
Sourcepub async fn serversettings_simulation_distance(&self) -> Result<i32>
pub async fn serversettings_simulation_distance(&self) -> Result<i32>
Get the server’s simulation distance in chunks
Sourcepub async fn serversettings_simulation_distance_set(
&self,
distance: i32,
) -> Result<i32>
pub async fn serversettings_simulation_distance_set( &self, distance: i32, ) -> Result<i32>
Set the server’s simulation distance in chunks
Sourcepub async fn serversettings_accept_transfers(&self) -> Result<bool>
pub async fn serversettings_accept_transfers(&self) -> Result<bool>
Get whether the server accepts player transfers from other servers
Sourcepub async fn serversettings_accept_transfers_set(
&self,
accept: bool,
) -> Result<bool>
pub async fn serversettings_accept_transfers_set( &self, accept: bool, ) -> Result<bool>
Enable or disable accepting player transfers from other servers
Sourcepub async fn serversettings_status_heartbeat_interval(&self) -> Result<i32>
pub async fn serversettings_status_heartbeat_interval(&self) -> Result<i32>
Get the interval in seconds between server status heartbeats
Sourcepub async fn serversettings_status_heartbeat_interval_set(
&self,
seconds: i32,
) -> Result<i32>
pub async fn serversettings_status_heartbeat_interval_set( &self, seconds: i32, ) -> Result<i32>
Set the interval in seconds between server status heartbeats
Sourcepub async fn serversettings_operator_user_permission_level(&self) -> Result<i32>
pub async fn serversettings_operator_user_permission_level(&self) -> Result<i32>
Get default operator permission level
Sourcepub async fn serversettings_operator_user_permission_level_set(
&self,
level: i32,
) -> Result<i32>
pub async fn serversettings_operator_user_permission_level_set( &self, level: i32, ) -> Result<i32>
Set default operator permission level
Sourcepub async fn serversettings_hide_online_players(&self) -> Result<bool>
pub async fn serversettings_hide_online_players(&self) -> Result<bool>
Get whether the server hides online player information from status queries
Sourcepub async fn serversettings_hide_online_players_set(
&self,
hide: bool,
) -> Result<bool>
pub async fn serversettings_hide_online_players_set( &self, hide: bool, ) -> Result<bool>
Enable or disable hiding online player information from status queries
Sourcepub async fn serversettings_status_replies(&self) -> Result<bool>
pub async fn serversettings_status_replies(&self) -> Result<bool>
Get whether the server responds to connection status requests
Sourcepub async fn serversettings_status_replies_set(
&self,
enable: bool,
) -> Result<bool>
pub async fn serversettings_status_replies_set( &self, enable: bool, ) -> Result<bool>
Enable or disable the server responding to connection status requests
Sourcepub async fn serversettings_entity_broadcast_range(&self) -> Result<i32>
pub async fn serversettings_entity_broadcast_range(&self) -> Result<i32>
Get the entity broadcast range as a percentage
Sourcepub async fn serversettings_entity_broadcast_range_set(
&self,
percentage_points: i32,
) -> Result<i32>
pub async fn serversettings_entity_broadcast_range_set( &self, percentage_points: i32, ) -> Result<i32>
Set the entity broadcast range as a percentage
Sourcepub async fn gamerules(&self) -> Result<Vec<TypedGameRule>>
pub async fn gamerules(&self) -> Result<Vec<TypedGameRule>>
Get the available game rule keys and their current values
Sourcepub async fn gamerules_update(
&self,
gamerule: UntypedGameRule,
) -> Result<TypedGameRule>
pub async fn gamerules_update( &self, gamerule: UntypedGameRule, ) -> Result<TypedGameRule>
Update game rule value
Sourcepub async fn notification_server_started(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
pub async fn notification_server_started( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
Server started
Sourcepub async fn notification_server_stopping(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
pub async fn notification_server_stopping( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
Server shutting down
Sourcepub async fn notification_server_saving(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
pub async fn notification_server_saving( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
Server save started
Sourcepub async fn notification_server_saved(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
pub async fn notification_server_saved( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
Server save completed
Sourcepub async fn notification_server_activity(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
pub async fn notification_server_activity( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>
Server activity occurred. Rate limited to 1 notification per 30 seconds
Sourcepub async fn notification_players_joined(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
pub async fn notification_players_joined( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
Player joined
Sourcepub async fn notification_players_left(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
pub async fn notification_players_left( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
Player left
Sourcepub async fn notification_operators_added(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<Operator>, Error>>>>
pub async fn notification_operators_added( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Operator>, Error>>>>
Player was oped
Sourcepub async fn notification_operators_removed(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<Operator>, Error>>>>
pub async fn notification_operators_removed( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Operator>, Error>>>>
Player was deoped
Sourcepub async fn notification_allowlist_added(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
pub async fn notification_allowlist_added( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
Player was added to allowlist
Sourcepub async fn notification_allowlist_removed(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
pub async fn notification_allowlist_removed( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
Player was removed from allowlist
Sourcepub async fn notification_ip_bans_added(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<IpBan>, Error>>>>
pub async fn notification_ip_bans_added( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<IpBan>, Error>>>>
Ip was added to ip ban list
Sourcepub async fn notification_ip_bans_removed(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<String>, Error>>>>
pub async fn notification_ip_bans_removed( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<String>, Error>>>>
Ip was removed from ip ban list
Sourcepub async fn notification_bans_added(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<UserBan>, Error>>>>
pub async fn notification_bans_added( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<UserBan>, Error>>>>
Player was added to ban list
Sourcepub async fn notification_bans_removed(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
pub async fn notification_bans_removed( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>
Player was removed from ban list
Sourcepub async fn notification_gamerules_updated(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<TypedGameRule>, Error>>>>
pub async fn notification_gamerules_updated( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<TypedGameRule>, Error>>>>
Gamerule was changed
Sourcepub async fn notification_server_status(
&self,
) -> Result<impl Stream<Item = Option<Result<Vec<ServerState>, Error>>>>
pub async fn notification_server_status( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<ServerState>, Error>>>>
Server status heartbeat