summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-04 23:05:33 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-04 23:05:33 +0200
commitf746d17424a071c15fd5b92bc521ce832ba15a07 (patch)
tree85fce40aa5d92dc03c360c916e277c5bf2f35ee6
parentAdded script to generate cloc statistics (diff)
downloadcuberite-f746d17424a071c15fd5b92bc521ce832ba15a07.tar
cuberite-f746d17424a071c15fd5b92bc521ce832ba15a07.tar.gz
cuberite-f746d17424a071c15fd5b92bc521ce832ba15a07.tar.bz2
cuberite-f746d17424a071c15fd5b92bc521ce832ba15a07.tar.lz
cuberite-f746d17424a071c15fd5b92bc521ce832ba15a07.tar.xz
cuberite-f746d17424a071c15fd5b92bc521ce832ba15a07.tar.zst
cuberite-f746d17424a071c15fd5b92bc521ce832ba15a07.zip
-rw-r--r--MCServer/Plugins/ProtectionAreas/CommandState.lua2
-rw-r--r--MCServer/Plugins/ProtectionAreas/HookHandlers.lua26
-rw-r--r--MCServer/Plugins/ProtectionAreas/PlayerAreas.lua6
-rw-r--r--MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua1
-rw-r--r--MCServer/Plugins/ProtectionAreas/Storage.lua49
5 files changed, 72 insertions, 12 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/CommandState.lua b/MCServer/Plugins/ProtectionAreas/CommandState.lua
index f9d0e28db..3df1259cc 100644
--- a/MCServer/Plugins/ProtectionAreas/CommandState.lua
+++ b/MCServer/Plugins/ProtectionAreas/CommandState.lua
@@ -40,7 +40,7 @@ end
--- Returns the current coord pair as a cCuboid object
-function cCommandState.GetCurrentCuboid()
+function cCommandState:GetCurrentCuboid()
local res = cCuboid(
self.Coords1.x, self.Coords1.y, self.Coords1.z,
self.Coords2.x, self.Coords2.y, self.Coords2.z
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
diff --git a/MCServer/Plugins/ProtectionAreas/PlayerAreas.lua b/MCServer/Plugins/ProtectionAreas/PlayerAreas.lua
index 472a4c59b..5d054ea15 100644
--- a/MCServer/Plugins/ProtectionAreas/PlayerAreas.lua
+++ b/MCServer/Plugins/ProtectionAreas/PlayerAreas.lua
@@ -11,7 +11,7 @@ A player can interact with a block if either one of these is true:
2, There is at least one area covering the block with IsAllowed set to true
The OOP class implementation follows the PiL 16.1
-Also, a global table g_PlayerAreas is the actual map of PlayerName -> cPlayerAreas
+Also, a global table g_PlayerAreas is the actual map of PlayerID -> cPlayerAreas
--]]
@@ -37,7 +37,7 @@ end
-- Adds a new cuboid to the area list, where the player is either allowed or not, depending on the IsAllowed param
function cPlayerAreas:AddArea(a_Cuboid, a_IsAllowed)
- table.add(self, {Cuboid = a_Cuboid, IsAllowed = a_IsAllowed});
+ table.insert(self, {Cuboid = a_Cuboid, IsAllowed = a_IsAllowed});
end
@@ -45,7 +45,7 @@ end
--- returns true if the player owning this object can interact with the specified block
-function cPlayerAreas:CanInteract(a_BlockX, a_BlockY, a_BlockZ)
+function cPlayerAreas:CanInteractWithBlock(a_BlockX, a_BlockY, a_BlockZ)
-- iterate through all the stored areas:
local IsInsideAnyArea = false;
for idx, Area in ipairs(self) do
diff --git a/MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua b/MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua
index 36256c5f3..d816f578f 100644
--- a/MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua
+++ b/MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua
@@ -10,6 +10,7 @@ function Initialize(a_Plugin)
a_Plugin:SetName("ProtectionAreas");
a_Plugin:SetVersion(1);
+ InitializeStorage();
InitializeHooks(a_Plugin);
InitializeCommandHandlers();
diff --git a/MCServer/Plugins/ProtectionAreas/Storage.lua b/MCServer/Plugins/ProtectionAreas/Storage.lua
index 260f895c2..8aebae0c7 100644
--- a/MCServer/Plugins/ProtectionAreas/Storage.lua
+++ b/MCServer/Plugins/ProtectionAreas/Storage.lua
@@ -2,8 +2,55 @@
-- Storage.lua
-- Implements the storage access object, shielding the rest of the code away from the DB
+--[[
+The cStorage class is the interface to the underlying storage, the SQLite database.
+This class knows how to load player areas from the DB, how to add or remove areas in the DB
+and other such operations.
+
+Also, a g_Storage global variable is declared, it holds the single instance of the storage.
+--]]
+
+
+
+
+
+cStorage = {};
+
+g_Storage = {};
+
+
+
+
+
+--- Initializes the storage subsystem, creates the g_Storage object
+function InitializeStorage()
+ g_Storage = cStorage:new();
+end
+
+
+
+
+
+function cStorage:new(obj)
+ obj = obj or {};
+ setmetatable(obj, self);
+ self.__index = self;
+ return obj;
+end
+
+
+
+
+--- Loads cPlayerAreas for the specified player from the DB. Returns a cPlayerAreas object
+function cStorage:LoadPlayerAreas(PlayerName)
+ local res = cPlayerAreas:new();
+ -- TODO: Load the areas from the DB, based on the player's location
+
+ -- DEBUG: Insert a dummy area for testing purposes:
+ res:AddArea(cCuboid(10, 0, 10, 20, 255, 20), false);
+ return res;
+end
--- TODO