forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtablist.rs
More file actions
64 lines (58 loc) · 1.83 KB
/
Copy pathtablist.rs
File metadata and controls
64 lines (58 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Sends tablist info to clients via the Player Info packet.
use base::{Gamemode, ProfileProperty};
use common::{
events::{EntityRemoveEvent, PlayerJoinEvent},
Game,
};
use ecs::{SysResult, SystemExecutor};
use quill_common::{components::Name, entities::Player};
use uuid::Uuid;
use crate::{ClientId, Server};
pub fn register(systems: &mut SystemExecutor<Game>) {
systems
.group::<Server>()
.add_system(remove_tablist_players)
.add_system(add_tablist_players);
}
fn remove_tablist_players(game: &mut Game, server: &mut Server) -> SysResult {
for (_, (_event, _player, &uuid)) in game
.ecs
.query::<(&EntityRemoveEvent, &Player, &Uuid)>()
.iter()
{
server.broadcast_with(|client| client.remove_tablist_player(uuid));
}
Ok(())
}
fn add_tablist_players(game: &mut Game, server: &mut Server) -> SysResult {
for (player, (_, &client_id, &uuid, name, &gamemode, profile)) in game
.ecs
.query::<(
&PlayerJoinEvent,
&ClientId,
&Uuid,
&Name,
&Gamemode,
&Vec<ProfileProperty>,
)>()
.iter()
{
// Add this player to other players' tablists
server.broadcast_with(|client| {
client.add_tablist_player(uuid, name.to_string(), profile, gamemode)
});
// Add other players to this player's tablist
for (other_player, (&uuid, name, &gamemode, profile)) in game
.ecs
.query::<(&Uuid, &Name, &Gamemode, &Vec<ProfileProperty>)>()
.iter()
{
if let Some(client) = server.clients.get(client_id) {
if other_player != player {
client.add_tablist_player(uuid, name.to_string(), profile, gamemode);
}
}
}
}
Ok(())
}