From 1cd8503ee17927a7b60de99c4eac73139f593ed7 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Thu, 1 Sep 2022 07:22:44 +1000 Subject: [PATCH 1/2] fix(server/player): don't refresh commands when updating PlayerData --- server/player.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/player.lua b/server/player.lua index 13336cd..9ea25d8 100644 --- a/server/player.lua +++ b/server/player.lua @@ -183,13 +183,10 @@ function QBCore.Player.CreatePlayer(PlayerData, Offline) self.PlayerData = PlayerData self.Offline = Offline - function self.Functions.UpdatePlayerData(dontUpdateChat) + function self.Functions.UpdatePlayerData() if self.Offline then return end -- Unsupported for Offline Players TriggerEvent('QBCore:Player:SetPlayerData', self.PlayerData) TriggerClientEvent('QBCore:Player:SetPlayerData', self.PlayerData.source, self.PlayerData) - if not dontUpdateChat then - QBCore.Commands.Refresh(self.PlayerData.source) - end end function self.Functions.SetJob(job, grade) From bc7555a49c9bd212d52bf9c290bcf8e1bf4464c1 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Thu, 1 Sep 2022 07:17:26 +1000 Subject: [PATCH 2/2] refactor(server/functions): grant principal to player.id Easier to read and test aces. --- server/functions.lua | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/server/functions.lua b/server/functions.lua index f586e1e..c472b68 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -308,25 +308,23 @@ end -- Setting & Removing Permissions function QBCore.Functions.AddPermission(source, permission) - local src = source - local license = QBCore.Functions.GetIdentifier(src, 'license') - ExecuteCommand(('add_principal identifier.%s qbcore.%s'):format(license, permission)) - QBCore.Commands.Refresh(src) + if not IsPlayerAceAllowed(source, permission) then + ExecuteCommand(('add_principal player.%s qbcore.%s'):format(source, permission)) + QBCore.Commands.Refresh(source) + end end function QBCore.Functions.RemovePermission(source, permission) - local src = source - local license = QBCore.Functions.GetIdentifier(src, 'license') if permission then - if IsPlayerAceAllowed(src, permission) then - ExecuteCommand(('remove_principal identifier.%s qbcore.%s'):format(license, permission)) - QBCore.Commands.Refresh(src) + if IsPlayerAceAllowed(source, permission) then + ExecuteCommand(('remove_principal player.%s qbcore.%s'):format(source, permission)) + QBCore.Commands.Refresh(source) end else for _, v in pairs(QBCore.Config.Server.Permissions) do - if IsPlayerAceAllowed(src, v) then - ExecuteCommand(('remove_principal identifier.%s qbcore.%s'):format(license, v)) - QBCore.Commands.Refresh(src) + if IsPlayerAceAllowed(source, v) then + ExecuteCommand(('remove_principal player.%s qbcore.%s'):format(source, v)) + QBCore.Commands.Refresh(source) end end end @@ -335,12 +333,11 @@ end -- Checking for Permission Level function QBCore.Functions.HasPermission(source, permission) - local src = source if type(permission) == "string" then - if IsPlayerAceAllowed(src, permission) then return true end + if IsPlayerAceAllowed(source, permission) then return true end elseif type(permission) == "table" then for _, permLevel in pairs(permission) do - if IsPlayerAceAllowed(src, permLevel) then return true end + if IsPlayerAceAllowed(source, permLevel) then return true end end end