1
0
Fork 0

ProtectionAreas: Actual protection is now working, areas are hard-coded (10,10) - (20,20)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1557 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-06-04 21:05:33 +00:00
parent 29db8d92b2
commit f746d17424
5 changed files with 72 additions and 12 deletions

View File

@ -40,7 +40,7 @@ end
--- Returns the current coord pair as a cCuboid object
function cCommandState.GetCurrentCuboid()
function cCommandState:GetCurrentCuboid()
local res = cCuboid(
self.Coords1.x, self.Coords1.y, self.Coords1.z,
self.Coords2.x, self.Coords2.y, self.Coords2.z

View File

@ -21,7 +21,7 @@ end
function OnDisconnect(a_Player, a_Reason)
-- Remove the player's cProtectionArea object
-- TODO: What if there are two players with the same name? need to check
g_PlayerAreas[a_Player:GetName()] = nil;
g_PlayerAreas[a_Player:GetUniqueID()] = nil;
-- If the player is a VIP, they had a command state, remove that as well
g_CommandStates[a_Player:GetUniqueID()] = nil;
@ -34,10 +34,12 @@ end;
function OnPlayerJoined(a_Player)
-- Create a new cProtectionArea for this player
g_PlayerAreas[a_Player:GetName()] = cPlayerAreas:new();
-- TODO: Load the protection areas for this player
-- Create a new cPlayerAreas object for this player
local PlayerName = a_Player:GetName();
local PlayerID = a_Player:GetUniqueID();
if (g_PlayerAreas[PlayerID] == nil) then
g_PlayerAreas[PlayerID] = g_Storage:LoadPlayerAreas(PlayerName);
end;
return false;
end
@ -63,8 +65,13 @@ function OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
return true;
end;
-- TODO: Check the player areas to see whether to disable this action
-- 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_BlockY, a_BlockZ)) then
return true;
end
-- Allow interaction
return false;
end
@ -89,8 +96,13 @@ function OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
return true;
end;
-- TODO: Check the player areas to see whether to disable this action
-- 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_BlockY, a_BlockZ)) then
return true;
end
-- Allow interaction
return false;
end

View File

@ -11,7 +11,7 @@ A player can interact with a block if either one of these is true:
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
Also, a global table g_PlayerAreas is the actual map of PlayerID -> cPlayerAreas
--]]
@ -37,7 +37,7 @@ 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});
table.insert(self, {Cuboid = a_Cuboid, IsAllowed = a_IsAllowed});
end
@ -45,7 +45,7 @@ end
--- returns true if the player owning this object can interact with the specified block
function cPlayerAreas:CanInteract(a_BlockX, a_BlockY, a_BlockZ)
function cPlayerAreas:CanInteractWithBlock(a_BlockX, a_BlockY, a_BlockZ)
-- iterate through all the stored areas:
local IsInsideAnyArea = false;
for idx, Area in ipairs(self) do

View File

@ -10,6 +10,7 @@ function Initialize(a_Plugin)
a_Plugin:SetName("ProtectionAreas");
a_Plugin:SetVersion(1);
InitializeStorage();
InitializeHooks(a_Plugin);
InitializeCommandHandlers();

View File

@ -2,8 +2,55 @@
-- Storage.lua
-- Implements the storage access object, shielding the rest of the code away from the DB
--[[
The cStorage class is the interface to the underlying storage, the SQLite database.
This class knows how to load player areas from the DB, how to add or remove areas in the DB
and other such operations.
Also, a g_Storage global variable is declared, it holds the single instance of the storage.
--]]
cStorage = {};
g_Storage = {};
--- Initializes the storage subsystem, creates the g_Storage object
function InitializeStorage()
g_Storage = cStorage:new();
end
function cStorage:new(obj)
obj = obj or {};
setmetatable(obj, self);
self.__index = self;
return obj;
end
--- Loads cPlayerAreas for the specified player from the DB. Returns a cPlayerAreas object
function cStorage:LoadPlayerAreas(PlayerName)
local res = cPlayerAreas:new();
-- TODO: Load the areas from the DB, based on the player's location
-- DEBUG: Insert a dummy area for testing purposes:
res:AddArea(cCuboid(10, 0, 10, 20, 255, 20), false);
return res;
end
-- TODO