Plugin API

From Mineserver Wiki

(Difference between revisions)
Jump to: navigation, search
(new format..)
(Creating a plugin)
 
(13 intermediate revisions not shown)
Line 9: Line 9:
Example plugin structure:
Example plugin structure:
-
<code>
+
<pre><nowiki>
-
  #include "plugin_api.h"
+
#include <stdio.h>
-
  #define PLUGIN_VERSION 1.0
+
#include <stdlib.h>
-
   std::string dtos( double n )
+
#include <time.h>
 +
#include <string.h>
 +
#include <cstdlib>
 +
#include <iostream>
 +
 
 +
#define MINESERVER_C_API
 +
#include "../src/plugin_api.h"
 +
#include "../src/logtype.h"
 +
 
 +
#define PLUGIN_VERSION 1.0
 +
double pluginVersion = PLUGIN_VERSION;
 +
 
 +
#define PLUGIN_NAME "pressurplate"
 +
const char* pluginName = PLUGIN_NAME;
 +
 
 +
const char* logSource = "plugin.screen";
 +
mineserver_pointer_struct* mineserver;
 +
 
 +
PLUGIN_API_EXPORT void CALLCONVERSION pressurplate_init(mineserver_pointer_struct* mineserver_temp)
 +
{
 +
   mineserver = mineserver_temp;
 +
 
 +
  if (mineserver->plugin.getPluginVersion(pluginName) > 0)
   {
   {
-
     std::ostringstream result;
+
     mineserver->logger.log(LogType::LOG_INFO, logSource, "The " PLUGIN_NAME " plugin is already loaded");
-
    result << n;
+
     return;
-
     return result.str();
+
   }
   }
-
  mineserver_pointer_struct* mineserver;
+
 
-
   std::string pluginName = "command";
+
   mineserver->logger.log(LogType::LOG_INFO, logSource, "Loaded " PLUGIN_NAME);
-
   PLUGIN_API_EXPORT void (plugin_name)_init(mineserver_pointer_struct* mineserver_temp)
+
   mineserver->plugin.setPluginVersion(pluginName, pluginVersion);
 +
 
 +
}
 +
 
 +
 
 +
