Add more events to the Plugin API (#552)

* Add PlayerChangeWorld event

* Fix docs

* Add PlayerGamemodeChange event

* Add PlayerLogin event

* Fix clippy

* Fix docs

* Add PlayerChat event

* Fix some event impls

* Post-merge issues

* Add PlayerCommandSend event

* Fix PlayerCommandSend event

* Fix PlayerLogin event docs

* Add PlayerMove event

* Implement PlayerCommandSend event

* Implement player position sync when move event cancelled

* Add PlayerMove event to handle_position_rotation

* Fix docs

* Implement PlayerTeleport event

* Add ServerBroadcast event

* Fix some event impls

* Add ServerPluginEnable event

* Add ServerPluginDisable event

* Implement plugin enable/disable events

* Add ServerComand event

* Fix clippy

* Add teleport method to player

* Fix player teleport event impl

* Fix imports

* remove not needed clones

* Fix clippy

* Fix formatting

* Respect server.defaultgamemode

---------

Co-authored-by: Alexander Medvedev <lilalexmed@proton.me>
This commit is contained in:
vyPal
2025-03-12 08:14:40 +01:00
committed by GitHub
parent b8810e8102
commit f0bdfc943e
20 changed files with 1081 additions and 335 deletions

View File

@@ -0,0 +1,45 @@
use pumpkin_macros::{Event, cancellable};
use std::sync::Arc;
use crate::entity::player::Player;
use super::PlayerEvent;
/// An event that occurs when a player executes a command
///
/// If the event is cancelled, the command will not be executed.
///
/// This event contains information about the player, and the command being executed.
#[cancellable]
#[derive(Event, Clone)]
pub struct PlayerCommandSendEvent {
/// The player who is executing the command.
pub player: Arc<Player>,
/// The command being executed
pub command: String,
}
impl PlayerCommandSendEvent {
/// Creates a new instance of `PlayerCommandSendEvent`.
///
/// # Arguments
/// - `player`: A reference to the player running a command.
/// - `command`: The command being executed.
///
/// # Returns
/// A new instance of `PlayerCommandSendEvent`.
pub fn new(player: Arc<Player>, command: String) -> Self {
Self {
player,
command,
cancelled: false,
}
}
}
impl PlayerEvent for PlayerCommandSendEvent {
fn get_player(&self) -> &Arc<Player> {
&self.player
}
}