From 00bfcde391c0f02e4eb9e7fb9f562ecebaeabb6d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 17 Nov 2022 17:42:30 +0000 Subject: move some stuff to the azalea_client::chat mod --- azalea-client/src/chat.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'azalea-client/src/chat.rs') diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs index 5eadc0c3..24ccbfd5 100755 --- a/azalea-client/src/chat.rs +++ b/azalea-client/src/chat.rs @@ -1,13 +1,32 @@ -use std::time::{SystemTime, UNIX_EPOCH}; +//! Implementations of chat-related features. +use crate::Client; +use azalea_chat::Component; use azalea_crypto::MessageSignature; use azalea_protocol::packets::game::{ - clientbound_player_chat_packet::LastSeenMessagesUpdate, + clientbound_player_chat_packet::{ClientboundPlayerChatPacket, LastSeenMessagesUpdate}, + clientbound_system_chat_packet::ClientboundSystemChatPacket, serverbound_chat_command_packet::ServerboundChatCommandPacket, serverbound_chat_packet::ServerboundChatPacket, }; +use std::time::{SystemTime, UNIX_EPOCH}; -use crate::Client; +/// A chat packet, either a system message or a chat message. +#[derive(Debug, Clone)] +pub enum ChatPacket { + System(ClientboundSystemChatPacket), + Player(Box), +} + +impl ChatPacket { + /// Get the message shown in chat for this packet. + pub fn message(&self) -> Component { + match self { + ChatPacket::System(p) => p.content.clone(), + ChatPacket::Player(p) => p.message(false), + } + } +} impl Client { /// Sends chat message to the server. This only sends the chat packet and -- cgit v1.2.3