Skip to main content

Player

Struct Player 

Source
pub struct Player<'a> { /* private fields */ }
Expand description

A handle to one player, bound to a Server.

Construct with Player::new when you only have the player name (most event callbacks), or with Player::with_uuid when you also have the UUID (e.g. from [yog_command::CommandContext]) — the latter unlocks the full entity-layer API.

Implementations§

Source§

impl<'a> Player<'a>

Source

pub fn new(server: &'a dyn Server, name: impl Into<String>) -> Player<'a>

Bind to the player called name. Entity-level ops that require a UUID will return None/false; use Player::with_uuid to unlock them.

Source

pub fn with_uuid( server: &'a dyn Server, name: impl Into<String>, uuid: impl Into<String>, ) -> Player<'a>

Bind to the player with both name and uuid (full functionality).

Source

pub fn name(&self) -> &str

Source

pub fn uuid(&self) -> Option<&str>

Source

pub fn entity(&self) -> Option<Entity<'_>>

The underlying Entity handle, available when a UUID was provided.

Source

pub fn give(&self, item_id: &str, count: u32) -> bool

Give count of item_id (e.g. "minecraft:diamond").

Source

pub fn send_packet(&self, channel: &str, payload: &[u8]) -> bool

Send a raw-byte packet to this player on channel (server → client).

Source

pub fn teleport(&self, x: f64, y: f64, z: f64) -> bool

Teleport to (x, y, z). Uses the entity layer when a UUID is known; falls back to the player-name primitive otherwise.

Source

pub fn position(&self) -> Option<(f64, f64, f64)>

Current position, or None if the entity isn’t loaded / UUID unknown.

Source

pub fn health(&self) -> Option<f32>

Health, or None if UUID unknown.

Source

pub fn set_health(&self, health: f32) -> bool

Set health; returns false if UUID unknown.

Source

pub fn kill(&self) -> bool

Kill/remove this player entity; returns false if UUID unknown.

Source

pub fn send_title( &self, title: &str, subtitle: &str, fadein: i32, stay: i32, fadeout: i32, ) -> bool

Send a title+subtitle screen to this player.

Source

pub fn send_actionbar(&self, message: &str) -> bool

Send a message to the action-bar (above hotbar).

Source

pub fn kick(&self, reason: &str) -> bool

Disconnect this player with a reason message.

Source

pub fn set_gamemode(&self, gamemode: &str) -> bool

Change this player’s game mode ("survival", "creative", "adventure", "spectator").

Source

pub fn play_sound(&self, sound_id: &str, volume: f32, pitch: f32) -> bool

Play a sound at this player’s position (audible to nearby players too).

Source

pub fn add_effect( &self, effect_id: &str, duration_ticks: i32, amplifier: u8, show_particles: bool, ) -> bool

Source

pub fn remove_effect(&self, effect_id: &str) -> bool

Source

pub fn clear_effects(&self) -> bool

Source

pub fn inventory(&self) -> Vec<(u32, String, u32)>

All occupied slots: (slot_index, item_id, count).

Source

pub fn set_slot(&self, slot: u32, item_id: &str, count: u32) -> bool

Set or clear (count==0) a specific inventory slot.

Source

pub fn teleport_to_dim(&self, dimension: &str, x: f64, y: f64, z: f64) -> bool

Teleport to (x, y, z) in dimension (may be a different dimension).

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Player<'a>

§

impl<'a> !Send for Player<'a>

§

impl<'a> !Sync for Player<'a>

§

impl<'a> !UnwindSafe for Player<'a>

§

impl<'a> Freeze for Player<'a>

§

impl<'a> Unpin for Player<'a>

§

impl<'a> UnsafeUnpin for Player<'a>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.