diff --git a/Cargo.lock b/Cargo.lock index 8e298a9076..7dc8d7606c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,7 +328,7 @@ source = "git+https://gitlab.com/veloren/auth.git?rev=bffb5181a35c19ddfd33ee0b4a dependencies = [ "auth-common", "fxhash", - "hex 0.3.2", + "hex", "reqwest", "rust-argon2", "serde", @@ -5976,6 +5976,7 @@ dependencies = [ "veloren-common", "veloren-common-net", "veloren-common-sys", + "veloren-plugin-api", "veloren_network", ] diff --git a/client/Cargo.toml b/client/Cargo.toml index d39bd94686..41c052a08c 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -31,6 +31,10 @@ vek = { version = "0.12.0", features = ["serde"] } hashbrown = { version = "0.9", features = ["rayon", "serde", "nightly"] } authc = { git = "https://gitlab.com/veloren/auth.git", rev = "bffb5181a35c19ddfd33ee0b4aedba741aafb68d" } +# Plugins + +plugin-api = { package = "veloren-plugin-api", path = "../plugin/api"} + [dev-dependencies] tracing-subscriber = { version = "0.2.3", default-features = false, features = ["fmt", "chrono", "ansi", "smallvec"] } diff --git a/client/src/lib.rs b/client/src/lib.rs index 4064ef854e..216c77c9d5 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -5,6 +5,9 @@ pub mod cmd; pub mod error; +#[cfg(feature = "plugins")] +pub use plugin_api::*; + // Reexports pub use crate::error::Error; pub use authc::AuthClientError; diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 3662b0695d..085694c191 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -20,6 +20,7 @@ mod social; mod spell; mod util; +use common_sys::plugin::PluginMgr; pub use hotbar::{SlotContents as HotbarSlotContents, State as HotbarState}; pub use settings_window::ScaleChange; @@ -53,19 +54,11 @@ use crate::{ window::{Event as WinEvent, FullScreenSettings, GameInput}, GlobalState, }; -use client::Client; -use common::{ - comp, - comp::{ +use client::{Client, event::{ChatCommandEvent, Player}}; +use common::{cmd::ChatCommand, comp, comp::{ item::{ItemDesc, Quality}, BuffKind, - }, - span, - terrain::TerrainChunk, - uid::Uid, - util::srgba_to_linear, - vol::RectRasterableVol, -}; + }, span, terrain::TerrainChunk, uid::Uid, util::srgba_to_linear, vol::RectRasterableVol}; use common_net::msg::{Notification, PresenceKind}; use conrod_core::{ text::cursor::Index, @@ -2018,7 +2011,37 @@ impl Hud { self.tab_complete = Some(input); }, Some(chat::Event::SendMessage(message)) => { - events.push(Event::SendMessage(message)); + println!("ROLLER 1: {}",message); + let manager = ecs.read_resource::(); + if message.starts_with("/") { + let mut cmd_iter = message.split(' '); + let command_tag = &cmd_iter.next().unwrap()[1..]; + let event = ChatCommandEvent { + command: message.clone(), + command_args: cmd_iter.map(|x| x.to_owned()).collect(), + player: Player { + id: ecs.read_storage::().get(entity).unwrap().clone(), + } + }; + match manager.execute_event(&format!("on_command_{}",command_tag), &event) { + Ok(e) => { + if e.is_empty() { + events.push(Event::SendMessage(message)); + } else { + println!("Send this message to the chat:"); + for i in &e { + println!("{:?}",i); + } + } + }, + Err(e) => { + println!("Error while hooking commands with plugins"); + println!("{:?}",e); + } + } + } else { + events.push(Event::SendMessage(message)); + } }, Some(chat::Event::Focus(focus_id)) => { self.to_focus = Some(Some(focus_id));