From 89d9abf9115a74a063e547f84a076165196954bf Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 26 May 2013 19:20:49 +0000 Subject: ProtectionAreas: Initial project import, skeleton code git-svn-id: http://mc-server.googlecode.com/svn/trunk@1516 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- MCServer/Plugins/ProtectionAreas/HookHandlers.lua | 99 +++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 MCServer/Plugins/ProtectionAreas/HookHandlers.lua (limited to 'MCServer/Plugins/ProtectionAreas/HookHandlers.lua') diff --git a/MCServer/Plugins/ProtectionAreas/HookHandlers.lua b/MCServer/Plugins/ProtectionAreas/HookHandlers.lua new file mode 100644 index 000000000..21ac6ef4d --- /dev/null +++ b/MCServer/Plugins/ProtectionAreas/HookHandlers.lua @@ -0,0 +1,99 @@ + +-- HookHandlers.lua +-- Implements the handlers for individual hooks + + + + + +function InitializeHooks(a_Plugin) + local PlgMgr = cRoot:Get():GetPluginManager(); + PlgMgr:AddHook(a_Plugin, cPluginManager.HOOK_DISCONNECT); + PlgMgr:AddHook(a_Plugin, cPluginManager.HOOK_PLAYER_JOINED); + PlgMgr:AddHook(a_Plugin, cPluginManager.HOOK_PLAYER_LEFT_CLICK); + PlgMgr:AddHook(a_Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICK); +end + + + + + +function OnDisconnect(a_Player, a_Reason) + -- Remove the player's cProtectionArea object + -- TODO: What if there are two players with the same name? need to check + g_PlayerAreas[a_Player:GetName()] = nil; + + -- If the player is a VIP, they had a command state, remove that as well + CommandStates[a_Player:GetUniqueID()] = nil; + + return false; +end; + + + + + +function OnPlayerJoined(a_Player) + -- Create a new cProtectionArea for this player + g_PlayerAreas[a_Player:GetName()] = cPlayerAreas:new(); + + -- TODO: Load the protection areas for this player + + return false; +end + + + + + +function OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status) + -- If the player has lclked with the wand; regardless of their permissions, let's set the coords: + if (cConfig:IsWand(a_Player:GetEquippedItem())) then + -- BlockFace < 0 means "use item", for which the coords are not given by the client + if (a_BlockFace < 0) then + return true; + end + + -- Convert the clicked coords into the block space + a_BlockX, a_BlockY, a_BlockZ = AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + + -- Set the coords in the CommandState + GetCommandStateForPlayer(a_Player):SetCoords1(a_BlockX, a_BlockY, a_BlockZ); + a_Player:SendMessage("Coords1 set as {" .. a_BlockX .. ", " .. a_BlockY .. ", " .. a_BlockZ .."}."); + return true; + end; + + -- TODO: Check the player areas to see whether to disable this action + + return false; +end + + + + + +function OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_Status) + -- If the player has rclked with the wand; regardless of their permissions, let's set the coords + if (cConfig:IsWand(a_Player:GetEquippedItem())) then + -- BlockFace < 0 means "use item", for which the coords are not given by the client + if (a_BlockFace < 0) then + return true; + end + + -- Convert the clicked coords into the block space + a_BlockX, a_BlockY, a_BlockZ = AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + + -- Set the coords in the CommandState + GetCommandStateForPlayer(a_Player):SetCoords2(a_BlockX, a_BlockY, a_BlockZ); + a_Player:SendMessage("Coords2 set as {" .. a_BlockX .. ", " .. a_BlockY .. ", " .. a_BlockZ .."}."); + return true; + end; + + -- TODO: Check the player areas to see whether to disable this action + + return false; +end + + + + -- cgit v1.2.3