summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/ProtectionAreas/HookHandlers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'MCServer/Plugins/ProtectionAreas/HookHandlers.lua')
-rw-r--r--MCServer/Plugins/ProtectionAreas/HookHandlers.lua26
1 files changed, 19 insertions, 7 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/HookHandlers.lua b/MCServer/Plugins/ProtectionAreas/HookHandlers.lua
index 4f1e3755e..d0748a8a4 100644
--- a/MCServer/Plugins/ProtectionAreas/HookHandlers.lua
+++ b/MCServer/Plugins/ProtectionAreas/HookHandlers.lua
@@ -21,7 +21,7 @@ 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;
+ g_PlayerAreas[a_Player:GetUniqueID()] = nil;
-- If the player is a VIP, they had a command state, remove that as well
g_CommandStates[a_Player:GetUniqueID()] = nil;
@@ -34,10 +34,12 @@ 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
+ -- Create a new cPlayerAreas object for this player
+ local PlayerName = a_Player:GetName();
+ local PlayerID = a_Player:GetUniqueID();
+ if (g_PlayerAreas[PlayerID] == nil) then
+ g_PlayerAreas[PlayerID] = g_Storage:LoadPlayerAreas(PlayerName);
+ end;
return false;
end
@@ -63,8 +65,13 @@ function OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
return true;
end;
- -- TODO: Check the player areas to see whether to disable this action
+ -- Check the player areas to see whether to disable this action
+ local Areas = g_PlayerAreas[a_Player:GetUniqueID()];
+ if not(Areas:CanInteractWithBlock(a_BlockX, a_BlockY, a_BlockZ)) then
+ return true;
+ end
+ -- Allow interaction
return false;
end
@@ -89,8 +96,13 @@ function OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
return true;
end;
- -- TODO: Check the player areas to see whether to disable this action
+ -- Check the player areas to see whether to disable this action
+ local Areas = g_PlayerAreas[a_Player:GetUniqueID()];
+ if not(Areas:CanInteractWithBlock(a_BlockX, a_BlockY, a_BlockZ)) then
+ return true;
+ end
+ -- Allow interaction
return false;
end