Plugin API

From Mineserver Wiki

(Difference between revisions)
Jump to: navigation, search
m (Available callbacks)
Line 12: Line 12:
   #include "plugin_api.h"
   #include "plugin_api.h"
   #define PLUGIN_VERSION 1.0
   #define PLUGIN_VERSION 1.0
 +
  std::string dtos( double n )
 +
  {
 +
    std::ostringstream result;
 +
    result << n;
 +
    return result.str();
 +
  }
   mineserver_pointer_struct* mineserver;
   mineserver_pointer_struct* mineserver;
 +
  std::string pluginName = "command";
   PLUGIN_API_EXPORT void (plugin_name)_init(mineserver_pointer_struct* mineserver_temp)
   PLUGIN_API_EXPORT void (plugin_name)_init(mineserver_pointer_struct* mineserver_temp)
   {
   {
     mineserver = mineserver_temp;
     mineserver = mineserver_temp;
-
     if (mineserver->plugin.getPluginVersion("(plugin_name)") > 0)
+
     if (mineserver->plugin.getPluginVersion(pluginName.c_str(),pluginName.size()) > 0)
     {
     {
-
       mineserver->screen.log("(plugin_name) is already loaded v." +dtos(mineserver->plugin.getPluginVersion("(plugin_name)")));
+
       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;
       return;
     }
     }
-
     mineserver->screen.log("Loaded \"(plugin_name)\"!");
+
    std::string msg="Loaded "+pluginName+"!";
-
     mineserver->plugin.setPluginVersion("(plugin_name)", PLUGIN_VERSION);
+
     mineserver->screen.log(msg.c_str(),msg.size());
-
     mineserver->callback.add_hook("ChatPre", (void *)chatPreFunction);
+
     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)
   PLUGIN_API_EXPORT void (plugin_name)_shutdown(void)
   {
   {
-
     if (mineserver->plugin.getPluginVersion("(plugin_name)") <= 0)
+
     if (mineserver->plugin.getPluginVersion(pluginName.c_str(),pluginName.size()) <= 0)
     {
     {
-
       mineserver->screen.log("(plugin_name) is not loaded!");
+
      std::string msg="command is not loaded!";
 +
       mineserver->screen.log(msg.c_str(),msg.size());
       return;
       return;
     }
     }

Revision as of 23:05, 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 Parameters Return value
sendmsgTo (std::string user,std::string msg) bool, telling it the user was found
This function is used to send msg to single user
sendmsg (std::string message) bool, telling it the user was found
This function is used to send msg to single user

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.