diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-08 17:06:24 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-08 17:06:24 +0200 |
commit | 2b232f547197ff061c395bf24030f489a58d9e0c (patch) | |
tree | 7b49d0c74d7fd2bfa0cf9c392ee71488a75cf520 /MCServer/Plugins/ProtectionAreas | |
parent | ProtectionAreas: The areas are now read from the DB (once) (diff) | |
download | cuberite-2b232f547197ff061c395bf24030f489a58d9e0c.tar cuberite-2b232f547197ff061c395bf24030f489a58d9e0c.tar.gz cuberite-2b232f547197ff061c395bf24030f489a58d9e0c.tar.bz2 cuberite-2b232f547197ff061c395bf24030f489a58d9e0c.tar.lz cuberite-2b232f547197ff061c395bf24030f489a58d9e0c.tar.xz cuberite-2b232f547197ff061c395bf24030f489a58d9e0c.tar.zst cuberite-2b232f547197ff061c395bf24030f489a58d9e0c.zip |
Diffstat (limited to 'MCServer/Plugins/ProtectionAreas')
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/CommandHandlers.lua | 30 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/Storage.lua | 42 |
2 files changed, 52 insertions, 20 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua index 18ab29f68..eec1f8042 100644 --- a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua +++ b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua @@ -44,8 +44,8 @@ function HandleAddArea(a_Split, a_Player) end
-- Add the area to the storage
- g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
- a_Player:SendMessage("Area added");
+ local AreaID = g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
+ a_Player:SendMessage("Area added, ID " .. AreaID);
-- Reload all currently logged in players
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
@@ -81,8 +81,8 @@ function HandleAddAreaCoords(a_Split, a_Player) end
-- Add the area to the storage
- g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
- a_Player:SendMessage("Area added");
+ local AreaID = g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
+ a_Player:SendMessage("Area added, ID = " .. AreaID);
-- Reload all currently logged in players
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
@@ -195,24 +195,20 @@ function HandleListAreas(a_Split, a_Player) a_Player:SendMessage("Listing protection areas intersecting block column {" .. x .. ", " .. z .. "}:");
-- List areas intersecting the coords
- local Areas = g_PlayerAreas[a_Player:GetUniqueID()]
- Areas:ForEachArea(
- function(a_Cuboid, a_IsAllowed)
- if (not(a_Cuboid:IsInside(x, 1, z))) then
- -- This cuboid doesn't intersect the column
- return;
- end
- -- Column intersected, send to the player
- local Coords = "{" ..
- a_Cuboid.p1.x .. ", " .. a_Cuboid.p1.z .. "} - {" ..
- a_Cuboid.p2.x .. ", " .. a_Cuboid.p2.z .. "} ";
+ local PlayerName = a_Player:GetName();
+ local WorldName = a_Player:GetWorld():GetName();
+ g_Storage:ForEachArea(x, z, WorldName,
+ function(AreaID, MinX, MinZ, MaxX, MaxZ, CreatorName)
+ local Coords = AreaID .. ": {" ..
+ MinX .. ", " .. MinZ .. "} - {" ..
+ MaxX .. ", " .. MaxZ .. "} ";
local Allowance;
- if (a_IsAllowed) then
+ if (g_Storage:IsAreaAllowed(AreaID, PlayerName, WorldName)) then
Allowance = "Allowed";
else
Allowance = "NOT allowed";
end
- a_Player:SendMessage(" " .. Coords .. Allowance);
+ a_Player:SendMessage(" " .. Coords .. Allowance .. ", Created by " .. CreatorName);
end
);
diff --git a/MCServer/Plugins/ProtectionAreas/Storage.lua b/MCServer/Plugins/ProtectionAreas/Storage.lua index 3c7a09b4e..b84415c1d 100644 --- a/MCServer/Plugins/ProtectionAreas/Storage.lua +++ b/MCServer/Plugins/ProtectionAreas/Storage.lua @@ -211,6 +211,7 @@ end --- Adds a new area into the DB. a_AllowedNames is a table listing all the players that are allowed in the area
+-- Returns the ID of the new area, or -1 on failure
function cStorage:AddArea(a_Cuboid, a_WorldName, a_CreatorName, a_AllowedNames)
-- Store the area in the DB
local ID = -1;
@@ -229,11 +230,11 @@ function cStorage:AddArea(a_Cuboid, a_WorldName, a_CreatorName, a_AllowedNames) "'); SELECT last_insert_rowid() AS ID";
if (not(self:DBExec(sql, RememberID))) then
LOGWARNING(PluginPrefix .. "SQL Error while inserting new area");
- return false;
+ return -1;
end
if (ID == -1) then
LOGWARNING(PluginPrefix .. "SQL Error while retrieving INSERTion ID");
- return false;
+ return -1;
end
-- Store each allowed player in the DB
@@ -243,7 +244,7 @@ function cStorage:AddArea(a_Cuboid, a_WorldName, a_CreatorName, a_AllowedNames) LOGWARNING(PluginPrefix .. "SQL Error while inserting new area's allowed player " .. Name);
end
end
- return true;
+ return ID;
end
@@ -289,3 +290,38 @@ end +
+--- Calls the callback for each area intersecting the specified coords
+-- Callback signature: function(ID, MinX, MinZ, MaxX, MaxZ, CreatorName)
+function cStorage:ForEachArea(a_BlockX, a_BlockZ, a_WorldName, a_Callback)
+
+ -- SQL callback that parses the values and calls our callback
+ function CallCallback(UserData, NumValues, Values, Names)
+ if (NumValues ~= 6) then
+ -- Not enough values returned, skip this row
+ return 0;
+ end
+ local ID = Values[1];
+ local MinX = Values[2];
+ local MaxX = Values[3];
+ local MinZ = Values[4];
+ local MaxZ = Values[5];
+ local CreatorName = Values[6];
+ a_Callback(ID, MinX, MinZ, MaxX, MaxZ, CreatorName);
+ return 0;
+ end
+
+ local sql = "SELECT ID, MinX, MinZ, MaxX, MaxZ, CreatorUserName FROM Areas WHERE " ..
+ "MinX <= " .. a_BlockX .. " AND MaxX >= " .. a_BlockX .. " AND " ..
+ "MinZ <= " .. a_BlockZ .. " AND MaxZ >= " .. a_BlockZ;
+ if (not(self:DBExec(sql, CallCallback))) then
+ LOGWARNING("SQL Error while iterating through areas (cStorage:ForEachArea())");
+ return false;
+ end
+ return true;
+end
+
+
+
+
+
|