Plugin API

From Mineserver Wiki

Revision as of 01:26, 7 January 2011 by Fador (Talk | contribs)
Jump to: navigation, search

Mineserver uses a C-plugin API which is described in this page.

Contents

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()) > 0)
   {
     std::string msg="command is already loaded v." +dtos(mineserver->plugin.getPluginVersion(pluginName.c_str()));
     mineserver->screen.log(msg.c_str(),msg.size());
     return;
   }
   std::string msg="Loaded "+pluginName+"!";
   mineserver->screen.log(msg.c_str());
   mineserver->plugin.setPluginVersion(pluginName.c_str(), PLUGIN_COMMAND_VERSION);
   mineserver->callback.add_hook("ChatPre", (void *)SOMEFUNCTIONNAME);
   mineserver->callback.add_hook("BlockPlacePre", (void *)SOMEFUNCTIONNAME2);
 }
 PLUGIN_API_EXPORT void (plugin_name)_shutdown(void)
 {
   if (mineserver->plugin.getPluginVersion(pluginName.c_str()) <= 0)
   {
     mineserver->screen.log("command is not loaded!"));
     return;
   }
 }

Available functions

Mineserver

Chat

Function Parameter name Parameter type Parameter info
sendmsgTo user const char* Username in null terminated char array
msg const char* Message in null terminated char array
Return value bool, telling it the user was found
Function Parameter name Parameter type Parameter info
sendmsg msg const char* Message in null terminated char array
Return value bool, telling it the user was found

Screen

Function Parameter name Parameter type Parameter info
log msg const char* Message in null terminated char array
Return value void
Prints message to server window

Map

Function Parameter name Parameter type Parameter info
createPickupSpawn x int x-coordinate
y int y-coordinate
z int z-coordinate
count int How many to spawn (1-64)
health int item health (0 = full health, max value depends on the item)
user const char* Username
Return value void
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.


Function Parameter name Parameter type Parameter info
setTime timeValue int value 0-24000
Return value bool
Sets server time to timeValue, which can be in range 0-24000
Function Parameter name Parameter type Parameter info
getSpawn x int* x-coordinate
y int* y-coordinate
z int* z-coordinate
Return value void
Gets server spawn position
Function Parameter name Parameter type Parameter info
getBlock x int x-coordinate
y int y-coordinate
z int z-coordinate
type unsigned char* block type
meta unsigned char* block metadata
Return value bool
Get block type and metadata (absolute block coordinates)
Function Parameter name Parameter type Parameter info
setBlock x int x-coordinate
y int y-coordinate
z int z-coordinate
type unsigned char block type
meta unsigned char block metadata
Return value bool
Set block type and metadata (absolute block coordinates)

Available callbacks

Name Parameter name Parameter type Parameter info
ChatPre user const char* Username in null terminated char array
msg const char* Message in null terminated char array
Return value bool
called on chat message prosessing, returning false will terminate the callback.
Name Parameter name Parameter type Parameter info
BlockPlacePre user const char* Username in char array
x int x-coord
y int y-coord
z int z-coord
block char block type
Return value bool
called on block placement, returning false will prevent block placement and terminate callback.
Name Parameter name Parameter type Parameter info
BlockBreakPre user const char* Username in char array
x int x-coord
y int y-coord
z int z-coord
Return value bool
called on block break, returning false will prevent block breaking and terminate callback.