summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'MCServer/Plugins/ProtectionAreas/CommandHandlers.lua')
-rw-r--r--MCServer/Plugins/ProtectionAreas/CommandHandlers.lua170
1 files changed, 153 insertions, 17 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua
index cc2e18b21..18ab29f68 100644
--- a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua
+++ b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua
@@ -33,15 +33,6 @@ function HandleAddArea(a_Split, a_Player)
end
local Cuboid = CmdState:GetCurrentCuboid();
if (Cuboid == nil) then
- a_Player:SendMessage("Cannot add area, internal plugin error (Cuboid == nil)");
- return true;
- end
-
- -- If the cuboid hasn't been assigned, give the player an error message and bail out
- if (
- (Cuboid.p1.x == 0) and (Cuboid.p1.y == 0) and (Cuboid.p1.z == 0) and
- (Cuboid.p1.x == 0) and (Cuboid.p1.y == 0) and (Cuboid.p1.z == 0)
- ) then
a_Player:SendMessage("Cannot add area, no area has been selected. Use a ProtWand lclk / rclk to select area first");
return true;
end
@@ -53,10 +44,11 @@ function HandleAddArea(a_Split, a_Player)
end
-- Add the area to the storage
- g_Storage:AddArea(Cuboid, a_Player:GetName(), AllowedNames);
+ g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
a_Player:SendMessage("Area added");
- -- TODO: Reload all currently logged in players
+ -- Reload all currently logged in players
+ ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
return true;
end
@@ -66,7 +58,36 @@ end
function HandleAddAreaCoords(a_Split, a_Player)
- -- TODO
+ -- Command syntax: ProtAddCoords x1 z1 x2 z2 username1 [username2] [username3] ...
+ if (#a_Split < 6) then
+ a_Player:SendMessage("Not enough parameters. Expected <x1> <z1> <x2> <z2> coords and a list of usernames.");
+ return true;
+ end
+
+ -- Convert the coords to a cCuboid
+ local x1, z1 = tonumber(a_Split[2]), tonumber(a_Split[3]);
+ local x2, z2 = tonumber(a_Split[4]), tonumber(a_Split[5]);
+ if ((x1 == nil) or (z1 == nil) or (x2 == nil) or (z2 == nil)) then
+ a_Player:SendMessage("Cannot parse coords.");
+ return true;
+ end
+ local Cuboid = cCuboid(x1, 0, z1, x2, 255, z1);
+ Cuboid:Sort();
+
+ -- Put all allowed players into a table:
+ AllowedNames = {};
+ for i = 6, #a_Split do
+ table.insert(AllowedNames, a_Split[i]);
+ end
+
+ -- Add the area to the storage
+ g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
+ a_Player:SendMessage("Area added");
+
+ -- Reload all currently logged in players
+ ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
+
+ return true;
end
@@ -74,7 +95,26 @@ end
function HandleAddAreaUser(a_Split, a_Player)
- -- TODO
+ -- Command syntax: ProtAddUser AreaID username1 [username2] [username3] ...
+ if (#a_Split < 3) then
+ a_Player:SendMessage("Not enough parameters. Expected <AreaID> and a list of usernames.");
+ return true;
+ end
+
+ -- Put all allowed players into a table:
+ AllowedNames = {};
+ for i = 3, #a_Split do
+ table.insert(AllowedNames, a_Split[i]);
+ end
+
+ -- Add the area to the storage
+ g_Storage:AddAreaUsers(tonumber(a_Split[2]), a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
+ a_Player:SendMessage("Users added: " .. table.concat(AllowedNames, ", "));
+
+ -- Reload all currently logged in players
+ ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
+
+ return true;
end
@@ -82,7 +122,26 @@ end
function HandleDelArea(a_Split, a_Player)
- -- TODO
+ -- Command syntax: ProtDelArea AreaID
+ if (#a_Split ~= 2) then
+ a_Player:SendMessage("Parameter mismatch. Expected <AreaID>.");
+ return true;
+ end
+
+ -- Parse the AreaID
+ local AreaID = tonumber(a_Split[2]);
+ if (AreaID == nil) then
+ a_Player:SendMessage("Cannot parse <AreaID>.");
+ return true;
+ end
+
+ -- Delete the area
+ g_Storage:DelArea(a_Player:GetWorld():GetName(), AreaID);
+
+ -- Reload all currently logged in players
+ ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
+
+ return true;
end
@@ -104,7 +163,61 @@ end
function HandleListAreas(a_Split, a_Player)
- -- TODO
+ -- Command syntax: ProtListAreas [x, z]
+
+ local x, z;
+ if (#a_Split == 1) then
+ -- Get the last "wanded" coord
+ local CmdState = GetCommandStateForPlayer(a_Player);
+ if (CmdState == nil) then
+ a_Player:SendMessage("Cannot list area, internal plugin error (CmdState == nil)");
+ return true;
+ end
+ x, z = CmdState:GetLastCoords();
+ if ((x == nil) or (z == nil)) then
+ a_Player:SendMessage("Cannot list areas, no query point has been selected. Use a ProtWand lclk / rclk to select a point first");
+ return true;
+ end
+ elseif (#a_Split == 3) then
+ -- Parse the coords from the command params
+ x = tonumber(a_Split[2]);
+ z = tonumber(a_Split[3]);
+ if ((x == nil) or (z == nil)) then
+ a_Player:SendMessage("Cannot list areas, cannot parse coords in params");
+ return true;
+ end
+ else
+ -- Wrong number of params, report back to the user
+ a_Player:SendMessage("Cannot list areas, syntax error. Expected either no params or <x> <z>.");
+ return true;
+ end
+
+ 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 Allowance;
+ if (a_IsAllowed) then
+ Allowance = "Allowed";
+ else
+ Allowance = "NOT allowed";
+ end
+ a_Player:SendMessage(" " .. Coords .. Allowance);
+ end
+ );
+
+ a_Player:SendMessage("Area list finished");
+ return true;
end
@@ -112,7 +225,22 @@ end
function HandleRemoveUser(a_Split, a_Player)
- -- TODO
+ -- Command syntax: ProtRemUser AreaID UserName
+ if (#a_Split ~= 3) then
+ a_Player:SendMessage("Parameter mismatch. Expected <AreaID> <UserName>.");
+ return true;
+ end
+
+ -- Parse the AreaID
+ local AreaID = tonumber(a_Split[2]);
+ if (AreaID == nil) then
+ a_Player:SendMessage("Cannot parse <AreaID>.");
+ return true;
+ end
+
+ -- Remove the user from the DB
+ g_Storage:RemoveUser(AreaID, a_Split[3], a_Player:GetWorld():GetName());
+ return true;
end
@@ -120,7 +248,15 @@ end
function HandleRemoveUserAll(a_Split, a_Player)
- -- TODO
+ -- Command syntax: ProtRemUserAll UserName
+ if (#a_Split ~= 2) then
+ a_Player:SendMessage("Parameter mismatch. Expected <UserName>.");
+ return true;
+ end
+
+ -- Remove the user from the DB
+ g_Storage.RemoveUserAll(a_Split[2], a_Player:GetWorld():GetName());
+ return true;
end