closing tui no longer crashes + onShutdown event

This commit is contained in:
Luuk van Oijen
2023-11-22 11:02:53 +01:00
parent 669e061fdf
commit 6ed714b863
7 changed files with 39 additions and 33 deletions

View File

@@ -45,6 +45,7 @@ impl PlayerIdentifiers {
#[derive(Debug)]
pub enum ScriptEvent {
OnPluginLoaded,
OnShutdown,
OnPlayerAuthenticated { name: String, role: String, is_guest: bool, identifiers: PlayerIdentifiers },
@@ -114,6 +115,13 @@ impl Plugin {
})
}
pub async fn close(mut self) {
let (tx, mut rx) = oneshot::channel();
self.send_event(PluginBoundPluginEvent::CallEventHandler((ScriptEvent::OnShutdown, Some(tx)))).await;
let _ = rx.await; // We just wait for it to finish shutting down
self.runtime.shutdown_background();
}
// TODO: For performance I think we can turn this into an iterator instead of first allocating
// a full vector?
pub fn get_events(&mut self) -> Vec<ServerBoundPluginEvent> {