From b84cd0b3c573d584d2dd73b9e3866cd990b9fd49 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 29 Dec 2013 13:15:46 +0100 Subject: APIDump: Documented OnPluginsLoaded. --- MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua (limited to 'MCServer/Plugins/APIDump/Hooks') 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 +} + + + + -- cgit v1.2.3 From 61254d035643de23013b8995a7385ac79a673cbd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 29 Dec 2013 14:48:58 +0100 Subject: APIDump: Fixed a factual error in OnPluginsLoaded description. --- MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'MCServer/Plugins/APIDump/Hooks') diff --git a/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua b/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua index d36cdf5c5..0d5b7271e 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua @@ -6,8 +6,8 @@ return 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. + perfect occasion for a plugin to query other plugins through {{cPluginManager}}:GetPlugin() and + possibly start communicating with them using the {{cPlugin}}:Call() function. ]], Params = {}, Returns = [[ -- cgit v1.2.3 From db935c4194b01e754a188473118055fd08e7d450 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 31 Dec 2013 14:50:46 +0100 Subject: Documented OnPlayerFished and OnPlayerFishing. --- MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua | 20 ++++++++++++++++++++ MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua create mode 100644 MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua (limited to 'MCServer/Plugins/APIDump/Hooks') diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua new file mode 100644 index 000000000..03ab5bfb9 --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua @@ -0,0 +1,20 @@ +return +{ + HOOK_PLAYER_FISHED = + { + CalledWhen = "A player gets a reward from fishing.", + DefaultFnName = "OnPlayerFished", -- also used as pagename + Desc = [[ + This hook gets called when a player already has his reward from fishing. + ]], + Params = + { + { Name = "Player", Type = "{{cPlayer}}", Notes = "The player who pulled the fish in." }, + { Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, tressure and junk." }, + }, + Returns = [[ + If the function returns false or no value, the next plugin's callback is called. If the function returns true, no other + callback is called for this event. + ]], + }, -- HOOK_PLAYER_FISHED +} \ No newline at end of file diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua new file mode 100644 index 000000000..1989b02cd --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua @@ -0,0 +1,21 @@ +return +{ + HOOK_PLAYER_FISHING = + { + CalledWhen = "A player is about to get a reward from fishing.", + DefaultFnName = "OnPlayerFishing", -- also used as pagename + Desc = [[ + This hook gets called when a player right clicks with a fishing rod while the floater is under water. + ]], + Params = + { + { Name = "Player", Type = "{{cPlayer}}", Notes = "The player who pulled the fish in." }, + { Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, tressure and junk." }, + }, + Returns = [[ + If the function returns false or no value, the next plugin's callback is called. Afterwards, the + server gives the player his reward. If the function returns true, no other + callback is called for this event and the player doesn't get his reward. + ]], + }, -- HOOK_PLAYER_FISHING +} \ No newline at end of file -- cgit v1.2.3 From c5b89ea0f5561ff1569d7b9638252cf3a0d9626c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 1 Jan 2014 15:02:43 +0100 Subject: Fixed typo's in the documentation. --- MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua | 4 ++-- MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'MCServer/Plugins/APIDump/Hooks') diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua index 03ab5bfb9..0ad2a3af3 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua @@ -10,11 +10,11 @@ return Params = { { Name = "Player", Type = "{{cPlayer}}", Notes = "The player who pulled the fish in." }, - { Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, tressure and junk." }, + { Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, treasure and junk." }, }, Returns = [[ If the function returns false or no value, the next plugin's callback is called. If the function returns true, no other callback is called for this event. ]], }, -- HOOK_PLAYER_FISHED -} \ No newline at end of file +}; \ No newline at end of file diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua index 1989b02cd..14851c08d 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua @@ -10,7 +10,7 @@ return Params = { { Name = "Player", Type = "{{cPlayer}}", Notes = "The player who pulled the fish in." }, - { Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, tressure and junk." }, + { Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, treasure and junk." }, }, Returns = [[ If the function returns false or no value, the next plugin's callback is called. Afterwards, the @@ -18,4 +18,4 @@ return callback is called for this event and the player doesn't get his reward. ]], }, -- HOOK_PLAYER_FISHING -} \ No newline at end of file +}; \ No newline at end of file -- cgit v1.2.3 From 78a876ace321648db85a9373cca2a4f03ef09873 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 1 Jan 2014 15:15:56 +0100 Subject: Using documentation Xoft recommended. --- MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MCServer/Plugins/APIDump/Hooks') diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua index 0ad2a3af3..40dd6b3cf 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua @@ -5,7 +5,7 @@ return CalledWhen = "A player gets a reward from fishing.", DefaultFnName = "OnPlayerFished", -- also used as pagename Desc = [[ - This hook gets called when a player already has his reward from fishing. + This hook gets called after a player reels in the fishing rod. This is a notification-only hook, the reward has already been decided. If a plugin needs to modify the reward, use the {{OnPlayerFishing|HOOK_PLAYER_FISHING}} hook. ]], Params = { -- cgit v1.2.3 From d656c253c0ead77218a8236e72b678b07316bd2c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 1 Jan 2014 15:18:12 +0100 Subject: Little more documentation for OnPlayerFishing. --- MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MCServer/Plugins/APIDump/Hooks') diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua index 14851c08d..3b4731091 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua @@ -5,7 +5,7 @@ return CalledWhen = "A player is about to get a reward from fishing.", DefaultFnName = "OnPlayerFishing", -- also used as pagename Desc = [[ - This hook gets called when a player right clicks with a fishing rod while the floater is under water. + This hook gets called when a player right clicks with a fishing rod while the floater is under water. The reward is already descided, but the plugin may change it. ]], Params = { -- cgit v1.2.3