diff --git a/hello_plugin/src/lib.rs b/hello_plugin/src/lib.rs new file mode 100644 index 0000000000..2de3c512ed --- /dev/null +++ b/hello_plugin/src/lib.rs @@ -0,0 +1,34 @@ +use veloren_plugin_rt::{ + api::{event::*, Action, GameMode}, + *, +}; + +#[veloren_plugin_rt::event_handler] +pub fn on_load(load: PluginLoadEvent) { + match load.game_mode { + GameMode::Server => emit_action(Action::Print("Hello, server!".to_owned())), + GameMode::Client => emit_action(Action::Print("Hello, client!".to_owned())), + GameMode::Singleplayer => emit_action(Action::Print("Hello, singleplayer!".to_owned())), + } +} + +#[event_handler] +pub fn on_command_testplugin(command: ChatCommandEvent) -> Result, String> { + Ok(vec![format!( + "Player of id {:?} sended command with args {:?}", + command.player, command.command_args + )]) +} + +#[event_handler] +pub fn on_player_join(input: PlayerJoinEvent) -> PlayerJoinResult { + emit_action(Action::PlayerSendMessage( + input.player_id, + format!("Welcome {} on our server", input.player_name), + )); + if input.player_name == "Cheater123" { + PlayerJoinResult::CloseConnection + } else { + PlayerJoinResult::None + } +}