GranularPermissionsV3
Hey developers, I’m bringing in a new handy module for you all to enjoy today.
Most of you following me will know my previous GranularPermissions modules haven’t been that usefull because they worked from alot of preset functions and such, well… here’s a solution to that.
I’m bringing you GranularPermissionsV3, the new way to run dynamic player & server checks in your games.
Registered as a LuaClass this module is quite useful, and doesn’t incur you using the repetitive :GetRankInGroup()
checks repetidly.
Here’s some basic documentation regarding the module:
--[[
The GranularPermissions module provides a flexible and granular permission management system for Roblox games.
It allows you to define authorization rules for players and groups, as well as register custom callbacks for
determining authorization based on specific conditions.
Usage:
local GranularPermissions = require("GranularPermissionsModulePath")
-- Creating a new instance of GranularPermissions
local permissions = GranularPermissions.new()
-- Registering an OmniUser (a user with full permissions)
permissions:RegisterOmniUser(userId)
-- Registering a replacement rule
permissions:RegisterReplacement("ReplacementName", "ReplaceWith")
-- Registering multiple replacement rules
-- Replacements replace arguments you pass into your details after the callback type such as XXXX:Argument:Argument
So if you want to a preset group Id and run your details via "Group:MyGroup:1-255", that's absolutely something you can do!
permissions:RegisterReplacementsBulk({
{ ReplacementName = "Replacement1", ReplaceWith = "Value1" },
{ ReplacementName = "Replacement2", ReplaceWith = "Value2" }
})
-- Registering a custom authorization callback
permissions:RegisterCallback("CallbackName", function(player, arguments)
-- Your custom authorization logic here
return true -- or false based on authorization result
end)
-- Checking if a player is authorized based on details
--Details are formatted like this:
{"CallbackName:Argument:Argument", ..., ImportAll = true|false}
You can have endless callbacks and arguments, and can even stack them inside each other to get a great result like this -
{"CallBackName:Test:1", {"CallBackName1:Test1:2", ImportAll = true} ,ImportAll = true}
If you put "!" infront of any callbackName, it'll return the opposite value.
[ImportAll]: This is a boolean that ensures that the user must meet ALL of the criteria passed, even if the criteria is stacked.
local isAuthorized = permissions:IsAuthorised(player, detailsTable)
-- Unregistering an OmniUser
permissions:UnregisterOmniUser(userId)
-- Updating the splitting syntax used in authorization details
permissions:UpdateSplittingSyntax(":")
-- Destroying the GranularPermissions instance when no longer needed
permissions:Destroy()
]]
And here’s an example of registering this with a group check callback:
local Permissions = require(ReplicatedStorage.GranularPermissions).new()
Permissions:RegisterReplacementsBulk({
{
ReplacementName = "MyGroup",
ReplaceWith = "16949084"
}
})
Permissions:RegisterCallback("Group", function(Player: Player, Arguments: any)
if Arguments[2] and Arguments[3] then
local Group = tonumber(Arguments[2])
local RankFrom;
local RankTo;
if not Group then
return false
end
if typeof(Arguments[3]) == "table" and Arguments[3][1] and Arguments[3][2] and tonumber(Arguments[3][1]) and tonumber(Arguments[3][2]) then
RankFrom = tonumber(Arguments[3][1])
RankTo = tonumber(Arguments[3][2])
elseif typeof(Arguments[3]) == "string" and tonumber(Arguments[3]) then
RankFrom = tonumber(Arguments[3])
RankTo = tonumber(Arguments[3])
end
local PlayerRank = Player:GetRankInGroup(Group)
return PlayerRank >= RankFrom and PlayerRank <= RankTo
end
return false
end)
print(Permissions:IsAuthorised(Player, {"Group:MyGroup:1-255"}))
Now I haven’t fully tested this module so if any bugs do occur please ensure you post here so I can work to fix them
Enjoy!