summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/APIDump/Hooks
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-01-12 10:04:16 +0100
committermadmaxoft <github@xoft.cz>2014-01-12 10:04:16 +0100
commit180b9b90993870532a8daa2ee6498005b6c3bf49 (patch)
treedac846b760b6f5fd294fbd771975dd55b0856c0d /MCServer/Plugins/APIDump/Hooks
parentFixed Linux configuration. (diff)
parentDisabled a useless MSVC warning in Bindings.cpp. (diff)
downloadcuberite-180b9b90993870532a8daa2ee6498005b6c3bf49.tar
cuberite-180b9b90993870532a8daa2ee6498005b6c3bf49.tar.gz
cuberite-180b9b90993870532a8daa2ee6498005b6c3bf49.tar.bz2
cuberite-180b9b90993870532a8daa2ee6498005b6c3bf49.tar.lz
cuberite-180b9b90993870532a8daa2ee6498005b6c3bf49.tar.xz
cuberite-180b9b90993870532a8daa2ee6498005b6c3bf49.tar.zst
cuberite-180b9b90993870532a8daa2ee6498005b6c3bf49.zip
Diffstat (limited to 'MCServer/Plugins/APIDump/Hooks')
-rw-r--r--MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua20
-rw-r--r--MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua21
-rw-r--r--MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua79
3 files changed, 120 insertions, 0 deletions
diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua
new file mode 100644
index 000000000..4e093f4ae
--- /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 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 =
+ {
+ { 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, 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
+};
diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua
new file mode 100644
index 000000000..c5aaecd92
--- /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. The reward is already descided, but the plugin may change it.
+ ]],
+ 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, treasure 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
+};
diff --git a/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua b/MCServer/Plugins/APIDump/Hooks/OnPluginsLoaded.lua
new file mode 100644
index 000000000..0d5b7271e
--- /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 through {{cPluginManager}}:GetPlugin() and
+ possibly start communicating with them using the {{cPlugin}}: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
+}
+
+
+
+