From 15e37a0c34dc9c3c836146be633945c2be7268cb Mon Sep 17 00:00:00 2001 From: Ethan Johnson <37124195+Asaayu@users.noreply.github.com> Date: Mon, 15 Aug 2022 18:37:32 +1200 Subject: [PATCH] Performance, notification, and localization updates to `server/commands.lua` (#638) * :racehorse: Update ace permissions loop from pairs() to for-i * Add success notification to `openserver` and `closeserver` * :globe_with_meridians: Add missing localization strings for commands * Add missing comma at end of line Co-authored-by: Kakarot <57848836+GhzGarage@users.noreply.github.com> Co-authored-by: BerkieBb <82737367+BerkieBb@users.noreply.github.com> --- locale/en.lua | 9 +++++++-- server/commands.lua | 12 ++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/locale/en.lua b/locale/en.lua index 202d41b..57b8f02 100644 --- a/locale/en.lua +++ b/locale/en.lua @@ -10,9 +10,14 @@ local Translations = { too_heavy = 'Inventory too full', duplicate_license = 'Duplicate Rockstar License Found', no_valid_license = 'No Valid Rockstar License Found', - not_whitelisted = 'You\'re not whitelisted for this server' + not_whitelisted = 'You\'re not whitelisted for this server', + server_already_open = 'The server is already open', + server_already_closed = 'The server is already closed' + }, + success = { + server_opened = 'The server has been opened', + server_closed = 'The server has been closed' }, - success = {}, info = { received_paycheck = 'You received your paycheck of $%{value}', job_info = 'Job: %{value} | Grade: %{value2} | Duty: %{value3}', diff --git a/server/commands.lua b/server/commands.lua index 99ef0f0..a85acff 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -6,8 +6,10 @@ QBCore.Commands.IgnoreList = { -- Ignore old perm levels while keeping backwards } CreateThread(function() -- Add ace to node for perm checking - for _, v in pairs(QBConfig.Server.Permissions) do - ExecuteCommand(('add_ace qbcore.%s %s allow'):format(v, v)) + local permissions = QBConfig.Server.Permissions + for i=1, #permissions do + local permission = permissions[i] + ExecuteCommand(('add_ace qbcore.%s %s allow'):format(permission, permission)) end end) @@ -140,11 +142,12 @@ end, 'god') QBCore.Commands.Add('openserver', 'Open the server for everyone (Admin Only)', {}, false, function(source) if not QBCore.Config.Server.Closed then - TriggerClientEvent('QBCore:Notify', source, 'The server is already open', 'error') + TriggerClientEvent('QBCore:Notify', source, Lang:t('error.server_already_open'), 'error') return end if QBCore.Functions.HasPermission(source, 'admin') then QBCore.Config.Server.Closed = false + TriggerClientEvent('QBCore:Notify', source, Lang:t('success.server_opened'), 'success') else QBCore.Functions.Kick(source, 'You don\'t have permissions for this..', nil, nil) end @@ -152,7 +155,7 @@ end, 'admin') QBCore.Commands.Add('closeserver', 'Close the server for people without permissions (Admin Only)', { { name = 'reason', help = 'Reason for closing it (optional)' } }, false, function(source, args) if QBCore.Config.Server.Closed then - TriggerClientEvent('QBCore:Notify', source, 'The server is already closed', 'error') + TriggerClientEvent('QBCore:Notify', source, Lang:t('error.server_already_closed'), 'error') return end if QBCore.Functions.HasPermission(source, 'admin') then @@ -164,6 +167,7 @@ QBCore.Commands.Add('closeserver', 'Close the server for people without permissi QBCore.Functions.Kick(k, reason, nil, nil) end end + TriggerClientEvent('QBCore:Notify', source, Lang:t('success.server_closed'), 'success') else QBCore.Functions.Kick(source, 'You don\'t have permissions for this..', nil, nil) end