diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-11 11:55:46 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-11 11:55:46 +0200 |
commit | 30924db5081f8c2322c1de81e6ff34cfe491aeee (patch) | |
tree | afe70634d8bc2ec814122d86329a756b3fc05266 /MCServer/Plugins | |
parent | ProtectionAreas: usernames are now handled case-insensitive (diff) | |
download | cuberite-30924db5081f8c2322c1de81e6ff34cfe491aeee.tar cuberite-30924db5081f8c2322c1de81e6ff34cfe491aeee.tar.gz cuberite-30924db5081f8c2322c1de81e6ff34cfe491aeee.tar.bz2 cuberite-30924db5081f8c2322c1de81e6ff34cfe491aeee.tar.lz cuberite-30924db5081f8c2322c1de81e6ff34cfe491aeee.tar.xz cuberite-30924db5081f8c2322c1de81e6ff34cfe491aeee.tar.zst cuberite-30924db5081f8c2322c1de81e6ff34cfe491aeee.zip |
Diffstat (limited to 'MCServer/Plugins')
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/CommandHandlers.lua | 79 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/CurrentLng.lua | 48 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/HookHandlers.lua | 8 |
3 files changed, 90 insertions, 45 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua index bb7da77a9..b943df060 100644 --- a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua +++ b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua @@ -21,19 +21,19 @@ end function HandleAddArea(a_Split, a_Player)
-- Command syntax: ProtAdd username1 [username2] [username3] ...
if (#a_Split < 2) then
- a_Player:SendMessage("Not enough parameters. Expected a list of usernames.");
+ a_Player:SendMessage(g_Msgs.ErrExpectedListOfUsernames);
return true;
end
-- Get the cuboid that the player had selected
local CmdState = GetCommandStateForPlayer(a_Player);
if (CmdState == nil) then
- a_Player:SendMessage("Cannot add area, internal plugin error (CmdState == nil)");
+ a_Player:SendMessage(g_Msgs.ErrCmdStateNilAddArea);
return true;
end
local Cuboid = CmdState:GetCurrentCuboid();
if (Cuboid == nil) then
- a_Player:SendMessage("Cannot add area, no area has been selected. Use a ProtWand lclk / rclk to select area first");
+ a_Player:SendMessage(g_Msgs.ErrNoAreaWanded);
return true;
end
@@ -45,7 +45,7 @@ function HandleAddArea(a_Split, a_Player) -- Add the area to the storage
local AreaID = g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
- a_Player:SendMessage("Area added, ID " .. AreaID);
+ a_Player:SendMessage(string.format(g_Msgs.AreaAdded, AreaID));
-- Reload all currently logged in players
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
@@ -60,7 +60,7 @@ end function HandleAddAreaCoords(a_Split, a_Player)
-- 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.");
+ a_Player:SendMessage(g_Msgs.ErrExpectedCoordsUsernames);
return true;
end
@@ -68,7 +68,7 @@ function HandleAddAreaCoords(a_Split, a_Player) 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.");
+ a_Player:SendMessage(g_Msgs.ErrParseCoords);
return true;
end
local Cuboid = cCuboid(x1, 0, z1, x2, 255, z1);
@@ -82,7 +82,7 @@ function HandleAddAreaCoords(a_Split, a_Player) -- Add the area to the storage
local AreaID = g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
- a_Player:SendMessage("Area added, ID = " .. AreaID);
+ a_Player:SendMessage(string.format(g_Msgs.AreaAdded, AreaID));
-- Reload all currently logged in players
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
@@ -97,7 +97,7 @@ end function HandleAddAreaUser(a_Split, a_Player)
-- 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.");
+ a_Player:SendMessage(g_Msgs.ErrExpectedAreaIDUsernames);
return true;
end
@@ -112,13 +112,13 @@ function HandleAddAreaUser(a_Split, a_Player) tonumber(a_Split[2]), a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames))
) then
LOGWARNING("g_Storage:AddAreaUsers failed");
- a_Player:SendMessage("Cannot add users, DB failure");
+ a_Player:SendMessage(g_Msgs.ErrDBFailAddUsers);
return true;
end
if (#AllowedNames == 0) then
- a_Player:SendMessage("All the specified users were already allowed.");
+ a_Player:SendMessage(g_Msgs.AllUsersAlreadyAllowed);
else
- a_Player:SendMessage("Users added: " .. table.concat(AllowedNames, ", "));
+ a_Player:SendMessage(string.format(g_Msgs.UsersAdded, table.concat(AllowedNames, ", ")));
end
-- Reload all currently logged in players
@@ -134,20 +134,21 @@ end function HandleDelArea(a_Split, a_Player)
-- Command syntax: ProtDelArea AreaID
if (#a_Split ~= 2) then
- a_Player:SendMessage("Parameter mismatch. Expected <AreaID>.");
+ a_Player:SendMessage(g_Msgs.ErrExpectedAreaID);
return true;
end
-- Parse the AreaID
local AreaID = tonumber(a_Split[2]);
if (AreaID == nil) then
- a_Player:SendMessage("Cannot parse <AreaID>.");
+ a_Player:SendMessage(g_Msgs.ErrParseAreaID);
return true;
end
-- Delete the area
g_Storage:DelArea(a_Player:GetWorld():GetName(), AreaID);
+ a_Player:SendMessage(string.format(g_Msgs.AreaDeleted, AreaID));
-- Reload all currently logged in players
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
@@ -161,9 +162,9 @@ end function HandleGiveWand(a_Split, a_Player)
local NumGiven = a_Player:GetInventory():AddItem(cConfig:GetWandItem());
if (NumGiven == 1) then
- a_Player:SendMessage("Wand given");
+ a_Player:SendMessage(g_Msgs.WandGiven);
else
- a_Player:SendMessage("Cannot give wand, no space in your inventory");
+ a_Player:SendMessage(g_Msgs.ErrNoSpaceForWand);
end
return true;
end
@@ -180,12 +181,12 @@ function HandleListAreas(a_Split, a_Player) -- 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)");
+ a_Player:SendMessage(g_Msgs.ErrCmdStateNilListAreas);
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");
+ a_Player:SendMessage(g_Msgs.ErrListNotWanded);
return true;
end
elseif (#a_Split == 3) then
@@ -193,36 +194,34 @@ function HandleListAreas(a_Split, a_Player) 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");
+ a_Player:SendMessage(g_Msgs.ErrParseCoordsListAreas);
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>.");
+ a_Player:SendMessage(g_Msgs.ErrSyntaxErrorListAreas);
return true;
end
- a_Player:SendMessage("Listing protection areas intersecting block column {" .. x .. ", " .. z .. "}:");
+ a_Player:SendMessage(string.format(g_Msgs.ListAreasHeader, x, z));
-- List areas intersecting the coords
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 Coords = string.format("%s: {%d, %d} - {%d, %d} ", AreaID, MinX, MinZ, MaxX, MaxZ);
local Allowance;
if (g_Storage:IsAreaAllowed(AreaID, PlayerName, WorldName)) then
- Allowance = "Allowed";
+ Allowance = g_Msgs.AreaAllowed;
else
- Allowance = "NOT allowed";
+ Allowance = g_Msgs.AreaNotAllowed;
end
- a_Player:SendMessage(" " .. Coords .. Allowance .. ", Created by " .. CreatorName);
+ a_Player:SendMessage(string.format(g_Msgs.ListAreasRow, Coords, Allowance, CreatorName));
end
);
- a_Player:SendMessage("Area list finished");
+ a_Player:SendMessage(g_Msgs.ListAreasFooter);
return true;
end
@@ -233,7 +232,7 @@ end function HandleListUsers(a_Split, a_Player)
-- Command syntax: ProtListUsers AreaID
if (#a_Split ~= 2) then
- a_Player:SendMessage("Expected AreaID as a parameter");
+ a_Player:SendMessage(g_Msgs.ErrExpectedAreaID);
end
-- Get the general info about the area
@@ -241,29 +240,24 @@ function HandleListUsers(a_Split, a_Player) local WorldName = a_Player:GetWorld():GetName();
local MinX, MinZ, MaxX, MaxZ, CreatorName = g_Storage:GetArea(AreaID, WorldName);
if (MinX == nil) then
- a_Player:SendMessage("No such area: " .. AreaID);
+ a_Player:SendMessage(string.format(g_Msgs.ErrNoSuchArea, AreaID));
return true;
end
-- Send the header
- a_Player:SendMessage(
- "Area ID " .. AreaID .. ": {" ..
- MinX .. ", " .. MinZ .. "} - {" ..
- MaxX .. ", " .. MaxZ .. "} " ..
- "Created by " .. CreatorName .. "; allowed users:"
- );
+ a_Player:SendMessage(string.format(g_Msgs.ListUsersHeader, AreaID, MinX, MinZ, MaxX, MaxZ, CreatorName));
-- List and count the allowed users
local NumUsers = 0;
g_Storage:ForEachUserInArea(AreaID, WorldName,
function(UserName)
- a_Player:SendMessage(" " .. UserName);
+ a_Player:SendMessage(string.format(g_Msgs.ListUsersRow, UserName));
NumUsers = NumUsers + 1;
end
);
-- Send the footer
- a_Player:SendMessage("End of area " .. AreaID .. " user list, total " .. NumUsers .. " users");
+ a_Player:SendMessage(string.format(g_Msgs.ListUsersFooter, AreaID, NumUsers));
return true;
end
@@ -275,14 +269,14 @@ end function HandleRemoveUser(a_Split, a_Player)
-- Command syntax: ProtRemUser AreaID UserName
if (#a_Split ~= 3) then
- a_Player:SendMessage("Parameter mismatch. Expected <AreaID> <UserName>.");
+ a_Player:SendMessage(g_Msgs.ErrExpectedAreaIDUserName);
return true;
end
-- Parse the AreaID
local AreaID = tonumber(a_Split[2]);
if (AreaID == nil) then
- a_Player:SendMessage("Cannot parse <AreaID>.");
+ a_Player:SendMessage(g_Msgs.ErrParseAreaID);
return true;
end
@@ -291,7 +285,7 @@ function HandleRemoveUser(a_Split, a_Player) g_Storage:RemoveUser(AreaID, UserName, a_Player:GetWorld():GetName());
-- Send confirmation
- a_Player:SendMessage("Removed " .. UserName .. " from area " .. AreaID);
+ a_Player:SendMessage(string.format(g_Msgs.RemovedUser, UserName, AreaID));
-- Reload all currently logged in players
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
@@ -306,13 +300,16 @@ end function HandleRemoveUserAll(a_Split, a_Player)
-- Command syntax: ProtRemUserAll UserName
if (#a_Split ~= 2) then
- a_Player:SendMessage("Parameter mismatch. Expected <UserName>.");
+ a_Player:SendMessage(g_Msgs.ErrExpectedUserName);
return true;
end
-- Remove the user from the DB
g_Storage:RemoveUserAll(a_Split[2], a_Player:GetWorld():GetName());
+ -- Send confirmation
+ a_Player:SendMessage(string.format(g_Msgs.RemovedUserAll, UserName));
+
-- Reload all currently logged in players
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
diff --git a/MCServer/Plugins/ProtectionAreas/CurrentLng.lua b/MCServer/Plugins/ProtectionAreas/CurrentLng.lua index 8fda353ae..f4cd4735e 100644 --- a/MCServer/Plugins/ProtectionAreas/CurrentLng.lua +++ b/MCServer/Plugins/ProtectionAreas/CurrentLng.lua @@ -8,6 +8,7 @@ -- Individual commands, and their help strings. Don't touch the first symbol on each line!
+-- This needs to be implemented as a function, because it references other functions which might not yet be loaded while Lua is processing the globals
function CommandReg()
return {
@@ -26,3 +27,50 @@ end; +
+
+--- Messages sent to players
+g_Msgs =
+{
+ AllUsersAlreadyAllowed = "All the specified users were already allowed.";
+ AreaAdded = "Area added, ID %s";
+ AreaAllowed = "Allowed";
+ AreaDeleted = "Area ID %s deleted";
+ AreaNotAllowed = "NOT allowed";
+ Coords1Set = "Coords1 set as {%d, %d}";
+ Coords2Set = "Coords2 set as {%d, %d}";
+ ErrCmdStateNilAddArea = "Cannot add area, internal plugin error (CmdState == nil)";
+ ErrCmdStateNilListAreas = "Cannot list areas, internal plugin error (CmdState == nil)";
+ ErrDBFailAddUsers = "Cannot add users, DB failure";
+ ErrExpectedAreaID = "Parameter mismatch. Expected <AreaID>.";
+ ErrExpectedAreaIDUserName = "Parameter mismatch. Expected <AreaID> <UserName>.";
+ ErrExpectedAreaIDUsernames = "Not enough parameters. Expected <AreaID> and a list of usernames.";
+ ErrExpectedCoordsUsernames = "Not enough parameters. Expected <x1> <z1> <x2> <z2> coords and a list of usernames.";
+ ErrExpectedListOfUsernames = "Not enough parameters. Expected a list of usernames.";
+ ErrExpectedUserName = "Parameter mismatch. Expected <UserName>.";
+ ErrListNotWanded = "Cannot list areas, no query point has been selected. Use a ProtWand lclk / rclk to select a point first";
+ ErrNoAreaWanded = "Cannot add area, no area has been selected. Use a ProtWand lclk / rclk to select area first";
+ ErrNoSpaceForWand = "Cannot give wand, no space in your inventory";
+ ErrNoSuchArea = "No such area: %s";
+ ErrParseAreaID = "Cannot parse <AreaID>.";
+ ErrParseCoords = "Cannot parse coords.";
+ ErrParseCoordsListAreas = "Cannot list areas, cannot parse coords in params";
+ ErrSyntaxErrorListAreas = "Cannot list areas, syntax error. Expected either no params or <x> <z>.";
+ ListAreasFooter = "Area list finished";
+ ListAreasHeader = "Listing protection areas intersecting block column {%d, %d}:";
+ ListAreasRow = " %s, %s, created by %s";
+ ListUsersFooter = "End of area %s user list, total %d users";
+ ListUsersHeader = "Area ID %s: {%d, %d} - {%d, %d}, created by %s; allowed users:";
+ ListUsersRow = " %s";
+ NotAllowedToBuild = "You are not allowed to build here!";
+ NotAllowedToDig = "You are not allowed to dig here!";
+ RemovedUser = "Removed %s from area %d";
+ RemovedUserAll = "Removed %s from all areas";
+ UsersAdded = "Users added: %s";
+ WandGiven = "Wand given";
+} ;
+
+
+
+
+
diff --git a/MCServer/Plugins/ProtectionAreas/HookHandlers.lua b/MCServer/Plugins/ProtectionAreas/HookHandlers.lua index db552067c..18fd4fa03 100644 --- a/MCServer/Plugins/ProtectionAreas/HookHandlers.lua +++ b/MCServer/Plugins/ProtectionAreas/HookHandlers.lua @@ -85,14 +85,14 @@ function OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, -- Set the coords in the CommandState
GetCommandStateForPlayer(a_Player):SetCoords1(a_BlockX, a_BlockZ);
- a_Player:SendMessage("Coords1 set as {" .. a_BlockX .. ", " .. a_BlockZ .."}.");
+ a_Player:SendMessage(string.format(g_Msgs.Coords1Set, a_BlockX, a_BlockZ));
return true;
end;
-- 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_BlockZ)) then
- a_Player:SendMessage("You are not allowed to dig here!");
+ a_Player:SendMessage(g_Msgs.NotAllowedToDig);
return true;
end
@@ -119,14 +119,14 @@ function OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, if (cConfig:IsWand(a_Player:GetEquippedItem())) then
-- Set the coords in the CommandState
GetCommandStateForPlayer(a_Player):SetCoords2(a_BlockX, a_BlockZ);
- a_Player:SendMessage("Coords2 set as {" .. a_BlockX .. ", " .. a_BlockZ .."}.");
+ a_Player:SendMessage(string.format(g_Msgs.Coords2Set, a_BlockX, a_BlockZ));
return true;
end;
-- 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_BlockZ)) then
- a_Player:SendMessage("You are not allowed to build here!");
+ a_Player:SendMessage(g_Msgs.NotAllowedToBuild);
return true;
end
|