diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-07 18:28:37 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-07 18:28:37 +0200 |
commit | 9790a6817cb4f1b4821de9af2630558cb5df882f (patch) | |
tree | ed9fd86bef0a74f0fcdc9b9bed12bb49c274b146 /MCServer/Plugins/ProtectionAreas/CommandState.lua | |
parent | ProtectionAreas: Newly added areas are stored in the DB (diff) | |
download | cuberite-9790a6817cb4f1b4821de9af2630558cb5df882f.tar cuberite-9790a6817cb4f1b4821de9af2630558cb5df882f.tar.gz cuberite-9790a6817cb4f1b4821de9af2630558cb5df882f.tar.bz2 cuberite-9790a6817cb4f1b4821de9af2630558cb5df882f.tar.lz cuberite-9790a6817cb4f1b4821de9af2630558cb5df882f.tar.xz cuberite-9790a6817cb4f1b4821de9af2630558cb5df882f.tar.zst cuberite-9790a6817cb4f1b4821de9af2630558cb5df882f.zip |
Diffstat (limited to '')
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/CommandState.lua | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/CommandState.lua b/MCServer/Plugins/ProtectionAreas/CommandState.lua index 8feae8f8c..dacf04599 100644 --- a/MCServer/Plugins/ProtectionAreas/CommandState.lua +++ b/MCServer/Plugins/ProtectionAreas/CommandState.lua @@ -18,8 +18,10 @@ Also, a global table g_CommandStates is the map of PlayerEntityID -> cCommandSta cCommandState = {
-- Default coords
- m_Coords1 = {x = 0, y = 0, z = 0};
- m_Coords2 = {x = 0, y = 0, z = 0};
+ m_Coords1 = {x = 0, z = 0}; -- lclk coords
+ m_Coords2 = {x = 0, z = 0}; -- rclk coords
+ m_LastCoords = 0; -- When Coords1 or Coords2 is set, this gets set to 1 or 2, signifying the last changed set of coords
+ m_HasCoords = 1; -- Set to 0, 1, 2 or 3, based on which set of coords has been set (bitmask)
};
g_CommandStates = {};
@@ -41,6 +43,11 @@ end --- Returns the current coord pair as a cCuboid object
function cCommandState:GetCurrentCuboid()
+ if (self.m_HasCoords ~= 3) then
+ -- Some of the coords haven't been set yet
+ return nil;
+ end
+
local res = cCuboid(
self.m_Coords1.x, self.m_Coords1.y, self.m_Coords1.z,
self.m_Coords2.x, self.m_Coords2.y, self.m_Coords2.z
@@ -52,11 +59,33 @@ end +
+--- Returns the x, z coords that were the set last,
+-- That is, either m_Coords1 or m_Coords2, based on m_LastCoords member
+-- Returns nothing if no coords were set yet
+function cCommandState:GetLastCoords()
+ if (self.m_LastCoords == 0) then
+ -- No coords have been set yet
+ return;
+ elseif (self.m_LastCoords == 1) then
+ return self.m_Coords1.x, self.m_Coords1.z;
+ elseif (self.m_LastCoords == 2) then
+ return self.m_Coords2.x, self.m_Coords2.z;
+ else
+ LOGWARNING(PluginPrefix .. "cCommandState is in an unexpected state, m_LastCoords == " .. self.m_LastCoords);
+ return;
+ end
+end
+
+
+
+
+
--- Sets the first set of coords (upon rclk with a wand)
-function cCommandState:SetCoords1(a_BlockX, a_BlockY, a_BlockZ)
+function cCommandState:SetCoords1(a_BlockX, a_BlockZ)
self.m_Coords1.x = a_BlockX;
- self.m_Coords1.y = a_BlockY;
self.m_Coords1.z = a_BlockZ;
+ self.m_LastCoords = 1;
end
@@ -64,10 +93,10 @@ end --- Sets the second set of coords (upon lclk with a wand)
-function cCommandState:SetCoords2(a_BlockX, a_BlockY, a_BlockZ)
+function cCommandState:SetCoords2(a_BlockX, a_BlockZ)
self.m_Coords2.x = a_BlockX;
- self.m_Coords2.y = a_BlockY;
self.m_Coords2.z = a_BlockZ;
+ self.m_LastCoords = 2;
end
|