Rename /who to /players and fmt

This commit is contained in:
timokoesters 2019-06-29 14:05:30 +02:00
parent 7182257214
commit 6289a097a5
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097

View File

@ -99,10 +99,10 @@ lazy_static! {
handle_spawn,
),
ChatCommand::new(
"who",
"players",
"{}",
"/who : Show the online players list",
handle_who
"/players : Show the online players list",
handle_players,
),
ChatCommand::new(
"help", "", "/help: Display this message", handle_help)
@ -291,28 +291,24 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C
}
}
fn handle_who(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
fn handle_players(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
let ecs = server.state.ecs();
let players = ecs.read_storage::<comp::Player>();
let count = players.join().count();
let mut str: String = format!("Online players ({})", count);
if count > 0 {
str += ": ";
let mut player_list: String = players
.join()
.fold(String::new(), |mut s, player| {
s += &player.alias;
s += ",";
s
});
let mut player_list: String = players.join().fold(String::new(), |mut s, player| {
s += &player.alias;
s += ",";
s
});
player_list.pop();
server
.clients
.notify(entity, ServerMsg::Chat(str + &player_list));
.clients
.notify(entity, ServerMsg::Chat(str + &player_list));
} else {
server
.clients
.notify(entity, ServerMsg::Chat(str));
server.clients.notify(entity, ServerMsg::Chat(str));
}
}