Skip to content

Commit 9d0fcc6

Browse files
committed
organize az-client file structure by moving things into plugins directory
1 parent e532511 commit 9d0fcc6

File tree

25 files changed

+162
-157
lines changed

25 files changed

+162
-157
lines changed

azalea-client/src/client.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,27 @@ use uuid::Uuid;
6262

6363
use crate::{
6464
attack::{self, AttackPlugin},
65+
brand::BrandPlugin,
6566
chat::ChatPlugin,
66-
chunks::{ChunkBatchInfo, ChunkPlugin},
67-
configuration::ConfigurationPlugin,
67+
chunks::{ChunkBatchInfo, ChunksPlugin},
6868
disconnect::{DisconnectEvent, DisconnectPlugin},
69-
events::{Event, EventPlugin, LocalPlayerEvents},
69+
events::{Event, EventsPlugin, LocalPlayerEvents},
7070
interact::{CurrentSequenceNumber, InteractPlugin},
7171
inventory::{Inventory, InventoryPlugin},
7272
local_player::{
73-
death_event, GameProfileComponent, Hunger, InstanceHolder, PermissionLevel,
74-
PlayerAbilities, TabList,
73+
GameProfileComponent, Hunger, InstanceHolder, PermissionLevel, PlayerAbilities, TabList,
7574
},
76-
mining::{self, MinePlugin},
77-
movement::{LastSentLookDirection, PhysicsState, PlayerMovePlugin},
75+
mining::{self, MiningPlugin},
76+
movement::{LastSentLookDirection, MovementPlugin, PhysicsState},
7877
packet::{
7978
login::{self, LoginSendPacketQueue},
80-
PacketHandlerPlugin,
79+
PacketPlugin,
8180
},
8281
player::retroactively_add_game_profile_component,
8382
raw_connection::RawConnection,
8483
respawn::RespawnPlugin,
85-
send_client_end::TickEndPlugin,
8684
task_pool::TaskPoolPlugin,
85+
tick_end::TickEndPlugin,
8786
Account, PlayerInfo,
8887
};
8988

