Client

Struct Client 

Source
pub struct Client(/* private fields */);

Implementations§

Source§

impl Client

Source

pub async fn new(uri: impl AsRef<str>, config: ClientConfig) -> Result<Self>

Source

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.

Source

pub async fn is_connected(&self) -> bool

Returns if the underlying socket is actively connected.

Source

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;
Source

pub fn on_reconnect( &self, ) -> impl Stream<Item = StdResult<Self, BroadcastStreamRecvError>>

Returns a Stream where a message of type Client will be sent upon each successful reconnection.

Source

pub fn on_disconnect( &self, ) -> impl Stream<Item = StdResult<Self, BroadcastStreamRecvError>>

Returns a Stream where a message of type Client will be sent upon disconnect.

Source§

impl Client

Source

pub async fn allowlist(&self) -> Result<Vec<Player>>

Get the allowlist

Source

pub async fn allowlist_set(&self, players: Vec<Player>) -> Result<Vec<Player>>

Set the allowlist

Source

pub async fn allowlist_add(&self, add: Vec<Player>) -> Result<Vec<Player>>

Add players to allowlist

Source

pub async fn allowlist_remove(&self, remove: Vec<Player>) -> Result<Vec<Player>>

Remove players from allowlist

Source

pub async fn allowlist_clear(&self) -> Result<Vec<Player>>

Clear all players in allowlist

Source

pub async fn bans(&self) -> Result<Vec<UserBan>>

Get the ban list

Source

pub async fn bans_set(&self, bans: Vec<UserBan>) -> Result<Vec<UserBan>>

Set the banlist

Source

pub async fn bans_add(&self, add: Vec<UserBan>) -> Result<Vec<UserBan>>

Add players to ban list

Source

pub async fn bans_remove(&self, remove: Vec<Player>) -> Result<Vec<UserBan>>

Remove players from ban list

Source

pub async fn bans_clear(&self) -> Result<Vec<UserBan>>

Clear all players in ban list

Source

pub async fn ip_bans(&self) -> Result<Vec<IpBan>>

Get the ip ban list

Source

pub async fn ip_bans_set(&self, banlist: Vec<IpBan>) -> Result<Vec<IpBan>>

Set the ip banlist

Source

pub async fn ip_bans_add(&self, add: Vec<IncomingIpBan>) -> Result<Vec<IpBan>>

Add ip to ban list

Source

pub async fn ip_bans_remove(&self, ip: Vec<String>) -> Result<Vec<IpBan>>

Remove ip from ban list

Source

pub async fn ip_bans_clear(&self) -> Result<Vec<IpBan>>

Clear all ips in ban list

Source

pub async fn players(&self) -> Result<Vec<Player>>

Get all connected players

Source

pub async fn players_kick(&self, kick: Vec<KickPlayer>) -> Result<Vec<Player>>

Kick players

Source

pub async fn operators(&self) -> Result<Vec<Operator>>

Get all oped players

Source

pub async fn operators_set( &self, operators: Vec<Operator>, ) -> Result<Vec<Operator>>

Set all oped players

Source

pub async fn operators_add(&self, add: Vec<Operator>) -> Result<Vec<Operator>>

Op players

Source

pub async fn operators_remove( &self, remove: Vec<Player>, ) -> Result<Vec<Operator>>

Deop players

Source

pub async fn operators_clear(&self) -> Result<Vec<Operator>>

Deop all players

Source

pub async fn server_status(&self) -> Result<ServerState>

Get server status

Source

pub async fn server_save(&self, flush: bool) -> Result<bool>

Save server state

Source

pub async fn server_stop(&self) -> Result<bool>

Stop server

Source

pub async fn server_system_message( &self, message: SystemMessage, ) -> Result<bool>

Send a system message

Source

pub async fn serversettings_autosave(&self) -> Result<bool>

Get whether automatic world saving is enabled on the server

Source

pub async fn serversettings_autosave_set(&self, enable: bool) -> Result<bool>

Enable or disable automatic world saving on the server

Source

pub async fn serversettings_difficulty(&self) -> Result<Difficulty>

Get the current difficulty level of the server

Source

pub async fn serversettings_difficulty_set( &self, difficulty: Difficulty, ) -> Result<Difficulty>

Set the difficulty level of the server

Source

pub async fn serversettings_enforce_allowlist(&self) -> Result<bool>

Get whether allowlist enforcement is enabled (kicks players immediately when removed from allowlist)

Source

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)

Source

pub async fn serversettings_use_allowlist(&self) -> Result<bool>

Get whether the allowlist is enabled on the server

Source

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)

Source

pub async fn serversettings_max_players(&self) -> Result<i32>

Get the maximum number of players allowed to connect to the server

Source

pub async fn serversettings_max_players_set(&self, max: i32) -> Result<i32>

Set the maximum number of players allowed to connect to the server

Source

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

Source

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

Source

pub async fn serversettings_player_idle_timeout(&self) -> Result<i32>

