Difference between revisions of "Plugin API"

From Mineserver Wiki
Jump to navigation Jump to search
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>
−
    std::ostringstream result;
+
#include <cstdlib>
−
    result << n;
+
#include <iostream>
−
    return result.str();
+
−
  }
+
#define MINESERVER_C_API
−
  mineserver_pointer_struct* mineserver;
+
#include "../src/plugin_api.h"
−
  std::string pluginName = "command";
+
#include "../src/logtype.h"
−
  PLUGIN_API_EXPORT void (plugin_name)_init(mineserver_pointer_struct* mineserver_temp)
+
 +
#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 = mineserver_temp;
+
mineserver->logger.log(LogType::LOG_INFO, logSource, "The " PLUGIN_NAME " plugin is already loaded");
−
if (mineserver->plugin.getPluginVersion(pluginName.c_str()) > 0)
+
return;
−
    {
 
−
      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->plugin.addCallback("PlayerChatPre", (void *)SOMEFUNCTIONNAME);
 
−
    mineserver->plugin.addCallback("BlockPlacePre", (void *)SOMEFUNCTIONNAME2);
 
  }
  }
−
  PLUGIN_API_EXPORT void (plugin_name)_shutdown(void)
+
 +
  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)
  {
  {
−
if (mineserver->plugin.getPluginVersion(pluginName.c_str()) <= 0)
+
mineserver->logger.log(LogType::LOG_INFO, logSource, PLUGIN_NAME " is not loaded!");
−
{
+
return;
−
      mineserver->screen.log("command is not loaded!"));
 
−
      return;
 
−
    }
 
  }
  }
−
</code>
+
  mineserver->logger.log(LogType::LOG_INFO, logSource, PLUGIN_NAME " has been unloaded!");
 +
}
 +
</nowiki>
 +
</pre>
 +
==Available functions==
==Available functions==
 
{{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}}
{{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}}
+
{{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==