Add character info to /players command

This commit is contained in:
scott-c 2020-06-01 21:01:10 +08:00
parent fe20da3923
commit 2d3f81b4c1

View File

@ -514,26 +514,28 @@ fn handle_players(
_action: &ChatCommand,
) {
let ecs = server.state.ecs();
let players = ecs.read_storage::<comp::Player>();
let count = players.join().count();
let header_message: String = format!("{} online players: \n", count);
if count > 0 {
let mut player_iter = players.join();
let first = player_iter
.next()
.expect("Player iterator returned none.")
.alias
.to_owned();
let player_list = player_iter.fold(first, |mut s, p| {
s += ",\n";
s += &p.alias;
s
});
server.notify_client(client, ServerMsg::private(header_message + &player_list));
} else {
server.notify_client(client, ServerMsg::private(header_message));
}
let entity_tuples = (
&ecs.entities(),
&ecs.read_storage::<comp::Player>(),
&ecs.read_storage::<comp::Stats>(),
);
server.notify_client(
client,
ServerMsg::private(entity_tuples.join().fold(
format!("{} online players:", entity_tuples.join().count()),
|s, (_, player, stat)| {
format!(
"{}\n[{}]{} Lvl {}",
s,
player.alias,
stat.name,
stat.level.level()
)
},
)),
);
}
fn handle_build(