Plugin API

From Mineserver Wiki

(Difference between revisions)
Jump to: navigation, search
(Chat: new table formatting)
(new format..)
Line 92: Line 92:
! class="col3" | Parameter info
! class="col3" | Parameter info
|- class="row1"
|- class="row1"
-
| class="col0" rowspan="4" | '''sendmsg'''
+
| class="col0" rowspan="2" | '''sendmsg'''
| class="col1" | msg
| class="col1" | msg
| class="col2" | const char*
| class="col2" | const char*
Line 108: Line 108:
{| class="wikitable"
{| class="wikitable"
-
|-
+
|- class="row0"
-
! Function
+
! class="col0" | Function
-
! Parameters
+
! class="col1" | Parameter name
-
! Return value
+
! class="col2" | Parameter type
-
|-
+
! class="col3" | Parameter info
-
| '''log'''
+
|- class="row1"
-
| (std::string message)
+
| class="col0" rowspan="2" | '''log'''
-
| none
+
| class="col1" | msg
-
|-
+
| class="col2" | const char*
-
| colspan="3" | Prints message to server window
+
| class="col3" | Message in char array
 +
|- class="row2"
 +
| class="col1" | msgLen
 +
| class="col2" | size_t
 +
| class="col3" | length of the message
 +
|- class="row3"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | void
 +
|- class="row8"
 +
| class="col0" colspan="4" | Prints message to server window
|}
|}
-
 
====Map====
====Map====
 +
{| class="wikitable"
{| class="wikitable"
-
|-
+
|- class="row0"
-
! Function
+
! class="col0" | Function
-
! Parameters
+
! class="col1" | Parameter name
-
! Return value
+
! class="col2" | Parameter type
-
|-
+
! class="col3" | Parameter info
-
| '''createPickupSpawn'''
+
|- class="row1"
-
| (int x, int y, int z, int type, int count, int health, std::string user)
+
| class="col0" rowspan="7" | '''createPickupSpawn'''
-
| none
+
| class="col1" | x
-
|-
+
| class="col2" | int
-
| colspan="3" | 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.
+
| class="col3" | x-coordinate
-
|-
+
|- class="row2"
-
| '''setTime'''
+
| class="col1" | y
-
| (std::string timeValue)
+
| class="col2" | int
-
| bool
+
| class="col3" | y-coordinate
-
|-
+
|- class="row3"
-
| colspan="3" | Sets server time to timeValue, which can be a string of value 0-24000
+
| class="col1" | z
-
|-
+
| class="col2" | int
-
| '''getSpawn'''
+
| class="col3" | z-coordinate
-
| (int* x, int* y, int* z)
+
|- class="row4"
-
| void
+
| class="col1" | count
-
|-
+
| class="col2" | int
-
| colspan="3" | Gets server spawn position
+
| class="col3" | How many to spawn (1-64)
-
|-
+
|- class="row4"
-
| '''getBlock'''
+
| class="col1" | health
-
| (int x, int y, int z, unsigned char* type,unsigned char* meta)
+
| class="col2" | int
-
| bool
+
| class="col3" | item health (0 = full health, max value depends on the item)
-
|-
+
|- class="row5"
-
| colspan="3" | Get block type and metadata (absolute block coordinates)
+
| class="col1" | user
-
|-
+
| class="col2" | const char*
-
| '''setBlock'''
+
| class="col3" | Username
-
| (int x, int y, int z, unsigned char type,unsigned char meta)
+
|- class="row6"
-
| bool
+
| class="col1" | userLen
-
|-
+
| class="col2" | size_t
-
| colspan="3" | Set block type and metadata (absolute block coordinates)
+
| class="col3" | Length of username
 +
|- class="row7"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | void
 +
|- class="row8"
 +
| class="col0" colspan="4" | 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.
 +
|}
 +
 
 +
 
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Function
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="1" | '''setTime'''
 +
| class="col1" | timeValue
 +
| class="col2" | int
 +
| class="col3" | value 0-24000
 +
|- class="row2"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool
 +
|- class="row3"
 +
| class="col0" colspan="4" | Sets server time to timeValue, which can be in range 0-24000
 +
|}
 +
 
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Function
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="3" | '''getSpawn'''
 +
| class="col1" | x
 +
| class="col2" | int*
 +
| class="col3" | x-coordinate
 +
|- class="row2"
 +
| class="col1" | y
 +
| class="col2" | int*
 +
| class="col3" | y-coordinate
 +
|- class="row3"
 +
| class="col1" | z
 +
| class="col2" | int*
 +
| class="col3" | z-coordinate
 +
|- class="row4"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | void
 +
|- class="row5"
 +
| class="col0" colspan="4" | Gets server spawn position
 +
|}
 +
 
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Function
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="5" | '''getBlock'''
 +
| class="col1" | x
 +
| class="col2" | int
 +
| class="col3" | x-coordinate
 +
|- class="row2"
 +
| class="col1" | y
 +
| class="col2" | int
 +
| class="col3" | y-coordinate
 +
|- class="row3"
 +
| class="col1" | z
 +
| class="col2" | int
 +
| class="col3" | z-coordinate
 +
|- class="row4"
 +
| class="col1" | type
 +
| class="col2" | unsigned char*
 +
| class="col3" | block type
 +
|- class="row5"
 +
| class="col1" | meta
 +
| class="col2" | unsigned char*
 +
| class="col3" | block metadata
 +
|- class="row6"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool
 +
|- class="row7"
 +
| class="col0" colspan="4" | Get block type and metadata (absolute block coordinates)
 +
|}
 +
 
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Function
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="5" | '''setBlock'''
 +
| class="col1" | x
 +
| class="col2" | int
 +
| class="col3" | x-coordinate
 +
|- class="row2"
 +
| class="col1" | y
 +
| class="col2" | int
 +
| class="col3" | y-coordinate
 +
|- class="row3"
 +
| class="col1" | z
 +
| class="col2" | int
 +
| class="col3" | z-coordinate
 +
|- class="row4"
 +
| class="col1" | type
 +
| class="col2" | unsigned char
 +
| class="col3" | block type
 +
|- class="row5"
 +
| class="col1" | meta
 +
| class="col2" | unsigned char
 +
| class="col3" | block metadata
 +
|- class="row6"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool
 +
|- class="row7"
 +
| class="col0" colspan="4" | Set block type and metadata (absolute block coordinates)
|}
|}

Revision as of 23:57, 6 January 2011

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(),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 Parameter name Parameter type Parameter info
log msg const char* Message in char array
msgLen size_t length of the message
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
userLen size_t Length of 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 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.