Get the number of seconds before idle players are automatically kicked from the server

Source

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

Source

pub async fn serversettings_allow_flight(&self) -> Result<bool>

Get whether flight is allowed for players in Survival mode

Source

pub async fn serversettings_allow_flight_set(&self, allow: bool) -> Result<bool>

Allow or disallow flight for players in Survival mode

Source

pub async fn serversettings_motd(&self) -> Result<String>

Get the server’s message of the day displayed to players

Source

pub async fn serversettings_motd_set(&self, message: String) -> Result<String>

Set the server’s message of the day displayed to players

Source

pub async fn serversettings_spawn_protection_radius(&self) -> Result<i32>

Get the spawn protection radius in blocks (only operators can edit within this area)

Source

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)

Source

pub async fn serversettings_force_game_mode(&self) -> Result<bool>

Get whether players are forced to use the server’s default game mode

Source

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

Source

pub async fn serversettings_game_mode(&self) -> Result<GameType>

Get the server’s default game mode

Source

pub async fn serversettings_game_mode_set( &self, mode: GameType, ) -> Result<GameType>

Set the server’s default game mode

Source

pub async fn serversettings_view_distance(&self) -> Result<i32>

Get the server’s view distance in chunks

Source

pub async fn serversettings_view_distance_set( &self, distance: i32, ) -> Result<i32>

Set the server’s view distance in chunks

Source

pub async fn serversettings_simulation_distance(&self) -> Result<i32>

Get the server’s simulation distance in chunks

Source

pub async fn serversettings_simulation_distance_set( &self, distance: i32, ) -> Result<i32>

Set the server’s simulation distance in chunks

Source

pub async fn serversettings_accept_transfers(&self) -> Result<bool>

Get whether the server accepts player transfers from other servers

Source

pub async fn serversettings_accept_transfers_set( &self, accept: bool, ) -> Result<bool>

Enable or disable accepting player transfers from other servers

Source

pub async fn serversettings_status_heartbeat_interval(&self) -> Result<i32>

Get the interval in seconds between server status heartbeats

Source

pub async fn serversettings_status_heartbeat_interval_set( &self, seconds: i32, ) -> Result<i32>

Set the interval in seconds between server status heartbeats

Source

pub async fn serversettings_operator_user_permission_level(&self) -> Result<i32>

Get default operator permission level

Source

pub async fn serversettings_operator_user_permission_level_set( &self, level: i32, ) -> Result<i32>

Set default operator permission level

Source

pub async fn serversettings_hide_online_players(&self) -> Result<bool>

Get whether the server hides online player information from status queries

Source

pub async fn serversettings_hide_online_players_set( &self, hide: bool, ) -> Result<bool>

Enable or disable hiding online player information from status queries

Source

pub async fn serversettings_status_replies(&self) -> Result<bool>

Get whether the server responds to connection status requests

Source

pub async fn serversettings_status_replies_set( &self, enable: bool, ) -> Result<bool>

Enable or disable the server responding to connection status requests

Source

pub async fn serversettings_entity_broadcast_range(&self) -> Result<i32>

Get the entity broadcast range as a percentage

Source

pub async fn serversettings_entity_broadcast_range_set( &self, percentage_points: i32, ) -> Result<i32>

Set the entity broadcast range as a percentage

Source

pub async fn gamerules(&self) -> Result<Vec<TypedGameRule>>

Get the available game rule keys and their current values

Source

pub async fn gamerules_update( &self, gamerule: UntypedGameRule, ) -> Result<TypedGameRule>

Update game rule value

Source

pub async fn notification_server_started( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>

Server started

Source

pub async fn notification_server_stopping( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>

Server shutting down

Source

pub async fn notification_server_saving( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>

Server save started

Source

pub async fn notification_server_saved( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<()>, Error>>>>

Server save completed

Source

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

Source

pub async fn notification_players_joined( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>

Player joined

Source

pub async fn notification_players_left( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>

Player left

Source

pub async fn notification_operators_added( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Operator>, Error>>>>

Player was oped

Source

pub async fn notification_operators_removed( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Operator>, Error>>>>

Player was deoped

Source

pub async fn notification_allowlist_added( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>

Player was added to allowlist

Source

pub async fn notification_allowlist_removed( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>

Player was removed from allowlist

Source

pub async fn notification_ip_bans_added( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<IpBan>, Error>>>>

Ip was added to ip ban list

Source

pub async fn notification_ip_bans_removed( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<String>, Error>>>>

Ip was removed from ip ban list

Source

pub async fn notification_bans_added( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<UserBan>, Error>>>>

Player was added to ban list

Source

pub async fn notification_bans_removed( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<Player>, Error>>>>

Player was removed from ban list

Source

pub async fn notification_gamerules_updated( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<TypedGameRule>, Error>>>>

Gamerule was changed

Source

pub async fn notification_server_status( &self, ) -> Result<impl Stream<Item = Option<Result<Vec<ServerState>, Error>>>>

Server status heartbeat

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more