mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
change the order of event in handle fn
This commit is contained in:
parent
d4d4ba054f
commit
5ffc46ae5c
2 changed files with 9 additions and 10 deletions
|
@ -33,7 +33,7 @@ impl BotTrait for azalea_client::Client {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl crate::Plugin for Plugin {
|
impl crate::Plugin for Plugin {
|
||||||
async fn handle(self: Arc<Self>, mut bot: Client, event: Arc<Event>) {
|
async fn handle(self: Arc<Self>, event: Arc<Event>, mut bot: Client) {
|
||||||
if let Event::Tick = *event {
|
if let Event::Tick = *event {
|
||||||
let mut state = self.state.lock();
|
let mut state = self.state.lock();
|
||||||
if state.jumping_once {
|
if state.jumping_once {
|
||||||
|
|
|
@ -11,10 +11,9 @@ use thiserror::Error;
|
||||||
/// Plugins can keep their own personal state, listen to events, and add new functions to Client.
|
/// Plugins can keep their own personal state, listen to events, and add new functions to Client.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Plugin: Send + Sync {
|
pub trait Plugin: Send + Sync {
|
||||||
async fn handle(self: Arc<Self>, bot: Client, event: Arc<Event>);
|
async fn handle(self: Arc<Self>, event: Arc<Event>, bot: Client);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub type HeuristicFn<N, W> = fn(start: &Vertex<N, W>, current: &Vertex<N, W>) -> W;
|
|
||||||
pub type HandleFn<Fut, S> = fn(Client, Arc<Event>, Arc<Mutex<S>>) -> Fut;
|
pub type HandleFn<Fut, S> = fn(Client, Arc<Event>, Arc<Mutex<S>>) -> Fut;
|
||||||
|
|
||||||
pub struct Options<S, A, Fut>
|
pub struct Options<S, A, Fut>
|
||||||
|
@ -65,18 +64,18 @@ pub async fn start<
|
||||||
|
|
||||||
while let Some(event) = rx.recv().await {
|
while let Some(event) = rx.recv().await {
|
||||||
// we put it into an Arc so it's cheaper to clone
|
// we put it into an Arc so it's cheaper to clone
|
||||||
|
|
||||||
let event = Arc::new(event);
|
let event = Arc::new(event);
|
||||||
|
|
||||||
for plugin in &options.plugins {
|
for plugin in &options.plugins {
|
||||||
tokio::spawn(plugin.clone().handle(bot.clone(), event.clone()));
|
tokio::spawn(plugin.clone().handle(event.clone(), bot.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
tokio::spawn(bot::Plugin::handle(
|
||||||
let bot_plugin = bot_plugin.clone();
|
bot_plugin.clone(),
|
||||||
let bot = bot.clone();
|
event.clone(),
|
||||||
let event = event.clone();
|
bot.clone(),
|
||||||
tokio::spawn(bot::Plugin::handle(bot_plugin, bot, event));
|
));
|
||||||
};
|
|
||||||
tokio::spawn((options.handle)(bot.clone(), event.clone(), state.clone()));
|
tokio::spawn((options.handle)(bot.clone(), event.clone(), state.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue