Plugin API
From Mineserver Wiki
Jump to navigationJump to searchMineserver uses a C-plugin API which is described in this page.
Creating a plugin
You will need to include plugin_api.h
to your project.
...write some more stuff here...
Example plugin structure:
#include "plugin_api.h"
#define PLUGIN_VERSION 1.0
std::string dtos( double n )
{
std::ostringstream result;
result << n;
return result.str();
}
mineserver_pointer_struct* mineserver;
std::string pluginName = "command";
PLUGIN_API_EXPORT void (plugin_name)_init(mineserver_pointer_struct* mineserver_temp)
{
mineserver = mineserver_temp;
if (mineserver->plugin.getPluginVersion(pluginName.c_str(),pluginName.size()) > 0)
{
std::string msg="command is already loaded v." +dtos(mineserver->plugin.getPluginVersion(pluginName.c_str(),pluginName.size()));
mineserver->screen.log(msg.c_str(),msg.size());
return;
}
std::string msg="Loaded "+pluginName+"!";
mineserver->screen.log(msg.c_str(),msg.size());
mineserver->plugin.setPluginVersion(pluginName.c_str(),pluginName.size(), PLUGIN_COMMAND_VERSION);
std::string hookName="ChatPre";
mineserver->callback.add_hook(hookName.c_str(),hookName.size(), (void *)SOMEFUNCTIONNAME);
hookName = "BlockPlacePre";
mineserver->callback.add_hook(hookName.c_str(),hookName.size(), (void *)SOMEFUNCTIONNAME2);
}
PLUGIN_API_EXPORT void (plugin_name)_shutdown(void)
{
if (mineserver->plugin.getPluginVersion(pluginName.c_str(),pluginName.size()) <= 0)
{
std::string msg="command is not loaded!";
mineserver->screen.log(msg.c_str(),msg.size());
return;
}
}
Available functions
Mineserver
Chat
Function | Parameter name | Parameter type | Parameter info |
---|---|---|---|
sendmsgTo | user | const char* | Username in char array |
userLen | size_t | Length of username | |
msg | const char* | Message in char array | |
msgLen | size_t | length of the message | |
Return value | bool, telling it the user was found |
Function | Parameter name | Parameter type | Parameter info |
---|---|---|---|
sendmsg | msg | const char* | Message in char array |
msgLen | size_t | length of the message | |
Return value | bool, telling it the user was found |
Screen
Function | Parameters | Return value |
---|---|---|
log | (std::string message) | none |
Prints message to server window |
Map
Function | Parameters | Return value |
---|---|---|
createPickupSpawn | (int x, int y, int z, int type, int count, int health, std::string user) | none |
Spawns an item at (x,y,z) with type,count and health specified. If "user" is set, he will not be able to pick up the item right away to make it possible to throw stuff away. | ||
setTime | (std::string timeValue) | bool |
Sets server time to timeValue, which can be a string of value 0-24000 | ||
getSpawn | (int* x, int* y, int* z) | void |
Gets server spawn position | ||
getBlock | (int x, int y, int z, unsigned char* type,unsigned char* meta) | bool |
Get block type and metadata (absolute block coordinates) | ||
setBlock | (int x, int y, int z, unsigned char type,unsigned char meta) | bool |
Set block type and metadata (absolute block coordinates) |
Available callbacks
Name | Parameters | Return value |
---|---|---|
ChatPre | const std::string& nick, std::string msg | bool |
called on chat message prosessing, returning false will terminate the callback. | ||
BlockPlacePre | const std::string& nick, int x,char y,int z,char block | bool |
called on block placement, returning false will prevent block placement and terminate callback. | ||
BlockBreakPre | (int* x, int* y, int* z) | bool |
called on block break, returning false will prevent block breaking and terminate callback. |