2021-03-01 18:00:44 +00:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
|
2020-12-13 23:08:15 +00:00
|
|
|
use veloren_plugin_rt::{
|
2020-12-13 17:11:55 +00:00
|
|
|
api::{event::*, Action, GameMode},
|
|
|
|
*,
|
|
|
|
};
|
2020-12-09 20:47:42 +00:00
|
|
|
|
2021-02-16 23:11:05 +00:00
|
|
|
#[event_handler]
|
2020-12-13 12:27:48 +00:00
|
|
|
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-11 23:37:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 15:02:58 +00:00
|
|
|
#[event_handler]
|
|
|
|
pub fn on_command_testplugin(command: ChatCommandEvent) -> Result<Vec<String>, String> {
|
2020-12-13 17:11:55 +00:00
|
|
|
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()
|
2021-02-17 13:05:05 +00:00
|
|
|
.expect("Can't get player health"),
|
2021-02-17 13:03:20 +00:00
|
|
|
command.command_args
|
2020-12-13 17:11:55 +00:00
|
|
|
)])
|
2020-12-12 15:02:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-01 18:00:44 +00:00
|
|
|
static COUNTER: AtomicBool = AtomicBool::new(false);
|
|
|
|
|
2020-12-12 13:22:51 +00:00
|
|
|
#[event_handler]
|
2021-03-01 18:00:44 +00:00
|
|
|
pub fn on_join(input: PlayerJoinEvent) -> PlayerJoinResult {
|
|
|
|
if COUNTER.swap(!COUNTER.load(Ordering::SeqCst), Ordering::SeqCst) {
|
2021-03-01 20:29:18 +00:00
|
|
|
PlayerJoinResult::Kick(format!("You are a cheater {:?}", input))
|
2020-12-11 23:37:22 +00:00
|
|
|
} else {
|
|
|
|
PlayerJoinResult::None
|
|
|
|
}
|
2020-12-09 20:47:42 +00:00
|
|
|
}
|