Difference between revisions of "Plugin API"
Jump to navigation
Jump to search
Example plugin structure: | Example plugin structure: | ||
| − | < | + | <pre><nowiki> |
| − | + | #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 | + | 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!"); | |
| + | } | ||
| + | </nowiki> | ||
| + | </pre> | ||
| + | |||
==Available functions== | ==Available functions== | ||
