Skip to content

Read player data

This page shows how a plugin finds players, reads their data, tells their ids apart and changes them. In Paper a Player is an object with methods. In mcrs a player is an entity inside the world of a dimension, and its state is a set of components, so you write a query where Paper code would hold on to the object.

The examples come from repository files; this docs update did not run them.

Every player entity has the marker component Player. A system in a dimension world sees the players of that dimension only, as Dimensions explains. The test harness finds a player with this kind of query:

Find a player entity by its session
pub fn player_in(&mut self, dim: Entity, anchor: Entity) -> Option<Entity> {
let session = self.session_of(anchor)?;
let world = self.world_in(dim);
world
.query_filtered::<(Entity, &Owner), With<Player>>()
.iter(world)
.find(|(_, owner)| owner.0 == session)
.map(|(player, _)| player)
}

crates/mcrs_minecraft_server/tests/it/host_app/mod.rs:346-354

In a plugin you write the query as a system parameter, for example Query<(&GameProfile, &PlayerGameMode), With<Player>>. That line is an illustration and was not compiled. Its type names come from the files in the next section.

GameProfile is the profile that the client logged in with:

GameProfile
#[derive(Debug, Clone, Component, serde::Serialize, serde::Deserialize)]
pub struct GameProfile {
pub id: uuid::Uuid,
pub username: String,
pub properties: Vec<Property<String>>,
}

crates/mcrs_minecraft_engine_shared/src/game_profile.rs:6-11

The game mode is in the crate mcrs_minecraft_game_mode, so a server and a client use the same component. Its bevy feature adds the Component derive:

PlayerGameMode
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Deref, DerefMut, serde::Serialize, serde::Deserialize,
)]
#[cfg_attr(feature = "bevy", derive(bevy_ecs::component::Component))]
pub struct PlayerGameMode(pub GameMode);
impl Default for PlayerGameMode {

crates/mcrs_minecraft_game_mode/src/player_game_mode.rs:5-11

The flight state and the operator level are in the engine:

PlayerFlying
use mcrs_minecraft_engine_world::session::PlayerSession;
#[derive(
Component,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Deref,
DerefMut,
Default,
serde::Serialize,
serde::Deserialize,
)]
pub struct PlayerFlying(pub bool);

crates/mcrs_minecraft_engine_shared/src/ability.rs:6-21

PlayerOpLevel in the same file holds the operator level, which goes from 0 for a player who is not an operator up to 4. The test harness reads a game mode like this:

Read PlayerGameMode of a player
pub fn game_mode(&mut self, anchor: Entity) -> GameMode {
let player = self.player(anchor);
self.world().get::<PlayerGameMode>(player).unwrap().0
}

crates/mcrs_minecraft_server/tests/it/host_app/mod.rs:360-363

You cannot use one of these ids in place of another.

Id Where What it is
GameProfile::id component of the player the UUID of the profile, as in Paper
PlayerSession component Owner of the player in a dimension world; also on the host the name of one connection. The host never hands out a value twice, and a change of dimension keeps it
Entity the entity of the player inside one dimension world a Bevy id that exists in one world only. The host also has an anchor entity for the same player, and it is a different entity
PlayerSession
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PlayerSession(pub u64);

crates/mcrs_minecraft_engine_world/src/session/sessions.rs:8-9

Use the session to address a player across worlds and to send packets. Use the UUID for anything that must survive a reconnect.

The client sees one more number, the entity id in packets, and it does not depend on the world. A player gets an odd id made from its PlayerSession, so the id stays the same through a change of dimension. Other entities get even ids from ranges that the host hands to each dimension world, and an entity taken into another dimension keeps its id. While the server runs, no two entities share an id.1

Inside the world of a player you can insert or edit its components. Do not change a player from a system that runs in a different world. A change that crosses worlds is a message or an effect. The vanilla commands gamemode and teleport do this with command effects, see Add a command.

Max health, movement speed and the two interaction ranges that set the reach are attributes of a player. With VanillaEntityAttributesPlugin in the server, every player entity has the component AttributeInstances from the crate mcrs_minecraft_entity_attribute, and it starts with the bases of the player type, because PlayerAttributesPlugin registers it as a required component of Player. A system in the world of the player changes an attribute with apply. It takes an Attribute, such as Attribute::MaxHealth, and an InstanceEdit: SetBase sets the base value, Put adds or replaces a modifier, and Remove takes a modifier away by its id. The sprint plugin puts its modifier on movement speed while a player sprints and removes it when the player stops:

