summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/ProtectionAreas/PlayerAreas.lua
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-26 21:20:49 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-26 21:20:49 +0200
commit89d9abf9115a74a063e547f84a076165196954bf (patch)
tree131d27b85f7da7cd9cf19482b00549bda04aaf17 /MCServer/Plugins/ProtectionAreas/PlayerAreas.lua
parentBlock entities with storage now correctly mark the chunk as dirty when their contents change. (diff)
downloadcuberite-89d9abf9115a74a063e547f84a076165196954bf.tar
cuberite-89d9abf9115a74a063e547f84a076165196954bf.tar.gz
cuberite-89d9abf9115a74a063e547f84a076165196954bf.tar.bz2
cuberite-89d9abf9115a74a063e547f84a076165196954bf.tar.lz
cuberite-89d9abf9115a74a063e547f84a076165196954bf.tar.xz
cuberite-89d9abf9115a74a063e547f84a076165196954bf.tar.zst
cuberite-89d9abf9115a74a063e547f84a076165196954bf.zip
Diffstat (limited to 'MCServer/Plugins/ProtectionAreas/PlayerAreas.lua')
-rw-r--r--MCServer/Plugins/ProtectionAreas/PlayerAreas.lua73
1 files changed, 73 insertions, 0 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/PlayerAreas.lua b/MCServer/Plugins/ProtectionAreas/PlayerAreas.lua
new file mode 100644
index 000000000..472a4c59b
--- /dev/null
+++ b/MCServer/Plugins/ProtectionAreas/PlayerAreas.lua
@@ -0,0 +1,73 @@
+
+-- PlayerAreas.lua
+-- Implements the cPlayerAreas class representing the per-player area storage object
+
+--[[
+Each player instance is expected to have a separate object of type cPlayerAreas.
+Each object has an array of {cuboid, IsAllowed} tables, one for each area that is "within reach"
+The code can then ask each object, whether the player can interact with a certain block or not.
+A player can interact with a block if either one of these is true:
+1, There are no areas covering the block
+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
+--]]
+
+
+
+
+cPlayerAreas = {};
+
+g_PlayerAreas = {};
+
+
+
+
+
+function cPlayerAreas:new(obj)
+ obj = obj or {};
+ setmetatable(obj, self);
+ self.__index = self;
+ return obj;
+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});
+end
+
+
+
+
+
+--- returns true if the player owning this object can interact with the specified block
+function cPlayerAreas:CanInteract(a_BlockX, a_BlockY, a_BlockZ)
+ -- iterate through all the stored areas:
+ local IsInsideAnyArea = false;
+ for idx, Area in ipairs(self) do
+ if (Area.Cuboid:IsInside(a_BlockX, a_BlockY, a_BlockZ)) then
+ if (Area.IsAllowed) then
+ return true;
+ end
+ -- The coords are inside a cuboid for which the player doesn't have access, take a note of it
+ IsInsideAnyArea = true;
+ end
+ end
+
+ if (IsInsideAnyArea) then
+ -- The specified coords are inside at least one area, but none of them allow the player to interact
+ return false;
+ end
+
+ -- The coords are not inside any area
+ -- TODO: Have a config saying whether a player can build in the non-areated space or not
+ return true;
+end
+
+
+
+