PLUGIN_API_EXPORT void CALLCONVERSION pressurplate_shutdown(void)
 +
{
 +
  if (mineserver->plugin.getPluginVersion(pluginName) <= 0)
   {
   {
-
     mineserver = mineserver_temp;
+
     mineserver->logger.log(LogType::LOG_INFO, logSource, PLUGIN_NAME " is not loaded!");
-
    if (mineserver->plugin.getPluginVersion(pluginName.c_str(),pluginName.size()) > 0)
+
     return;
-
    {
+
-
      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)
+
   mineserver->logger.log(LogType::LOG_INFO, logSource, PLUGIN_NAME " has been unloaded!");
-
  {
+
}
-
    if (mineserver->plugin.getPluginVersion(pluginName.c_str(),pluginName.size()) <= 0)
+
 
-
    {
+
</nowiki>
-
      std::string msg="command is not loaded!";
+
</pre>
-
      mineserver->screen.log(msg.c_str(),msg.size());
+
-
      return;
+
-
    }
+
-
  }
+
-
</code>
+
==Available functions==
==Available functions==
-
 
-
 
===Mineserver===
===Mineserver===
Line 56: Line 65:
====Chat====
====Chat====
 +
{{APIFunct2|sendmsgTo|user|const char*|Username in null Terminated char array|msg|const char*|Message in null terminated char array|bool, telling it the user was found|Sends a message to specified ''user''}}
-
{| class="wikitable"
+
{{APIFunct1|sendmsg|msg|const char*|Message in null terminated char array|bool, telling it the user was found|Sends a message to all players, except they are in DND mode}}
-
|- class="row0"
+
-
! class="col0" | Function
+
-
! class="col1" | Parameter name
+
-
! class="col2" | Parameter type
+
-
! class="col3" | Parameter info
+
-
|- class="row1"
+
-
| class="col0" rowspan="4" | '''sendmsgTo'''
+
-
| class="col1" | user
+
-
| class="col2" | const char*
+
-
| class="col3" | Username in char array
+
-
|- class="row2"
+
-
| class="col1" | userLen
+
-
| class="col2" | size_t
+
-
| class="col3" | Length of username
+
-
|- class="row4"
+
-
| class="col1" | msg
+
-
| class="col2" | const char*
+
-
| class="col3" | Message in char array
+
-
|- class="row5"
+
-
| class="col1" | msgLen
+
-
| class="col2" | size_t
+
-
| class="col3" | length of the message
+
-
|- class="row6"
+
-
! class="col0" | Return value
+
-
| class="col1 rightalign" colspan="3" | bool, telling it the user was found
+
-
|}
+
-
{| class="wikitable"
+
{{APIFunct1|sendUserList|user|const char*|User in null terminated char array|bool, telling it the user was found|Sends the playerlist to ''user''}}
-
|- class="row0"
+
-
! class="col0" | Function
+
-
! class="col1" | Parameter name
+
-
! class="col2" | Parameter type
+
-
! class="col3" | Parameter info
+
-
|- class="row1"
+
-
| class="col0" rowspan="2" | '''sendmsg'''
+
-
| class="col1" | msg
+
-
| class="col2" | const char*
+
-
| 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" | bool, telling it the user was found
+
-
|}
+
====Screen====
====Screen====
 +
 +
{{APIFunctVoid|log|msg|const char*|Message in null terminated char array|Prints message to server window}}
 +
 +
====Map====
 +
 +
{{APIFunct6|createPickupSpawn|x|int|x-coordinate|y|int|y-coordinate|z|int|z-coordinate|conut|int|How many to spawn(1-64)|health|int|item health. 0 is max health, max value depends on the item|user|const char*|Username|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.}}
 +
 +
{{APIFunct1|setTime|timeValue|int|value between 0 and 2400|bool|Sets server time to ''timeValue''}}
{| class="wikitable"
{| class="wikitable"
Line 114: Line 88:
! class="col3" | Parameter info
! class="col3" | Parameter info
|- class="row1"
|- class="row1"
-
| class="col0" rowspan="2" | '''log'''
+
| class="col0" rowspan="3" | '''getSpawn'''
-
| class="col1" | msg
+
| class="col1" | x
-
| class="col2" | const char*
+
| class="col2" | int*
-
| class="col3" | Message in char array
+
| class="col3" | x-coordinate
|- class="row2"
|- class="row2"
-
| class="col1" | msgLen
+
| class="col1" | y
-
| class="col2" | size_t
+
| class="col2" | int*
-
| class="col3" | length of the message
+
| class="col3" | y-coordinate
|- class="row3"
|- class="row3"
 +
| class="col1" | z
 +
| class="col2" | int*
 +
| class="col3" | z-coordinate
 +
|- class="row4"
! class="col0" | Return value
! class="col0" | Return value
| class="col1 rightalign" colspan="3" | void
| class="col1 rightalign" colspan="3" | void
-
|- class="row8"
+
|- class="row5"
-
| class="col0" colspan="4" | Prints message to server window
+
| class="col0" colspan="4" | Gets server spawn position
|}
|}
-
 
-
====Map====
 
-
 
{| class="wikitable"
{| class="wikitable"
Line 139: Line 114:
! class="col3" | Parameter info
! class="col3" | Parameter info
|- class="row1"
|- class="row1"
-
| class="col0" rowspan="7" | '''createPickupSpawn'''
+
| class="col0" rowspan="5" | '''getBlock'''
| class="col1" | x
| class="col1" | x
| class="col2" | int
| class="col2" | int
Line 152: Line 127:
| class="col3" | z-coordinate
| class="col3" | z-coordinate
|- class="row4"
|- class="row4"
-
| class="col1" | count
+
| class="col1" | type
-
| class="col2" | int
+
| class="col2" | unsigned char*
-
| class="col3" | How many to spawn (1-64)
+
| class="col3" | block type
-
|- class="row4"
+
-
| class="col1" | health
+
-
| class="col2" | int
+
-
| class="col3" | item health (0 = full health, max value depends on the item)
+
|- class="row5"
|- class="row5"
-
| class="col1" | user
+
| class="col1" | meta
-
| class="col2" | const char*
+
| class="col2" | unsigned char*
-
| class="col3" | Username
+
| class="col3" | block metadata
|- class="row6"
|- class="row6"
-
| class="col1" | userLen
+
! class="col0" | Return value
-
| class="col2" | size_t
+
| class="col1 rightalign" colspan="3" | bool
-
| class="col3" | Length of username
+
|- class="row7"
|- class="row7"
-
! class="col0" | Return value
+
| class="col0" colspan="4" | Get block type and metadata (absolute block coordinates) in first world (id 0)
-
| 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="wikitable"
Line 182: Line 148:
! class="col3" | Parameter info
! class="col3" | Parameter info
|- class="row1"
|- class="row1"
-
| class="col0" rowspan="1" | '''setTime'''
+
| class="col0" rowspan="6" | '''getBlockW'''
-
| class="col1" | timeValue
+
| class="col1" | x
| class="col2" | int
| class="col2" | int
-
| class="col3" | value 0-24000
+
| class="col3" | x-coordinate
|- class="row2"
|- 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" | w
 +
| class="col2" | int
 +
| class="col3" | World ID
 +
|- class="row5"
 +
| class="col1" | type
 +
| class="col2" | unsigned char*
 +
| class="col3" | block type
 +
|- class="row6"
 +
| class="col1" | meta
 +
| class="col2" | unsigned char*
 +
| class="col3" | block metadata
 +
|- class="row7"
! class="col0" | Return value
! class="col0" | Return value
| class="col1 rightalign" colspan="3" | bool
| class="col1 rightalign" colspan="3" | bool
-
|- class="row3"
+
|- class="row8"
-
| class="col0" colspan="4" | Sets server time to timeValue, which can be in range 0-24000
+
| class="col0" colspan="4" | Gets block type and metadata (absolute block coordinates)
|}
|}
Line 200: Line 186:
! class="col3" | Parameter info
! class="col3" | Parameter info
|- class="row1"
|- class="row1"
-
| class="col0" rowspan="3" | '''getSpawn'''
+
| class="col0" rowspan="5" | '''setBlock'''
| class="col1" | x
| class="col1" | x
-
| class="col2" | int*
+
| class="col2" | int
| class="col3" | x-coordinate
| class="col3" | x-coordinate
|- class="row2"
|- class="row2"
| class="col1" | y
| class="col1" | y
-
| class="col2" | int*
+
| class="col2" | int
| class="col3" | y-coordinate
| class="col3" | y-coordinate
|- class="row3"
|- class="row3"
| class="col1" | z
| class="col1" | z
-
| class="col2" | int*
+
| class="col2" | int
| class="col3" | z-coordinate
| class="col3" | z-coordinate
|- class="row4"
|- class="row4"
-
! class="col0" | Return value
+
| class="col1" | type
-
| class="col1 rightalign" colspan="3" | void
+
| class="col2" | unsigned char
 +
| class="col3" | block type
|- class="row5"
|- class="row5"
-
| class="col0" colspan="4" | Gets server spawn position
+
| 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)
|}
|}
Line 226: Line 220:
! class="col3" | Parameter info
! class="col3" | Parameter info
|- class="row1"
|- class="row1"
-
| class="col0" rowspan="5" | '''getBlock'''
+
| class="col0" rowspan="6" | '''setBlockW'''
| class="col1" | x
| class="col1" | x
| class="col2" | int
| class="col2" | int
Line 239: Line 233:
| class="col3" | z-coordinate
| class="col3" | z-coordinate
|- class="row4"
|- class="row4"
 +