The sprint modifier on movement speed
fn give_sprint_modifier(
mut players: Populated<(&PlayerSprinting, &mut AttributeInstances), Changed<PlayerSprinting>>,
) {
for (sprinting, mut instances) in &mut players {
let edit = if sprinting.0 {
InstanceEdit::Put(InstanceModifier::transient(&SPRINT_MODIFIER))
} else {
InstanceEdit::Remove(SPRINT_MODIFIER.id.to_buf())
};
if instances
.bypass_change_detection()
.apply(Attribute::MovementSpeed, &edit)
== InstanceChange::Changed
{
instances.set_changed();
}
}
}

crates/mcrs_minecraft_vanilla_attributes/src/sprint_attribute_plugin.rs:30-47

apply returns an InstanceChange, and the system marks the component changed only when a value changed, so systems that wait for a change of AttributeInstances skip a player whose values stayed the same. Your plugin edits the component the same way. A repository test sets the base of Attribute::MaxHealth to 30 and reads it back after the player joins again.

The server sends each changed attribute to the client of the player and to the other players whose clients show this player. Only attributes that their definition marks as synced go out. The player file keeps the bases and the modifiers of kind ModifierKind::Permanent. A transient modifier, such as the sprint modifier, is not saved, but it stays with the player through a change of dimension.

The sprint modifier and the extra reach in creative mode (0.5 for blocks, 2.0 for entities) come from VanillaSprintAttributePlugin and VanillaCreativeRangePlugin. Each is a member of the server plugin group, so you can disable one and keep the other, as Remove and replace vanilla parts shows.

Use mcrs_minecraft_engine_player::SwingPlayer in the player’s world. SwingPlayer::new(player, hand, animation, duration) sends to current tracking observers, and default_main(player) chooses a six-tick main-hand whack. These constructors reject spectators and dead players. VanillaSwingPlugin supplies punch and piercing-weapon stab inputs, and placement and inventory plugins supply their own triggers.2

SwingPlayer::command(player, hand, animation, duration) includes the actor exactly once, even with no observers, and accepts spectators and dead players until corpse removal. Both paths share one cooldown across both hands, suppress delivery when the player disappears in the same tick and replay nothing to a later viewer. A swing request deals no damage. Mobs have a separate ECS path through swing_mob in mcrs_minecraft_engine_physics; it replicates a swing even when the mob stands still. The /swing command is not registered yet.3

This is server packet delivery. The mcrs client does not consume the swing packet or render its animation yet.

For health, damage filters, death messages and respawn requests, see Handle damage, death and respawn.

mcrs has no player.sendMessage(). The low-level way is to write a packet for a session. The chat plugin does this for a player who has chat hidden:

Write a system chat packet to the session of a player
if info.is_some_and(|info| info.chat_mode == ChatMode::Hidden) {
let disabled: Text = Text::translate("chat.disabled.options", vec![]).color(Color::RED);
if let Ok(disabled) = RawText::from_text(&disabled) {
packet_writer.write(mcrs_minecraft_engine_shared::to(
owner.0,
system_chat(disabled),
));
}
return;
}

crates/mcrs_minecraft_chat_server/src/chat_plugin.rs:54-63

A friendlier layer for this does not exist yet. We know of no issue for it, so we promise nothing.

The server saves player data to the player files of the world folder, as Worlds and saves describes. A component of your plugin goes into the player file only when the plugin registers it with PersistScope::Persisted, as the page on persisted components explains.4

Next: Handle damage, death and respawn.

  1. Works#158 Makes the entity ids on the wire independent of the owning world. ↩

  2. Works#1064 Replicates player arm swings through a public request and replaceable input plugin. ↩

  3. Works#1079 Adds self-included swing requests and stationary mob swing replication. ↩

  4. Works#159 One registry of persisted components for saving, handover and dimension travel. ↩

Sources and verification

Verified: 26.4-snapshot-7, 1cf84286c, 2026-11-30

Related open issues:

  • #1072 Partial Implement the /swing command