Skip to content

Commit

Permalink
remove unwraps in events.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Jul 22, 2024
1 parent 86fd316 commit ca48ed9
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions azalea-client/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ impl Plugin for EventPlugin {
// when LocalPlayerEvents is added, it means the client just started
fn init_listener(query: Query<&LocalPlayerEvents, Added<LocalPlayerEvents>>) {
for local_player_events in &query {
local_player_events.send(Event::Init).unwrap();
let _ = local_player_events.send(Event::Init);
}
}

// when MinecraftEntityId is added, it means the player is now in the world
fn login_listener(query: Query<&LocalPlayerEvents, Added<MinecraftEntityId>>) {
for local_player_events in &query {
local_player_events.send(Event::Login).unwrap();
let _ = local_player_events.send(Event::Login);
}
}

Expand All @@ -152,16 +152,14 @@ fn chat_listener(query: Query<&LocalPlayerEvents>, mut events: EventReader<ChatR
let local_player_events = query
.get(event.entity)
.expect("Non-local entities shouldn't be able to receive chat events");
local_player_events
.send(Event::Chat(event.packet.clone()))
.unwrap();
let _ = local_player_events.send(Event::Chat(event.packet.clone()));
}
}

// only tick if we're in a world
fn tick_listener(query: Query<&LocalPlayerEvents, With<InstanceName>>) {
for local_player_events in &query {
local_player_events.send(Event::Tick).unwrap();
let _ = local_player_events.send(Event::Tick);
}
}

Expand All @@ -170,9 +168,7 @@ fn packet_listener(query: Query<&LocalPlayerEvents>, mut events: EventReader<Pac
let local_player_events = query
.get(event.entity)
.expect("Non-local entities shouldn't be able to receive packet events");
local_player_events
.send(Event::Packet(event.packet.clone()))
.unwrap();
let _ = local_player_events.send(Event::Packet(event.packet.clone()));
}
}

Expand All @@ -181,9 +177,7 @@ fn add_player_listener(query: Query<&LocalPlayerEvents>, mut events: EventReader
let local_player_events = query
.get(event.entity)
.expect("Non-local entities shouldn't be able to receive add player events");
local_player_events
.send(Event::AddPlayer(event.info.clone()))
.unwrap();
let _ = local_player_events.send(Event::AddPlayer(event.info.clone()));
}
}

Expand All @@ -195,9 +189,7 @@ fn update_player_listener(
let local_player_events = query
.get(event.entity)
.expect("Non-local entities shouldn't be able to receive update player events");
local_player_events
.send(Event::UpdatePlayer(event.info.clone()))
.unwrap();
let _ = local_player_events.send(Event::UpdatePlayer(event.info.clone()));
}
}

Expand All @@ -209,18 +201,14 @@ fn remove_player_listener(
let local_player_events = query
.get(event.entity)
.expect("Non-local entities shouldn't be able to receive remove player events");
local_player_events
.send(Event::RemovePlayer(event.info.clone()))
.unwrap();
let _ = local_player_events.send(Event::RemovePlayer(event.info.clone()));
}
}

pub fn death_listener(query: Query<&LocalPlayerEvents>, mut events: EventReader<DeathEvent>) {
for event in events.read() {
if let Ok(local_player_events) = query.get(event.entity) {
local_player_events
.send(Event::Death(event.packet.clone().map(|p| p.into())))
.unwrap();
let _ = local_player_events.send(Event::Death(event.packet.clone().map(|p| p.into())));
}
}
}
Expand All @@ -230,9 +218,7 @@ fn keepalive_listener(query: Query<&LocalPlayerEvents>, mut events: EventReader<
let local_player_events = query
.get(event.entity)
.expect("Non-local entities shouldn't be able to receive keepalive events");
local_player_events
.send(Event::KeepAlive(event.id))
.unwrap();
let _ = local_player_events.send(Event::KeepAlive(event.id));
}
}

Expand Down

0 comments on commit ca48ed9

Please sign in to comment.