| class="col1" | w
 +
| class="col2" | int
 +
| class="col3" | World ID
 +
|- class="row5"
| class="col1" | type
| class="col1" | type
| class="col2" | unsigned char*
| class="col2" | unsigned char*
| class="col3" | block type
| class="col3" | block type
-
|- class="row5"
+
|- class="row6"
| class="col1" | meta
| class="col1" | meta
| class="col2" | unsigned char*
| class="col2" | unsigned char*
| class="col3" | block metadata
| class="col3" | block metadata
-
|- class="row6"
+
|- class="row7"
! class="col0" | Return value
! class="col0" | Return value
| class="col1 rightalign" colspan="3" | bool
| class="col1 rightalign" colspan="3" | bool
-
|- class="row7"
+
|- class="row8"
-
| class="col0" colspan="4" | Get block type and metadata (absolute block coordinates)
+
| class="col0" colspan="4" | Sets block type and metadata (absolute block coordinates)
|}
|}
Line 260: Line 258:
! class="col3" | Parameter info
! class="col3" | Parameter info
|- class="row1"
|- class="row1"
-
| class="col0" rowspan="5" | '''setBlock'''
+
| class="col0" rowspan="5" | '''setSpawn'''
| class="col1" | x
| class="col1" | x
| class="col2" | int
| class="col2" | int
Line 273: Line 271:
| class="col3" | z-coordinate
| class="col3" | z-coordinate
|- class="row4"
|- 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="col0" | Return value
| class="col1 rightalign" colspan="3" | bool
| class="col1 rightalign" colspan="3" | bool
-
|- class="row7"
+
|- class="row5"
-
| class="col0" colspan="4" | Set block type and metadata (absolute block coordinates)
+
| class="col0" colspan="4" | Set spawn to x, y, z (absolute coordinates)
|}
|}
 +
 +
{{APIFunctVoid|saveWholeMap| |void| |Saves the whole map to disk}}
 +
 +
{{APIFunct2|getMapData_block|x|int|x-coordinate|z|int|z-coordinate|unsigned char*| }}
 +
 +
{{APIFunct2|getMapData_meta|x|int|x-coordinate|z|int|z-coordinate|unsigned char*| }}
 +
 +
{{APIFunct2|getMapData_skylight|x|int|x-coordinate|z|int|z-coordinate|unsigned char*| }}
 +
 +
{{APIFunct2|getMapData_blocklight|x|int|x-coordinate|z|int|z-coordinate|unsigned char*| }}
 +
 +
