diff options
author | madmaxoft <github@xoft.cz> | 2013-12-29 13:15:46 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-12-29 13:15:46 +0100 |
commit | b84cd0b3c573d584d2dd73b9e3866cd990b9fd49 (patch) | |
tree | 55809a9f7120a4b391b011796f5651b23cd92c96 /MCServer/Plugins/APIDump | |
parent | Added HOOK_PLUGINS_LOADED. (diff) | |
download | cuberite-b84cd0b3c573d584d2dd73b9e3866cd990b9fd49.tar cuberite-b84cd0b3c573d584d2dd73b9e3866cd990b9fd49.tar.gz cuberite-b84cd0b3c573d584d2dd73b9e3866cd990b9fd49.tar.bz2 cuberite-b84cd0b3c573d584d2dd73b9e3866cd990b9fd49.tar.lz cuberite-b84cd0b3c573d584d2dd73b9e3866cd990b9fd49.tar.xz cuberite-b84cd0b3c573d584d2dd73b9e3866cd990b9fd49.tar.zst cuberite-b84cd0b3c573d584d2dd73b9e3866cd990b9fd49.zip |
Diffstat (limited to '')
-rw-r--r-- | MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua b/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua new file mode 100644 index 000000000..d36cdf5c5 --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua @@ -0,0 +1,79 @@ +return +{ + HOOK_PLUGINS_LOADED = + { + CalledWhen = "All the enabled plugins have been loaded", + DefaultFnName = "OnPluginsLoaded", -- also used as pagename + Desc = [[ + This callback gets called when the server finishes loading and initializing plugins. This is the + perfect occasion for a plugin to query other plugins and possibly start communicating with them using + the {{cPluginManager}}:Call() function. + ]], + Params = {}, + Returns = [[ + The return value is ignored, all registered callbacks are called. + ]], + CodeExamples = + { + { + Title = "CoreMessaging", + Desc = [[ + This example shows how to implement the CoreMessaging functionality - messages to players will be + sent through the Core plugin, formatted by that plugin. As a fallback for when the Core plugin is + not present, the messages are sent directly by this code, unformatted. + ]], + Code = [[ +-- These are the fallback functions used when the Core is not present: +local function SendMessageFallback(a_Player, a_Message) + a_Player:SendMessage(a_Message); +end + +local function SendMessageSuccessFallback(a_Player, a_Message) + a_Player:SendMessage(a_Message); +end + +local function SendMessageFailureFallback(a_Player, a_Message) + a_Player:SendMessage(a_Message); +end + +-- These three "variables" will hold the actual functions to call. +-- By default they are initialized to the Fallback variants, but will be redirected to Core when all plugins load +SendMessage = SendMessageFallback; +SendMessageSuccess = SendMessageSuccessFallback; +SendMessageFailure = SendMessageFailureFallback; + +-- The callback tries to connect to the Core, if successful, overwrites the three functions with Core ones +local function OnPluginsLoaded() + local CorePlugin = cPluginManager:Get():GetPlugin("Core"); + if (CorePlugin == nil) then + -- The Core is not loaded, keep the Fallback functions + return; + end + + -- Overwrite the three functions with Core functionality: + SendMessage = function(a_Player, a_Message) + CorePlugin:Call("SendMessage", a_Player, a_Message); + end + SendMessageSuccess = function(a_Player, a_Message) + CorePlugin:Call("SendMessageSuccess", a_Player, a_Message); + end + SendMessageFailure = function(a_Player, a_Message) + CorePlugin:Call("SendMessageFailure", a_Player, a_Message); + end +end + +-- Global scope, register the callback: +cPluginManager.AddHook(cPluginManager.HOOK_PLUGINS_LOADED, CoreMessagingPluginsLoaded); + + +-- Usage, anywhere else in the plugin: +SendMessageFailure(a_Player, "Cannot teleport to player, the destination player " .. PlayerName .. " was not found"); + ]], + }, + } , -- CodeExamples + }, -- HOOK_PLUGINS_LOADED +} + + + + |