This commit is contained in:
1 parent
6b5470fafc
commit
be2707a4f1
3 files changed
+19
-25
No files matched your search
@@ -6,7 +6,7 @@ use crate::entity::player::Player;
|
|||||||
|
|
||||||
use super::PlayerEvent;
|
use super::PlayerEvent;
|
||||||
|
|
||||||
/// An event that occurs when a player joins the game.
|
/// An event that occurs when a player is spawned and joined the game.
|
||||||
///
|
///
|
||||||
/// This event contains information about the player joining and a message to display upon joining.
|
/// This event contains information about the player joining and a message to display upon joining.
|
||||||
#[cancellable]
|
#[cancellable]
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ impl Server {
|
|||||||
'after: {
|
'after: {
|
||||||
player.screen_handler_sync_handler.store_player(player.clone()).await;
|
player.screen_handler_sync_handler.store_player(player.clone()).await;
|
||||||
if world
|
if world
|
||||||
.add_player(player.clone())
|
.add_player(&player)
|
||||||
.is_ok() {
|
.is_ok() {
|
||||||
let mut user_cache = self.data.user_cache.write().await;
|
let mut user_cache = self.data.user_cache.write().await;
|
||||||
user_cache.upsert(player.gameprofile.id, player.gameprofile.name.clone());
|
user_cache.upsert(player.gameprofile.id, player.gameprofile.name.clone());
|
||||||
|
|||||||
+17
-23
@@ -2067,6 +2067,22 @@ impl World {
|
|||||||
|
|
||||||
player.send_active_effects().await;
|
player.send_active_effects().await;
|
||||||
self.send_player_equipment(player).await;
|
self.send_player_equipment(player).await;
|
||||||
|
|
||||||
|
let msg_comp = TextComponent::translate(
|
||||||
|
translation::MULTIPLAYER_PLAYER_JOINED,
|
||||||
|
[TextComponent::text(player.gameprofile.name.clone())],
|
||||||
|
)
|
||||||
|
.color_named(NamedColor::Yellow);
|
||||||
|
let event = PlayerJoinEvent::new(player.clone(), msg_comp);
|
||||||
|
|
||||||
|
let event = server.plugin_manager.fire(event).await;
|
||||||
|
|
||||||
|
if !event.cancelled {
|
||||||
|
self.broadcast_system_message(&event.join_message, false)
|
||||||
|
.await;
|
||||||
|
// TODO: Switch to structured logging, e.g. info!(player = %name, "connected")
|
||||||
|
info!("{}", event.join_message.to_pretty_console());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_player_equipment(&self, from: &Player) {
|
async fn send_player_equipment(&self, from: &Player) {
|
||||||
@@ -2863,35 +2879,13 @@ impl World {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `uuid`: The unique UUID of the player to add.
|
|
||||||
/// * `player`: An `Arc<Player>` reference to the player object.
|
/// * `player`: An `Arc<Player>` reference to the player object.
|
||||||
pub fn add_player(&self, player: Arc<Player>) -> Result<(), String> {
|
pub fn add_player(&self, player: &Arc<Player>) -> Result<(), String> {
|
||||||
self.players.rcu(|current_list| {
|
self.players.rcu(|current_list| {
|
||||||
let mut new_list = (**current_list).clone();
|
let mut new_list = (**current_list).clone();
|
||||||
new_list.push(player.clone());
|
new_list.push(player.clone());
|
||||||
new_list
|
new_list
|
||||||
});
|
});
|
||||||
|
|
||||||
let server = self.server.upgrade().unwrap();
|
|
||||||
let current_players = self.players.load();
|
|
||||||
player.clone().spawn_task(async move {
|
|
||||||
let msg_comp = TextComponent::translate(
|
|
||||||
translation::MULTIPLAYER_PLAYER_JOINED,
|
|
||||||
[TextComponent::text(player.gameprofile.name.clone())],
|
|
||||||
)
|
|
||||||
.color_named(NamedColor::Yellow);
|
|
||||||
let event = PlayerJoinEvent::new(player.clone(), msg_comp);
|
|
||||||
|
|
||||||
let event = server.plugin_manager.fire(event).await;
|
|
||||||
|
|
||||||
if !event.cancelled {
|
|
||||||
for player in current_players.iter() {
|
|
||||||
player.send_system_message(&event.join_message).await;
|
|
||||||
}
|
|
||||||
// TODO: Switch to structured logging, e.g. info!(player = %name, "connected")
|
|
||||||
info!("{}", event.join_message.to_pretty_console());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user