====User Functions====
 +
 +
{{APIFunct1|toggleDND|user|const char*|Username in null terminated char array|bool, indicates if user was found|Toggles the DND (Do not Disturb)-Mode of a ''user''}}
 +
 +
{{APIFunct7|getPosition|user|const char*|Username in null terminated char array|x|double*|x-coordinate|y|double*|y-coordinate|z|double*|z-coordinate|yaw|float*|yaw-Value|pitch|float*|pitch-Value|*stance|double|stance-Value|bool, true if user has been found|Finds a player and stores its info in the referenced variables}}
 +
 +
{{APIFunct8|getPosition|user|const char*|Username in null terminated char array|x|double*|x-coordinate|y|double*|y-coordinate|z|double*|z-coordinate|w|int*|World ID|yaw|float*|yaw-Value|pitch|float*|pitch-Value| *stance|double|stance-Value|bool, true if user has been found|Finds a player and stores its info in the referenced variables}}
 +
 +
{{APIFunct4|teleport|user|const char*|Username in null terminated char array|x|double*|x-coordinate|y|double*|y-coordinate|z|double*|z-coordinate|bool, true if user was found|Teleports a ''user'' to ''x'',''y'',''z''}}
 +
 +
{{APIFunct5|teleport|user|const char*|Username in null terminated char array|x|double*|x-coordinate|y|double*|y-coordinate|z|double*|z-coordinate|map|int|Map ID|bool, true if user was found|Teleports a ''user'' to ''x'',''y'',''z'' on ''map''}}
 +
 +
{{APIFunct2|setHealth|user|const char*|Username in null terminated char array|userHealth|int|Health of ''user''. Must not be greater than 20.|bool, true if user is not null|Sets the health of a ''user''.}}
 +
 +
{{APIFunct1|getHealth|user|const char*|Username in null terminated char array|int, player's health|Gets the health of a ''user''}}
 +
 +
{{APIFunct1|no paramters| | |int, number of players online|Gets the number of players online}}
 +
 +
{{APIFunct4|getItemInHand|user|const char*|Username in null terminated char array|*type|int|Type of item|*meta|int|Health of item|*quant|int|quantity of item|bool, true if user was found|Gets the item in the hand of ''user''}}
 +
 +
{{APIFunct4|setItemInHand|user|const char*|Username in null terminated char array|type|int|Type of item|meta|int|Health of item|quant|int|quantity of item, must not be greater than 64|bool, true if user was found|Sets the item in the hand of ''user''}}
 +
 +
{{APIFunct4|addItem|user|const char*|Username in null terminated char array|type|int|Type of item|meta|int|Health of item|quant|int|quantity of item, must not be greater than 64|bool, true if user was found|Adds the ''item'' to the ''user'''s inventory}}
 +
 +
{{APIFunct4|hasItem|user|const char*|Username in null terminated char array|type|int|Type of item|meta|int|Health of item|quant|int|quantity of item, must not be greater than 64|bool, true if the item is in Users inventory. Chests are unchecked.|Checks if ''item'' is in ''user'''s inventory}}
 +
 +
{{APIFunct4|delItem|user|const char*|Username in null terminated char array|type|int|Type of item|meta|int|Health of item|quant|int|quantity of item, must not be greater than 64|bool, true if user was found|Delets the ''item'' ''quantity'' times from the ''user'''s inventory. Chests are untouched.}}
 +
 +
{{APIFunct1|kick|user|const char*|Username in null terminated char array|bool, true if user is found|Kicks ''user'' with standard reason "You have been kicked"}}
 +
 +
====Config wrapper functions====
 +
{{APIFunct1|has|name|const char*|name of the config string|bool, true if config string was found|Checks if the config string ''name'' exists in the configuration file}}
 +
 +
{{APIFunct1|iData|name|const char*|name of the config string|int|Gets integer data from configuration string ''name''}}
 +
 +
{{APIFunct1|lData|name|const char*|name of the config string|int64_t|Gets long (int64_t) data from configuration string ''name''}}
 +
 +
{{APIFunct1|fData|name|const char*|name of the config string|float|Gets float data from configuration string ''name''}}
 +
 +
{{APIFunct1|dData|name|const char*|name of the config string|double|Gets double data from configuration string ''name''}}
 +
 +
{{APIFunct1|sData|name|const char*|name of the config string|const char*|Gets string (char*) data from configuration string ''name''}}
 +
 +
{{APIFunct1|bData|name|const char*|name of the config string|bool|Gets bool data from configuration string ''name''}}
 +
 +
====Mobs====
 +
 +
====Permissions====
 +
 +
{{APIFunct1|setAdmin|name|const char*|Username in null terminated char array|bool, true if user was found|Makes ''user'' to a server administrator, providing him with full permissions.}}
 +
 +
{{APIFunct1|setOp|name|const char*|Username in null terminated char array|bool, true if user was found|Makes ''user'' to a server Operator}}
 +
 +
{{APIFunct1|setMember|name|const char*|Username in null terminated char array|bool, true if user was found|Makes ''user'' to a regular member}}
 +
 +
{{APIFunct1|setGuest|name|const char*|Username in null terminated char array|bool, true if user was found|Makes ''user'' to a guest}}
 +
 +
{{APIFunct1|isAdmin|name|const char*|Username in null terminated char array|bool, true if user is admin|Checks, if ''user'' is a server administrator}}
 +
 +
{{APIFunct1|isOp|name|const char*|Username in null terminated char array|bool, true if user is operator|Checks, if ''user'' is a server Operator}}
 +
 +
{{APIFunct1|isMember|name|const char*|Username in null terminated char array|bool, true if user is member|Checks, if ''user'' is a regular member}}
 +
 +
{{APIFunct1|Guest|name|const char*|Username in null terminated char array|bool, true if user is guest|Checks, if ''user'' is a guest}}
==Available callbacks==
==Available callbacks==
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Name
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="1" | '''Timer200'''
 +
| class="col1" | no params
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row2"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool, isn't used
 +
|- class="row3"
 +
| class="col0" colspan="4" | 200ms timer callback
 +
|}
{| class="wikitable"
{| class="wikitable"
-
|-
+
|- class="row0"
-
! Name
+
! class="col0" | Name
-
! Parameters
+
! class="col1" | Parameter name
-
! Return value
+
! class="col2" | Parameter type
-
|-
+
! class="col3" | Parameter info
-
| '''ChatPre'''
+
|- class="row1"
-
| const std::string& nick, std::string msg
+
| class="col0" rowspan="1" | '''Timer1000'''
-
| bool
+
| class="col1" | no params
-
|-
+
| class="col2" |
-
| colspan="3" | called on chat message prosessing, returning false will terminate the callback.
+
| class="col3" |  
-
|-
+
|- class="row2"
-
| '''BlockPlacePre'''
+
! class="col0" | Return value
-
| const std::string& nick, int x,char y,int z,char block
+
| class="col1 rightalign" colspan="3" | bool, isn't used
-
| bool
+
|- class="row3"
-
|-
+
| class="col0" colspan="4" | 1000ms (1s) timer callback
-
| colspan="3" | called on block placement, returning false will prevent block placement and terminate callback.
+
-
|-
+
-
| '''BlockBreakPre'''
+
-
| (int* x, int* y, int* z)
+
-
| bool
+
-
|-
+
-
| colspan="3" | called on block break, returning false will prevent block breaking and terminate callback.
+
|}
|}
 +
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Name
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="1" | '''Timer10000'''
 +
| class="col1" | no params
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row2"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool, isn't used
 +
|- class="row3"
 +
| class="col0" colspan="4" | 10s timer callback
 +
|}
 +
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Name
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="3" | '''PlayerChatPre'''
 +
| class="col1" | user
 +
| class="col2" | const char*
 +
| class="col3" | Username in null terminated char array
 +
|- class="row2"
 +
| class="col1" | timestamp
 +
| class="col2" | size_t
 +
| class="col3" | time of the message
 +
|- class="row2"
 +
| class="col1" | msg
 +
| class="col2" | const char*
 +
| class="col3" | Message in null terminated char array
 +
|- class="row3"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool
 +
|- class="row4"
 +
| class="col0" colspan="4" | called on chat message processing, returning false will terminate the callback.
 +
|}
 +
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Name
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="4" | '''PlayerChatCommand'''
 +
| class="col1" | user
 +
| class="col2" | const char*
 +
| class="col3" | Username in null terminated char array
 +
|- class="row2"
 +
| class="col1" | command
 +
| class="col2" | const char*
 +
| class="col3" | command
 +
|- class="row2"
 +
| class="col1" | argc
 +
| class="col2" | int
 +
| class="col3" | argument count
 +
|- class="row3"
 +
| class="col1" | arguments
 +
| class="col2" | const char**
 +
| class="col3" | list of arguments
 +
|- class="row4"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool
 +
|- class="row5"
 +
| class="col0" colspan="4" | called when chat command is used
 +
|}
 +
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Name
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="6" | '''BlockPlacePre'''
 +
| class="col1" | user
 +
| class="col2" | const char*
 +
| class="col3" | Username in char array
 +
|- class="row2"
 +
| class="col1" | x
 +
| class="col2" | int32_t
 +
| class="col3" | x-coord
 +
|- class="row3"
 +
| class="col1" | y
 +
| class="col2" | int8_t
 +
| class="col3" | y-coord
 +
|- class="row4"
 +
| class="col1" | z
 +
| class="col2" | int32_t
 +
| class="col3" | z-coord
 +
|- class="row5"
 +
| class="col1" | block
 +
| class="col2" | int16_t
 +
| class="col3" | block type
 +
|- class="row6"
 +
| class="col1" | direction
 +
| class="col2" | int8_t
 +
| class="col3" | placement direction
 +
|- class="row7"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool
 +
|- class="row8"
 +
| class="col0" colspan="4" | called on block placement, returning false will prevent block placement and terminate callback.
 +
|}
 +
 +
{| class="wikitable"
 +
|- class="row0"
 +
! class="col0" | Name
 +
! class="col1" | Parameter name
 +
! class="col2" | Parameter type
 +
! class="col3" | Parameter info
 +
|- class="row1"
 +
| class="col0" rowspan="4" | '''BlockBreakPre'''
 +
| class="col1" | user
 +
| class="col2" | const char*
 +
| class="col3" | Username in char array
 +
|- class="row2"
 +
| class="col1" | x
 +
| class="col2" | int
 +
| class="col3" | x-coord
 +
|- class="row3"
 +
| class="col1" | y
 +
| class="col2" | int
 +
| class="col3" | y-coord
 +
|- class="row4"
 +
| class="col1" | z
 +
| class="col2" | int
 +
| class="col3" | z-coord
 +
|- class="row5"
 +
! class="col0" | Return value
 +
| class="col1 rightalign" colspan="3" | bool
 +
|- class="row6"
 +
| class="col0" colspan="4" | called on block break, returning false will prevent block breaking and terminate callback.
 +
|}
 +
 +
 +
ToDo:
 +
 +
    setHook("PlayerLoginPre", new Hook2<bool,const char*,char***>);
 +
    setHook("PlayerLoginPost", new Hook1<bool,const char*>);
 +
    setHook("PlayerNickPost", new Hook2<bool,const char*,const char*>);
 +
    setHook("PlayerKickPost", new Hook2<bool,const char*,const char*>);
 +
    setHook("PlayerQuitPost", new Hook1<bool,const char*>);
 +
    setHook("PlayerChatPost", new Hook3<bool,const char*,time_t,const char*>);
 +
    setHook("PlayerArmSwing", new Hook1<bool,const char*>);
 +
    setHook("PlayerDamagePre", new Hook3<bool,const char*,const char*,int>);
 +
    setHook("PlayerDamagePost", new Hook3<bool,const char*,const char*,int>);
 +
    setHook("PlayerDisconnect", new Hook3<bool,const char*,uint32,uint16>);
 +
    setHook("PlayerDiggingStarted", new Hook4<bool,const char*,sint32,sint8,sint32>);
 +
    setHook("PlayerDigging", new Hook4<bool,const char*,sint32,sint8,sint32>);
 +
    setHook("PlayerDiggingStopped", new Hook4<bool,const char*,sint32,sint8,sint32>);
 +
    setHook("BlockBreakPre", new Hook4<bool,const char*,sint32,sint8,sint32>);
 +
    setHook("BlockBreakPost", new Hook4<bool,const char*,sint32,sint8,sint32>);
 +
    setHook("BlockNeighbourBreak", new Hook7<bool,const char*,sint32,sint8,sint32,sint32,sint8,sint32>);
 +
    setHook("BlockPlacePre", new Hook5<bool,const char*,sint32,sint8,sint32,sint16>);
 +
    setHook("BlockPlacePost", new Hook5<bool,const char*,sint32,sint8,sint32,sint16>);
 +
    setHook("BlockNeighbourPlace", new Hook7<bool,const char*,sint32,sint8,sint32,sint32,sint8,sint32>);
 +
    setHook("BlockReplacePost", new Hook6<bool,const char*,sint32,sint8,sint32,sint16,sint16>);
 +
    setHook("BlockNeighbourReplace", new Hook9<bool,const char*,sint32,sint8,sint32,sint32,sint8,sint32,sint16,sint16>);

Latest revision as of 21:06, 27 February 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 <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <cstdlib>
#include <iostream>

#define MINESERVER_C_API
#include "../src/plugin_api.h"
#include "../src/logtype.h"

#define PLUGIN_VERSION 1.0
double pluginVersion = PLUGIN_VERSION;

#define PLUGIN_NAME "pressurplate"
const char* pluginName = PLUGIN_NAME;

const char* logSource = "plugin.screen";
mineserver_pointer_struct* mineserver;

 PLUGIN_API_EXPORT void CALLCONVERSION pressurplate_init(mineserver_pointer_struct* mineserver_temp)
{
  mineserver = mineserver_temp;

  if (mineserver->plugin.getPluginVersion(pluginName) > 0)
  {
    mineserver->logger.log(LogType::LOG_INFO, logSource, "The " PLUGIN_NAME " plugin is already loaded");
    return;
  }

  mineserver->logger.log(LogType::LOG_INFO, logSource, "Loaded " PLUGIN_NAME);
  mineserver->plugin.setPluginVersion(pluginName, pluginVersion);

}


PLUGIN_API_EXPORT void CALLCONVERSION pressurplate_shutdown(void)
{
  if (mineserver->plugin.getPluginVersion(pluginName) <= 0)
  {
    mineserver->logger.log(LogType::LOG_INFO, logSource, PLUGIN_NAME " is not loaded!");
    return;
  }
  mineserver->logger.log(LogType::LOG_INFO, logSource, PLUGIN_NAME " has been unloaded!");
}


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
Sends a message to specified user


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
Sends a message to all players, except they are in DND mode


Function Parameter name Parameter type Parameter info
sendUserList user const char* User in null terminated char array
Return value bool, telling it the user was found
Sends the playerlist to user

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
conut int How many to spawn(1-64)
health int item health. 0 is max 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 between 0 and 2400
Return value bool
Sets server time to timeValue
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) in first world (id 0)
Function Parameter name Parameter type Parameter info
getBlockW x int x-coordinate
y int y-coordinate
z int z-coordinate
w int World ID
type unsigned char* block type
meta unsigned char* block metadata
Return value bool
Gets 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)
Function Parameter name Parameter type Parameter info
setBlockW x int x-coordinate
y int y-coordinate
z int z-coordinate
w int World ID
type unsigned char* block type
meta unsigned char* block metadata
Return value bool
Sets block type and metadata (absolute block coordinates)
Function Parameter name Parameter type Parameter info
setSpawn x int x-coordinate
y int y-coordinate
z int z-coordinate
Return value bool
Set spawn to x, y, z (absolute coordinates)


Function Parameter name Parameter type Parameter info
saveWholeMap void
Return value void
Saves the whole map to disk


Function Parameter name Parameter type Parameter info
getMapData_block x int x-coordinate
z int z-coordinate
Return value unsigned char*


Function Parameter name Parameter type Parameter info
getMapData_meta x int x-coordinate
z int z-coordinate
Return value unsigned char*


Function Parameter name Parameter type Parameter info
getMapData_skylight x int x-coordinate
z int z-coordinate
Return value unsigned char*


Function Parameter name Parameter type Parameter info
getMapData_blocklight x int x-coordinate
z int z-coordinate
Return value unsigned char*

User Functions

Function Parameter name Parameter type Parameter info
toggleDND user const char* Username in null terminated char array
Return value bool, indicates if user was found
Toggles the DND (Do not Disturb)-Mode of a user
Function Parameter name Parameter type Parameter info
getPosition user const char* Username in null terminated char array
x double* x-coordinate
y double* y-coordinate
z double* z-coordinate
yaw float* yaw-Value
pitch float* pitch-Value
*stance double stance-Value
Return value bool, true if user has been found
Finds a player and stores its info in the referenced variables
Function Parameter name Parameter type Parameter info
getPosition user const char* Username in null terminated char array
x double* x-coordinate
y double* y-coordinate
z double* z-coordinate
w int* World ID
yaw float* yaw-Value
pitch float* pitch-Value
*stance double stance-Value
Return value bool, true if user has been found
Finds a player and stores its info in the referenced variables
Function Parameter name Parameter type Parameter info
teleport user const char* Username in null terminated char array
x double* x-coordinate
y double* y-coordinate
z double* z-coordinate
Return value bool, true if user was found
Teleports a user to x,y,z
Function Parameter name Parameter type Parameter info
teleport user const char* Username in null terminated char array
x double* x-coordinate
y double* y-coordinate
z double* z-coordinate
map int Map ID
Return value bool, true if user was found
Teleports a user to x,y,z on map


Function Parameter name Parameter type Parameter info
setHealth user const char* Username in null terminated char array
userHealth int Health of user. Must not be greater than 20.
Return value bool, true if user is not null
Sets the health of a user.


Function Parameter name Parameter type Parameter info
getHealth user const char* Username in null terminated char array
Return value int, player's health
Gets the health of a user


Function Parameter name Parameter type Parameter info
no paramters int, number of players online
Return value Gets the number of players online
{{{6}}}
Function Parameter name Parameter type Parameter info
getItemInHand user const char* Username in null terminated char array
*type int Type of item
*meta int Health of item
*quant int quantity of item
Return value bool, true if user was found
Gets the item in the hand of user
Function Parameter name Parameter type Parameter info
setItemInHand user const char* Username in null terminated char array
type int Type of item
meta int Health of item
quant int quantity of item, must not be greater than 64
Return value bool, true if user was found
Sets the item in the hand of user
Function Parameter name Parameter type Parameter info
addItem user const char* Username in null terminated char array
type int Type of item
meta int Health of item
quant int quantity of item, must not be greater than 64
Return value bool, true if user was found
Adds the item to the user's inventory
Function Parameter name Parameter type Parameter info
hasItem user const char* Username in null terminated char array
type int Type of item
meta int Health of item
quant int quantity of item, must not be greater than 64
Return value bool, true if the item is in Users inventory. Chests are unchecked.
Checks if item is in user's inventory
Function Parameter name Parameter type Parameter info
delItem user const char* Username in null terminated char array
type int Type of item
meta int Health of item
quant int quantity of item, must not be greater than 64
Return value bool, true if user was found
Delets the item quantity times from the user's inventory. Chests are untouched.


Function Parameter name Parameter type Parameter info
kick user const char* Username in null terminated char array
Return value bool, true if user is found
Kicks user with standard reason "You have been kicked"

Config wrapper functions

Function Parameter name Parameter type Parameter info
has name const char* name of the config string
Return value bool, true if config string was found
Checks if the config string name exists in the configuration file


Function Parameter name Parameter type Parameter info
iData name const char* name of the config string
Return value int
Gets integer data from configuration string name


Function Parameter name Parameter type Parameter info
lData name const char* name of the config string
Return value int64_t
Gets long (int64_t) data from configuration string name


Function Parameter name Parameter type Parameter info
fData name const char* name of the config string
Return value float
Gets float data from configuration string name


Function Parameter name Parameter type Parameter info
dData name const char* name of the config string
Return value double
Gets double data from configuration string name


Function Parameter name Parameter type Parameter info
sData name const char* name of the config string
Return value const char*
Gets string (char*) data from configuration string name


Function Parameter name Parameter type Parameter info
bData name const char* name of the config string
Return value bool
Gets bool data from configuration string name

Mobs

Permissions

Function Parameter name Parameter type Parameter info
setAdmin name const char* Username in null terminated char array
Return value bool, true if user was found
Makes user to a server administrator, providing him with full permissions.


Function Parameter name Parameter type Parameter info
setOp name const char* Username in null terminated char array
Return value bool, true if user was found
Makes user to a server Operator


Function Parameter name Parameter type Parameter info
setMember name const char* Username in null terminated char array
Return value bool, true if user was found
Makes user to a regular member


Function Parameter name Parameter type Parameter info
setGuest name const char* Username in null terminated char array
Return value bool, true if user was found
Makes user to a guest


Function Parameter name Parameter type Parameter info
isAdmin name const char* Username in null terminated char array
Return value bool, true if user is admin
Checks, if user is a server administrator


Function Parameter name Parameter type Parameter info
isOp name const char* Username in null terminated char array
Return value bool, true if user is operator
Checks, if user is a server Operator


Function Parameter name Parameter type Parameter info
isMember name const char* Username in null terminated char array
Return value bool, true if user is member
Checks, if user is a regular member


Function Parameter name Parameter type Parameter info
Guest name const char* Username in null terminated char array
Return value bool, true if user is guest
Checks, if user is a guest

Available callbacks

Name Parameter name Parameter type Parameter info
Timer200 no params
Return value bool, isn't used
200ms timer callback
Name Parameter name Parameter type Parameter info
Timer1000 no params
Return value bool, isn't used
1000ms (1s) timer callback
Name Parameter name Parameter type Parameter info
Timer10000 no params
Return value bool, isn't used
10s timer callback
Name Parameter name Parameter type Parameter info
PlayerChatPre user const char* Username in null terminated char array
timestamp size_t time of the message
msg const char* Message in null terminated char array
Return value bool
called on chat message processing, returning false will terminate the callback.
Name Parameter name Parameter type Parameter info
PlayerChatCommand user const char* Username in null terminated char array
command const char* command
argc int argument count
arguments const char** list of arguments
Return value bool
called when chat command is used
Name Parameter name Parameter type Parameter info
BlockPlacePre user const char* Username in char array
x int32_t x-coord
y int8_t y-coord
z int32_t z-coord
block int16_t block type
direction int8_t placement direction
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.


ToDo:

   setHook("PlayerLoginPre", new Hook2<bool,const char*,char***>);
   setHook("PlayerLoginPost", new Hook1<bool,const char*>);
   setHook("PlayerNickPost", new Hook2<bool,const char*,const char*>);
   setHook("PlayerKickPost", new Hook2<bool,const char*,const char*>);
   setHook("PlayerQuitPost", new Hook1<bool,const char*>);
   setHook("PlayerChatPost", new Hook3<bool,const char*,time_t,const char*>);
   setHook("PlayerArmSwing", new Hook1<bool,const char*>);
   setHook("PlayerDamagePre", new Hook3<bool,const char*,const char*,int>);
   setHook("PlayerDamagePost", new Hook3<bool,const char*,const char*,int>);
   setHook("PlayerDisconnect", new Hook3<bool,const char*,uint32,uint16>);
   setHook("PlayerDiggingStarted", new Hook4<bool,const char*,sint32,sint8,sint32>);
   setHook("PlayerDigging", new Hook4<bool,const char*,sint32,sint8,sint32>);
   setHook("PlayerDiggingStopped", new Hook4<bool,const char*,sint32,sint8,sint32>);
   setHook("BlockBreakPre", new Hook4<bool,const char*,sint32,sint8,sint32>);
   setHook("BlockBreakPost", new Hook4<bool,const char*,sint32,sint8,sint32>);
   setHook("BlockNeighbourBreak", new Hook7<bool,const char*,sint32,sint8,sint32,sint32,sint8,sint32>);
   setHook("BlockPlacePre", new Hook5<bool,const char*,sint32,sint8,sint32,sint16>);
   setHook("BlockPlacePost", new Hook5<bool,const char*,sint32,sint8,sint32,sint16>);
   setHook("BlockNeighbourPlace", new Hook7<bool,const char*,sint32,sint8,sint32,sint32,sint8,sint32>);
   setHook("BlockReplacePost", new Hook6<bool,const char*,sint32,sint8,sint32,sint16,sint16>);
   setHook("BlockNeighbourReplace", new Hook9<bool,const char*,sint32,sint8,sint32,sint32,sint8,sint32,sint16,sint16>);