diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-26 21:20:49 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-26 21:20:49 +0200 |
commit | 89d9abf9115a74a063e547f84a076165196954bf (patch) | |
tree | 131d27b85f7da7cd9cf19482b00549bda04aaf17 /MCServer/Plugins | |
parent | Block entities with storage now correctly mark the chunk as dirty when their contents change. (diff) | |
download | cuberite-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')
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/CommandHandlers.lua | 98 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/CurrentLng.lua | 27 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/HookHandlers.lua | 99 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/PlayerAreas.lua | 73 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/ProtectionAreas.deproj | 27 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua | 20 | ||||
-rw-r--r-- | MCServer/Plugins/ProtectionAreas/Storage.lua | 9 |
7 files changed, 353 insertions, 0 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua new file mode 100644 index 000000000..21049a517 --- /dev/null +++ b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua @@ -0,0 +1,98 @@ +
+-- CommandHandlers.lua
+-- Defines the individual command handlers
+
+
+
+
+
+function InitializeCommandHandlers()
+ local PlgMgr = cRoot:Get():GetPluginManager();
+ for idx, Cmd in ipairs(CommandReg()) do
+ PlgMgr:BindCommand(Cmd[2], Cmd[3], Cmd[1], Cmd[4]);
+ end
+end
+
+
+
+
+
+--- Handles the ProtAdd command
+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.");
+ return true;
+ end
+
+ -- TODO: Add the area to the storage and reload all currently logged in players
+
+ return true;
+end
+
+
+
+
+
+function HandleAddAreaCoords(a_Split, a_Player)
+ -- TODO
+end
+
+
+
+
+
+function HandleAddAreaUser(a_Split, a_Player)
+ -- TODO
+end
+
+
+
+
+
+function HandleDelArea(a_Split, a_Player)
+ -- TODO
+end
+
+
+
+
+
+function HandleGiveWand(a_Split, a_Player)
+ local NumGiven = a_Player:GetInventory():AddItem(cConfig:GetWandItem());
+ if (NumGiven == 1) then
+ a_Player:SendMessage("Wand given");
+ else
+ a_Player:SendMessage("Cannot give wand, no space in your inventory");
+ end
+ return true;
+end
+
+
+
+
+
+function HandleListAreas(a_Split, a_Player)
+ -- TODO
+end
+
+
+
+
+
+function HandleRemoveUser(a_Split, a_Player)
+ -- TODO
+end
+
+
+
+
+
+function HandleRemoveUserAll(a_Split, a_Player)
+ -- TODO
+end
+
+
+
+
+
diff --git a/MCServer/Plugins/ProtectionAreas/CurrentLng.lua b/MCServer/Plugins/ProtectionAreas/CurrentLng.lua new file mode 100644 index 000000000..0c5fc636b --- /dev/null +++ b/MCServer/Plugins/ProtectionAreas/CurrentLng.lua @@ -0,0 +1,27 @@ +
+-- CurrentLng.lua
+-- This file provides all the translatable strings
+-- The expectation is that the translators will create copies of this file, translate the texts and then the users will overwrite this file with a specific language version
+-- Note that the individual languages must not have ".lua" extension, otherwise MCServer will load them and the plugin won't work!
+
+
+
+
+-- Individual commands, and their help strings. Don't touch the first symbol on each line!
+
+function CommandReg()
+ return {
+ -- Handler function | Command | Permission | Help text
+ {HandleAddArea, "/ProtAdd", "Prot.Add", "Adds a new protected area"},
+ {HandleAddAreaCoords, "/ProtAddCoords", "Prot.Add", "Adds a new protected area by coords"},
+ {HandleAddAreaUser, "/ProtAddUser", "Prot.AddUser", "Adds a new user to an existing protected area"},
+ {HandleDelArea, "/ProtDelID", "Prot.Del", "Deletes a protected area by ID"},
+ {HandleGiveWand, "/ProtWand", "Prot.Wand", "Gives you the wand used for protection"},
+ {HandleListAreas, "/ProtList", "Prot.List", "Lists all areas for the marked block"},
+ {HandleRemoveUser, "/ProtRemUser", "Prot.RemUser", "Removes a user from the protected area"},
+ {HandleRemoveUserAll, "/ProtRemUserAll", "Prot.RemUser", "Removes a user from all protected areas"},
+ };
+end;
+
+
+
diff --git a/MCServer/Plugins/ProtectionAreas/HookHandlers.lua b/MCServer/Plugins/ProtectionAreas/HookHandlers.lua new file mode 100644 index 000000000..21ac6ef4d --- /dev/null +++ b/MCServer/Plugins/ProtectionAreas/HookHandlers.lua @@ -0,0 +1,99 @@ +
+-- HookHandlers.lua
+-- Implements the handlers for individual hooks
+
+
+
+
+
+function InitializeHooks(a_Plugin)
+ local PlgMgr = cRoot:Get():GetPluginManager();
+ PlgMgr:AddHook(a_Plugin, cPluginManager.HOOK_DISCONNECT);
+ PlgMgr:AddHook(a_Plugin, cPluginManager.HOOK_PLAYER_JOINED);
+ PlgMgr:AddHook(a_Plugin, cPluginManager.HOOK_PLAYER_LEFT_CLICK);
+ PlgMgr:AddHook(a_Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICK);
+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;
+
+ -- If the player is a VIP, they had a command state, remove that as well
+ CommandStates[a_Player:GetUniqueID()] = nil;
+
+ return false;
+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
+
+ return false;
+end
+
+
+
+
+
+function OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status)
+ -- If the player has lclked with the wand; regardless of their permissions, let's set the coords:
+ if (cConfig:IsWand(a_Player:GetEquippedItem())) then
+ -- BlockFace < 0 means "use item", for which the coords are not given by the client
+ if (a_BlockFace < 0) then
+ return true;
+ end
+
+ -- Convert the clicked coords into the block space
+ a_BlockX, a_BlockY, a_BlockZ = AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+
+ -- Set the coords in the CommandState
+ GetCommandStateForPlayer(a_Player):SetCoords1(a_BlockX, a_BlockY, a_BlockZ);
+ a_Player:SendMessage("Coords1 set as {" .. a_BlockX .. ", " .. a_BlockY .. ", " .. a_BlockZ .."}.");
+ return true;
+ end;
+
+ -- TODO: Check the player areas to see whether to disable this action
+
+ return false;
+end
+
+
+
+
+
+function OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_Status)
+ -- If the player has rclked with the wand; regardless of their permissions, let's set the coords
+ if (cConfig:IsWand(a_Player:GetEquippedItem())) then
+ -- BlockFace < 0 means "use item", for which the coords are not given by the client
+ if (a_BlockFace < 0) then
+ return true;
+ end
+
+ -- Convert the clicked coords into the block space
+ a_BlockX, a_BlockY, a_BlockZ = AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+
+ -- Set the coords in the CommandState
+ GetCommandStateForPlayer(a_Player):SetCoords2(a_BlockX, a_BlockY, a_BlockZ);
+ a_Player:SendMessage("Coords2 set as {" .. a_BlockX .. ", " .. a_BlockY .. ", " .. a_BlockZ .."}.");
+ return true;
+ end;
+
+ -- TODO: Check the player areas to see whether to disable this action
+
+ return false;
+end
+
+
+
+
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
+
+
+
+
diff --git a/MCServer/Plugins/ProtectionAreas/ProtectionAreas.deproj b/MCServer/Plugins/ProtectionAreas/ProtectionAreas.deproj new file mode 100644 index 000000000..d1a2188f7 --- /dev/null +++ b/MCServer/Plugins/ProtectionAreas/ProtectionAreas.deproj @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<project> + <file> + <filename>CommandHandlers.lua</filename> + </file> + <file> + <filename>CommandState.lua</filename> + </file> + <file> + <filename>Config.lua</filename> + </file> + <file> + <filename>CurrentLng.lua</filename> + </file> + <file> + <filename>HookHandlers.lua</filename> + </file> + <file> + <filename>PlayerAreas.lua</filename> + </file> + <file> + <filename>ProtectionAreas.lua</filename> + </file> + <file> + <filename>Storage.lua</filename> + </file> +</project> diff --git a/MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua b/MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua new file mode 100644 index 000000000..36256c5f3 --- /dev/null +++ b/MCServer/Plugins/ProtectionAreas/ProtectionAreas.lua @@ -0,0 +1,20 @@ +
+-- ProtectionAreas.lua
+-- Defines the main plugin entrypoint
+
+
+
+
+
+function Initialize(a_Plugin)
+ a_Plugin:SetName("ProtectionAreas");
+ a_Plugin:SetVersion(1);
+
+ InitializeHooks(a_Plugin);
+ InitializeCommandHandlers();
+
+ -- TODO: We might be reloading, so there may be players already present in the server
+ -- Reload areas for all present players
+
+ return true;
+end
diff --git a/MCServer/Plugins/ProtectionAreas/Storage.lua b/MCServer/Plugins/ProtectionAreas/Storage.lua new file mode 100644 index 000000000..260f895c2 --- /dev/null +++ b/MCServer/Plugins/ProtectionAreas/Storage.lua @@ -0,0 +1,9 @@ +
+-- Storage.lua
+-- Implements the storage access object, shielding the rest of the code away from the DB
+
+
+
+
+
+-- TODO
|