From 32dcc7a7752b448f9a7dc3e08ca1c86b36b894f5 Mon Sep 17 00:00:00 2001 From: Kumpelinus Date: Fri, 10 Jul 2026 14:24:24 +0200 Subject: [PATCH] Add list command --- src/default_commands/src/lib.rs | 1 + src/default_commands/src/list.rs | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/default_commands/src/list.rs diff --git a/src/default_commands/src/lib.rs b/src/default_commands/src/lib.rs index 177962cb..a36ad190 100644 --- a/src/default_commands/src/lib.rs +++ b/src/default_commands/src/lib.rs @@ -3,6 +3,7 @@ mod credits; pub mod echo; pub mod gamemode; mod kill; +mod list; mod motion; pub mod op; mod stop; diff --git a/src/default_commands/src/list.rs b/src/default_commands/src/list.rs new file mode 100644 index 00000000..03669f6a --- /dev/null +++ b/src/default_commands/src/list.rs @@ -0,0 +1,55 @@ +use bevy_ecs::prelude::{Entity, Query, Res, With}; +use temper_command_infra::{CommandHandler, CommandResult, CommandSource}; +use temper_components::entity_identity::Identity; +use temper_components::player::player_marker::PlayerMarker; +use temper_macros::Command; +use temper_state::GlobalStateResource; + +#[derive(Command)] +#[command(name = "list")] +enum ListCommand { + Normal, + #[literal("uuid")] + Uuid, +} + +impl CommandHandler for ListCommand { + type SystemParam<'w, 's> = ( + Res<'w, GlobalStateResource>, + Query<'w, 's, (Entity, &'static Identity), With>, + ); + + fn handle( + self, + source: CommandSource, + params: &mut Self::SystemParam<'_, '_>, + ) -> CommandResult { + let &mut (ref state, query) = params; + + let player_list = query + .into_iter() + .map(|(_, identity)| { + let Some(ref player_name) = identity.name else { + return Err("player entity does not have a name"); + }; + + Ok(match self { + ListCommand::Normal => player_name.clone(), + ListCommand::Uuid => format!("{player_name} ({})", identity.uuid), + }) + }) + .collect::, _>>()?; + + source.send_message( + format!( + "There are {} of a max of {} players online: {}", + player_list.len(), + state.0.config.max_players, + player_list.join(", "), + ) + .into(), + ); + + Ok(()) + } +}