Moved plugin API to Uid instead of usize for entity IDs, hello plugin to an example

This commit is contained in:
Joshua Barretto
2020-12-13 23:08:15 +00:00
parent 023888f560
commit fc96fd780b
13 changed files with 18 additions and 1621 deletions

View File

@ -9,3 +9,10 @@ plugin-api = { package = "veloren-plugin-api", path = "../api" }
plugin-derive = { package = "veloren-plugin-derive", path = "../derive"}
serde = {version = "1.0.118", features = ["derive"]}
bincode = "1.3.1"
[[example]]
name = "hello"
crate-type = ["cdylib"]
[dev-dependencies]
plugin-derive = { package = "veloren-plugin-derive", path = "../derive"}

View File

@ -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<Vec<String>, 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
}
}