veloren/plugin/rt/examples/hello.rs

47 lines
1.3 KiB
Rust
Raw Permalink Normal View History

use veloren_plugin_rt::{
api::{event::*, Action, GameMode},
*,
};
#[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())),
}
}
2020-12-12 15:02:58 +00:00
#[event_handler]
pub fn on_command_testplugin(command: ChatCommandEvent) -> Result<Vec<String>, String> {
Ok(vec![format!(
2021-02-17 13:03:20 +00:00
"Player of id {:?} named {} with {:?} sended command with args {:?}",
command.player.id,
command
.player
.get_player_name()
.expect("Can't get player name"),
command
.player
.get_entity_health()
.expect("Can't get player health"),
2021-02-17 13:03:20 +00:00
command.command_args
)])
2020-12-12 15:02:58 +00:00
}
2021-03-02 16:15:19 +00:00
#[global_state]
#[derive(Default)]
struct State {
counter: bool,
}
#[event_handler]
2021-03-02 16:15:19 +00:00
pub fn on_join(input: PlayerJoinEvent, state: &mut State) -> PlayerJoinResult {
state.counter = !state.counter;
if !state.counter {
2021-03-01 20:29:18 +00:00
PlayerJoinResult::Kick(format!("You are a cheater {:?}", input))
} else {
PlayerJoinResult::None
}
}