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>
impl<'a> Player<'a>
Sourcepub fn new(server: &'a dyn Server, name: impl Into<String>) -> Player<'a>
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.
Sourcepub fn with_uuid(
server: &'a dyn Server,
name: impl Into<String>,
uuid: impl Into<String>,
) -> Player<'a>
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).
pub fn name(&self) -> &str
pub fn uuid(&self) -> Option<&str>
Sourcepub fn entity(&self) -> Option<Entity<'_>>
pub fn entity(&self) -> Option<Entity<'_>>
The underlying Entity handle, available when a UUID was provided.
Sourcepub fn give(&self, item_id: &str, count: u32) -> bool
pub fn give(&self, item_id: &str, count: u32) -> bool
Give count of item_id (e.g. "minecraft:diamond").
Sourcepub fn send_packet(&self, channel: &str, payload: &[u8]) -> bool
pub fn send_packet(&self, channel: &str, payload: &[u8]) -> bool
Send a raw-byte packet to this player on channel (server → client).
Sourcepub fn teleport(&self, x: f64, y: f64, z: f64) -> bool
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.
Sourcepub fn position(&self) -> Option<(f64, f64, f64)>
pub fn position(&self) -> Option<(f64, f64, f64)>
Current position, or None if the entity isn’t loaded / UUID unknown.
Sourcepub fn set_health(&self, health: f32) -> bool
pub fn set_health(&self, health: f32) -> bool
Set health; returns false if UUID unknown.
Sourcepub fn send_title(
&self,
title: &str,
subtitle: &str,
fadein: i32,
stay: i32,
fadeout: i32,
) -> bool
pub fn send_title( &self, title: &str, subtitle: &str, fadein: i32, stay: i32, fadeout: i32, ) -> bool
Send a title+subtitle screen to this player.
Sourcepub fn send_actionbar(&self, message: &str) -> bool
pub fn send_actionbar(&self, message: &str) -> bool
Send a message to the action-bar (above hotbar).
Sourcepub fn set_gamemode(&self, gamemode: &str) -> bool
pub fn set_gamemode(&self, gamemode: &str) -> bool
Change this player’s game mode ("survival", "creative", "adventure", "spectator").
Sourcepub fn play_sound(&self, sound_id: &str, volume: f32, pitch: f32) -> bool
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).
pub fn add_effect( &self, effect_id: &str, duration_ticks: i32, amplifier: u8, show_particles: bool, ) -> bool
pub fn remove_effect(&self, effect_id: &str) -> bool
pub fn clear_effects(&self) -> bool
Sourcepub fn inventory(&self) -> Vec<(u32, String, u32)>
pub fn inventory(&self) -> Vec<(u32, String, u32)>
All occupied slots: (slot_index, item_id, count).