@@ -818,8 +817,6 @@ impl Plugin for AzaleaPlugin {
818817
app.add_systems(
819818
Update,
820819
(
821-
// fire the Death event when the player dies.
822-
death_event,
823820
// add GameProfileComponent when we get an AddPlayerEvent
824821
retroactively_add_game_profile_component.after(EntityUpdateSet::Index),
825822
),
@@ -965,23 +962,23 @@ impl PluginGroup for DefaultPlugins {
965962
let mut group = PluginGroupBuilder::start::<Self>()
966963
.add(AmbiguityLoggerPlugin)
967964
.add(TimePlugin)
968-
.add(PacketHandlerPlugin)
965+
.add(PacketPlugin)
969966
.add(AzaleaPlugin)
970967
.add(EntityPlugin)
971968
.add(PhysicsPlugin)
972-
.add(EventPlugin)
969+
.add(EventsPlugin)
973970
.add(TaskPoolPlugin::default())
974971
.add(InventoryPlugin)
975972
.add(ChatPlugin)
976973
.add(DisconnectPlugin)
977-
.add(PlayerMovePlugin)
974+
.add(MovementPlugin)
978975
.add(InteractPlugin)
979976
.add(RespawnPlugin)
980-
.add(MinePlugin)
977+
.add(MiningPlugin)
981978
.add(AttackPlugin)
982-
.add(ChunkPlugin)
979+
.add(ChunksPlugin)
983980
.add(TickEndPlugin)
984-
.add(ConfigurationPlugin)
981+
.add(BrandPlugin)
985982
.add(TickBroadcastPlugin);
986983
#[cfg(feature = "log")]
987984
{

azalea-client/src/lib.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,13 @@
88
#![feature(error_generic_member_access)]
99

1010
mod account;
11-
pub mod attack;
12-
pub mod chat;
13-
pub mod chunks;
1411
mod client;
15-
pub mod configuration;
16-
pub mod disconnect;
1712
mod entity_query;
18-
pub mod events;
19-
pub mod interact;
20-
pub mod inventory;
2113
mod local_player;
22-
pub mod mining;
23-
pub mod movement;
24-
pub mod packet;
2514
pub mod ping;
2615
mod player;
16+
mod plugins;
2717
pub mod raw_connection;
28-
pub mod respawn;
29-
pub mod send_client_end;
30-
pub mod task_pool;
3118

3219
pub use account::{Account, AccountOpts};
3320
pub use azalea_protocol::common::client_information::ClientInformation;
@@ -41,3 +28,4 @@ pub use movement::{
4128
PhysicsState, SprintDirection, StartSprintEvent, StartWalkEvent, WalkDirection,
4229
};
4330
pub use player::PlayerInfo;
31+
pub use plugins::*;

azalea-client/src/local_player.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{collections::HashMap, io, sync::Arc};
22

33
use azalea_auth::game_profile::GameProfile;
44
use azalea_core::game_type::GameMode;
5-
use azalea_entity::Dead;
65
use azalea_protocol::packets::game::c_player_abilities::ClientboundPlayerAbilities;
76
use azalea_world::{Instance, PartialInstance};
87
use bevy_ecs::{component::Component, prelude::*};
@@ -13,10 +12,8 @@ use tokio::sync::mpsc;
1312
use tracing::error;
1413
use uuid::Uuid;
1514

16-
use crate::{
17-
events::{Event as AzaleaEvent, LocalPlayerEvents},
18-
ClientInformation, PlayerInfo,
19-
};
15+
use crate::Event as AzaleaEvent;
16+
use crate::{ClientInformation, PlayerInfo};
2017

2118
/// A component that keeps strong references to our [`PartialInstance`] and
2219
/// [`Instance`] for local players.
@@ -143,13 +140,6 @@ impl InstanceHolder {
143140
}
144141
}
145142

146-
/// Send the "Death" event for [`LocalEntity`]s that died with no reason.
147-
pub fn death_event(query: Query<&LocalPlayerEvents, Added<Dead>>) {
148-
for local_player_events in &query {
149-
local_player_events.send(AzaleaEvent::Death(None)).unwrap();
150-
}
151-
}
152-
153143
#[derive(Error, Debug)]
154144
pub enum HandlePacketError {
155145
#[error("{0}")]
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use bevy_ecs::prelude::*;
1212

1313
use crate::{client::InConfigState, packet::config::SendConfigPacketEvent};
1414

15-
pub struct ConfigurationPlugin;
16-
impl Plugin for ConfigurationPlugin {
15+
pub struct BrandPlugin;
16+
impl Plugin for BrandPlugin {
1717
fn build(&self, app: &mut App) {
1818
app.add_systems(
1919
Update,
@@ -22,13 +22,14 @@ impl Plugin for ConfigurationPlugin {
2222
}
2323
}
2424

25-
fn handle_in_configuration_state(
25+
pub fn handle_in_configuration_state(
2626
query: Query<(Entity, &ClientInformation), Added<InConfigState>>,
2727
mut send_packet_events: EventWriter<SendConfigPacketEvent>,
2828
) {
2929
for (entity, client_information) in query.iter() {
3030
let mut brand_data = Vec::new();
31-
// they don't have to know :)
31+
// azalea pretends to be vanilla everywhere else so it makes sense to lie here
32+
// too
3233
"vanilla".azalea_write(&mut brand_data).unwrap();
3334
send_packet_events.send(SendConfigPacketEvent::new(
3435
entity,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use std::time::{SystemTime, UNIX_EPOCH};
2+
3+
use azalea_protocol::packets::{
4+
game::{s_chat::LastSeenMessagesUpdate, ServerboundChat, ServerboundChatCommand},
5+
Packet,
6+
};
7+
use bevy_ecs::prelude::*;
8+
9+
use super::ChatKind;
10+
use crate::packet::game::SendPacketEvent;
11+
12+
/// Send a chat packet to the server of a specific kind (chat message or
13+
/// command). Usually you just want [`SendChatEvent`] instead.
14+
///
15+
/// Usually setting the kind to `Message` will make it send a chat message even
16+
/// if it starts with a slash, but some server implementations will always do a
17+
/// command if it starts with a slash.
18+
///
19+
/// If you're wondering why this isn't two separate events, it's so ordering is
20+
/// preserved if multiple chat messages and commands are sent at the same time.
21+
#[derive(Event)]
22+
pub struct SendChatKindEvent {
23+
pub entity: Entity,
24+
pub content: String,
25+
pub kind: ChatKind,
26+
}
27+
28+
pub fn handle_send_chat_kind_event(
29+
mut events: EventReader<SendChatKindEvent>,
30+
mut send_packet_events: EventWriter<SendPacketEvent>,
31+
) {
32+
for event in events.read() {
33+
let content = event
34+
.content
35+
.chars()
36+
.filter(|c| !matches!(c, '\x00'..='\x1F' | '\x7F' | '§'))
37+
.take(256)
38+
.collect::<String>();
39+
let packet = match event.kind {
40+
ChatKind::Message => ServerboundChat {
41+
message: content,
42+
timestamp: SystemTime::now()
43+
.duration_since(UNIX_EPOCH)
44+
.expect("Time shouldn't be before epoch")
45+
.as_millis()
46+
.try_into()
47+
.expect("Instant should fit into a u64"),
48+
salt: azalea_crypto::make_salt(),
49+
signature: None,
50+
last_seen_messages: LastSeenMessagesUpdate::default(),
51+
}
52+
.into_variant(),
53+
ChatKind::Command => {
54+
// TODO: chat signing
55+
ServerboundChatCommand { command: content }.into_variant()
56+
}
57+
};
58+
59+
send_packet_events.send(SendPacketEvent::new(event.entity, packet));
60+
}
61+
}
Lines changed: 25 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
//! Implementations of chat-related features.
22
3-
use std::{
4-
sync::Arc,
5-
time::{SystemTime, UNIX_EPOCH},
6-
};
3+
pub mod handler;
4+
5+
use std::sync::Arc;
76

87
use azalea_chat::FormattedText;
9-
use azalea_protocol::packets::{
10-
game::{
11-
c_disguised_chat::ClientboundDisguisedChat,
12-
c_player_chat::ClientboundPlayerChat,
13-
c_system_chat::ClientboundSystemChat,
14-
s_chat::{LastSeenMessagesUpdate, ServerboundChat},
15-
s_chat_command::ServerboundChatCommand,
16-
},
17-
Packet,
8+
use azalea_protocol::packets::game::{
9+
c_disguised_chat::ClientboundDisguisedChat, c_player_chat::ClientboundPlayerChat,
10+
c_system_chat::ClientboundSystemChat,
1811
};
1912
use bevy_app::{App, Plugin, Update};
2013
use bevy_ecs::{
@@ -23,12 +16,27 @@ use bevy_ecs::{
2316
prelude::Event,
2417
schedule::IntoSystemConfigs,
2518
};
19+
use handler::{handle_send_chat_kind_event, SendChatKindEvent};
2620
use uuid::Uuid;
2721

28-
use crate::{
29-
client::Client,
30-
packet::game::{handle_sendpacketevent, SendPacketEvent},
31-
};
22+
use crate::{client::Client, packet::game::handle_sendpacketevent};
23+
24+
pub struct ChatPlugin;
25+
impl Plugin for ChatPlugin {
26+
fn build(&self, app: &mut App) {
27+
app.add_event::<SendChatEvent>()
28+
.add_event::<SendChatKindEvent>()
29+
.add_event::<ChatReceivedEvent>()
30+
.add_systems(
31+
Update,
32+
(
33+
handle_send_chat_event,
34+
handle_send_chat_kind_event.after(handle_sendpacketevent),
35+
)
36+
.chain(),
37+
);
38+
}
39+
}
3240

3341
/// A chat packet, either a system message or a chat message.
3442
#[derive(Debug, Clone, PartialEq)]
@@ -180,23 +188,6 @@ impl Client {
180188
}
181189
}
182190

183-
pub struct ChatPlugin;
184-
impl Plugin for ChatPlugin {
185-
fn build(&self, app: &mut App) {
186-
app.add_event::<SendChatEvent>()
187-
.add_event::<SendChatKindEvent>()
188-
.add_event::<ChatReceivedEvent>()
189-
.add_systems(
190-
Update,
191-
(
192-
handle_send_chat_event,
193-
handle_send_chat_kind_event.after(handle_sendpacketevent),
194-
)
195-
.chain(),
196-
);
197-
}
198-
}
199-
200191
/// A client received a chat message packet.
201192
#[derive(Event, Debug, Clone)]
202193
pub struct ChatReceivedEvent {
@@ -232,63 +223,12 @@ pub fn handle_send_chat_event(
232223
}
233224
}
234225

235-
/// Send a chat packet to the server of a specific kind (chat message or
236-
/// command). Usually you just want [`SendChatEvent`] instead.
237-
///
238-
/// Usually setting the kind to `Message` will make it send a chat message even
239-
/// if it starts with a slash, but some server implementations will always do a
240-
/// command if it starts with a slash.
241-
///
242-
/// If you're wondering why this isn't two separate events, it's so ordering is
243-
/// preserved if multiple chat messages and commands are sent at the same time.
244-
#[derive(Event)]
245-
pub struct SendChatKindEvent {
246-
pub entity: Entity,
247-
pub content: String,
248-
pub kind: ChatKind,
249-
}
250-
251226
/// A kind of chat packet, either a chat message or a command.
252227
pub enum ChatKind {
253228
Message,
254229
Command,
255230
}
256231

257-
pub fn handle_send_chat_kind_event(
258-
mut events: EventReader<SendChatKindEvent>,
259-
mut send_packet_events: EventWriter<SendPacketEvent>,
260-
) {
261-
for event in events.read() {
262-
let content = event
263-
.content
264-
.chars()
265-
.filter(|c| !matches!(c, '\x00'..='\x1F' | '\x7F' | '§'))
266-
.take(256)
267-
.collect::<String>();
268-
let packet = match event.kind {
269-
ChatKind::Message => ServerboundChat {
270-
message: content,
271-
timestamp: SystemTime::now()
272-
.duration_since(UNIX_EPOCH)
273-
.expect("Time shouldn't be before epoch")
274-
.as_millis()
275-
.try_into()
276-
.expect("Instant should fit into a u64"),
277-
salt: azalea_crypto::make_salt(),
278-
signature: None,
279-
last_seen_messages: LastSeenMessagesUpdate::default(),
280-
}
281-
.into_variant(),
282-
ChatKind::Command => {
283-
// TODO: chat signing
284-
ServerboundChatCommand { command: content }.into_variant()
285-
}
286-
};
287-
288-
send_packet_events.send(SendPacketEvent::new(event.entity, packet));
289-
}
290-
}
291-
292232
// TODO
293233
// MessageSigner, ChatMessageContent, LastSeenMessages
294234
// fn sign_message() -> MessageSignature {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use crate::{
2626
InstanceHolder,
2727
};
2828

29-
pub struct ChunkPlugin;
30-
impl Plugin for ChunkPlugin {
29+
pub struct ChunksPlugin;
30+
impl Plugin for ChunksPlugin {
3131
fn build(&self, app: &mut App) {
3232
app.add_systems(
3333
Update,

0 commit comments

Comments
 (0)