2020-12-11 23:37:22 +00:00
|
|
|
use serde::{Serialize, de::DeserializeOwned, Deserialize};
|
2020-12-13 12:27:48 +00:00
|
|
|
use common::{sync, resources};
|
2020-12-11 23:37:22 +00:00
|
|
|
|
|
|
|
#[derive(Deserialize,Serialize,Debug)]
|
|
|
|
pub enum Action {
|
|
|
|
ServerClose,
|
|
|
|
Print(String),
|
|
|
|
PlayerSendMessage(usize,String),
|
|
|
|
KillEntity(usize)
|
|
|
|
}
|
|
|
|
|
2020-12-12 15:56:09 +00:00
|
|
|
pub trait Event: Serialize + DeserializeOwned + Send + Sync{
|
|
|
|
type Response: Serialize + DeserializeOwned + Send + Sync;
|
2020-12-11 23:37:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 12:27:48 +00:00
|
|
|
pub use resources::GameMode;
|
2020-12-12 15:02:58 +00:00
|
|
|
|
2020-12-12 19:26:42 +00:00
|
|
|
pub mod event {
|
|
|
|
use super::*;
|
2020-12-11 23:37:22 +00:00
|
|
|
use serde::{Serialize,Deserialize};
|
2020-12-12 13:01:54 +00:00
|
|
|
|
2020-12-12 15:02:58 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct ChatCommandEvent {
|
|
|
|
pub command: String,
|
|
|
|
pub command_args: Vec<String>,
|
|
|
|
pub player: Player,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Event for ChatCommandEvent {
|
|
|
|
type Response = Result<Vec<String>, String>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct Player {
|
2020-12-13 12:27:48 +00:00
|
|
|
pub id: sync::Uid,
|
2020-12-12 15:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
2020-12-11 23:37:22 +00:00
|
|
|
pub struct PlayerJoinEvent {
|
|
|
|
pub player_name: String,
|
|
|
|
pub player_id: usize
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Event for PlayerJoinEvent {
|
|
|
|
type Response = PlayerJoinResult;
|
|
|
|
}
|
|
|
|
|
2020-12-12 15:02:58 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
2020-12-11 23:37:22 +00:00
|
|
|
pub enum PlayerJoinResult {
|
|
|
|
CloseConnection,
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for PlayerJoinResult {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 15:02:58 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
2020-12-12 19:26:42 +00:00
|
|
|
pub struct PluginLoadEvent {
|
2020-12-13 12:27:48 +00:00
|
|
|
pub game_mode: GameMode,
|
2020-12-12 19:26:42 +00:00
|
|
|
}
|
2020-12-11 23:37:22 +00:00
|
|
|
|
|
|
|
impl Event for PluginLoadEvent {
|
|
|
|
type Response = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// #[derive(Serialize, Deserialize, Debug)]
|
|
|
|
// pub struct EmptyResult;
|
|
|
|
|
|
|
|
// impl Default for PlayerJoinResult {
|
|
|
|
// fn default() -> Self {
|
|
|
|
// Self::None
|
|
|
|
// }
|
|
|
|
// }
|
2020-12-12 13:01:54 +00:00
|
|
|
}
|