mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Added to common and added more comments to groups
This commit is contained in:
@@ -13,6 +13,44 @@ function Public.type_check(value,test_type)
|
||||
return test_type and value and type(value) == test_type or not test_type and not value or false
|
||||
end
|
||||
|
||||
--- Raises an error if invalid type is given
|
||||
-- @tparam value any the value that you want to test the type of
|
||||
-- @tparam test_type string the type that the value should be
|
||||
-- @tparam error_message string the error message that is returned
|
||||
-- @tparam level number the level to call the error on (level = 1 means the caller)
|
||||
-- @treturn boolean true if no error was called
|
||||
function Public.type_check_error(value,test_type,error_message,level)
|
||||
level = level and level+1 or 2
|
||||
return Public.test_type(value,test_type) or error(error_message,level)
|
||||
end
|
||||
|
||||
--- Raises an error with type error with a consistent error message
|
||||
-- @tparam value any the value that you want to test the type of
|
||||
-- @tparam test_type string the type that the value should be
|
||||
-- @tparam param_name string the name of the param
|
||||
-- @tparam param_number number the number param it is
|
||||
-- @treturn boolean true if no error was raised
|
||||
function Public.param_check(value,test_type,param_name,param_number)
|
||||
if not Public.test_type(value,test_type) then
|
||||
local function_name = debug.getinfo(2,'n').name or '<anon>'
|
||||
local error_message = string.format('Invalid param #%2d given to %s; %s is not of type %s',param_number,function_name,param_name,test_type)
|
||||
return error(error_message,3)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Extracts certain keys from a table
|
||||
-- @tparam tbl table the table which contains the keys
|
||||
-- @tparam ... string the names of the keys you want extracted
|
||||
-- @return the keys in the order given
|
||||
function Public.extract_keys(tbl,...)
|
||||
local values = {}
|
||||
for _,key in pairs({...}) do
|
||||
table.insert(values,tbl[key])
|
||||
end
|
||||
return unpack(values)
|
||||
end
|
||||
|
||||
--- Will return a value of any type to the player/server console, allows colour for in-game players
|
||||
-- @usage player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
|
||||
-- @usage player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
|
||||
@@ -54,4 +92,25 @@ function Public.player_return(value,colour,player)
|
||||
else rcon.print(returnAsString) end
|
||||
end
|
||||
|
||||
--- Calls a require that will not error if the file is not found
|
||||
-- @tparam path string the path that you want to require
|
||||
-- @return the returns from that file or nil, error if not loaded
|
||||
function Public.opt_require(path)
|
||||
local success, rtn = pcall(require,path)
|
||||
if success then return rtn
|
||||
else return nil,rtn end
|
||||
end
|
||||
|
||||
--- Calls a require and returns only the keys given, file must return a table
|
||||
-- @tparam path string the path that you want to require
|
||||
-- @tparam ... string the name of the keys that you want returned
|
||||
-- @return the keys in the order given
|
||||
function Public.ext_require(path,...)
|
||||
local rtn = require(path)
|
||||
if type(rtn) ~= 'table' then
|
||||
error('File did not return a table, can not extract keys.',2)
|
||||
end
|
||||
return Public.extract_keys(rtn,...)
|
||||
end
|
||||
|
||||
return Public
|
||||
@@ -23,7 +23,30 @@
|
||||
:allow('write_to_console') -- here we allow them to chat, {} can be used here if we had more than one action
|
||||
|
||||
>>>>Functions List (see function for more detail):
|
||||
Permissions_Groups.new_group(name) --- Defines a new permission group that can have it actions set in the config
|
||||
Permissions_Groups.get_group_by_name(name) --- Returns the group with the given name, case sensitive
|
||||
Permissions_Groups.get_group_from_player(player) --- Returns the group that a player is in
|
||||
|
||||
Permissions_Groups.reload_permissions() --- Reloads/creates all permission groups and sets them to they configured state
|
||||
Permissions_Groups.lockdown_permissions(exempt) --- Removes all permissions from every permission group except for "Default" and any passed as exempt
|
||||
|
||||
Permissions_Groups.set_player_group(player,group) --- Sets a player's group to the one given, a player can only have one group at a time
|
||||
|
||||
Permissions_Groups._prototype:set_action(action,state) --- Sets the allow state of an action for this group, used internally but is safe to use else where
|
||||
Permissions_Groups._prototype:allow(actions) --- Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime
|
||||
Permissions_Groups._prototype:disallow(actions) --- Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime
|
||||
Permissions_Groups._prototype:allow_all() --- Sets the default state for any actions not given to be allowed, useful with :disallow
|
||||
Permissions_Groups._prototype:disallow_all() --- Sets the default state for any action not given to be disallowed, useful with :allow
|
||||
Permissions_Groups._prototype:is_allowed(action) --- Returns if an input action is allowed for this group
|
||||
|
||||
Permissions_Groups._prototype:get_raw() --- Returns the LuaPermissionGroup that was created with this group object, used internally
|
||||
Permissions_Groups._prototype:create() --- Creates or updates the permission group with the configured actions, used internally
|
||||
|
||||
Permissions_Groups._prototype:add_player(player) --- Adds a player to this group
|
||||
Permissions_Groups._prototype:remove_player(player) --- Removes a player from this group
|
||||
Permissions_Groups._prototype:get_players(online) --- Returns all player that are in this group with the option to filter to online/offline only
|
||||
|
||||
Permissions_Groups._prototype:print(message) --- Prints a message to every player in this group
|
||||
]]
|
||||
|
||||
|
||||
@@ -62,6 +85,7 @@ end
|
||||
-- @treturn ?Permissions_Groups._prototype|nil the group with that player or nil if non found
|
||||
function Permissions_Groups.get_group_from_player(player)
|
||||
player = Game.get_player_from_any(player)
|
||||
if not player then return end
|
||||
local group = player.permission_group
|
||||
if group then
|
||||
return Permissions_Groups.groups[group.name]
|
||||
|
||||
Reference in New Issue
Block a user