basalt_api/events/chat.rs
1//! Chat and command events.
2
3/// A player sent a chat message.
4///
5/// If cancelled, the message is not broadcast. The sender is
6/// available via `ctx.player()`.
7#[derive(Debug, Clone)]
8pub struct ChatMessageEvent {
9 /// The chat message content.
10 pub message: String,
11 /// Whether this event has been cancelled by a Validate handler.
12 pub cancelled: bool,
13}
14crate::instant_cancellable_event!(ChatMessageEvent);
15
16/// A player issued a command (e.g., `/tp 0 64 0`).
17///
18/// If cancelled, the command is not executed. The issuing player
19/// is available via `ctx.player()`.
20#[derive(Debug, Clone)]
21pub struct CommandEvent {
22 /// The command string without the leading `/`.
23 pub command: String,
24 /// Whether this event has been cancelled by a Validate handler.
25 pub cancelled: bool,
26}
27crate::instant_cancellable_event!(CommandEvent);
28
29#[cfg(test)]
30mod tests {
31 use crate::events::{BusKind, EventRouting};
32
33 use super::*;
34
35 #[test]
36 fn event_routing() {
37 assert_eq!(ChatMessageEvent::BUS, BusKind::Instant);
38 assert_eq!(CommandEvent::BUS, BusKind::Instant);
39 }
40}