Skip to content

Commit

Permalink
refactor: use native ace perms
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon authored Feb 21, 2024
1 parent 550b22f commit ee248c5
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ local generalOptions = {
end,
}
RegisterNetEvent('qbx_admin:server:playerOptionsGeneral', function(selected, selectedPlayer, input)
if not exports.qbx_core:HasPermission(source, config.eventPerms.playerOptionsGeneral) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.playerOptionsGeneral) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end

---@diagnostic disable-next-line: redundant-parameter
generalOptions[selected](selectedPlayer, source, input)
end)

local administrationOptions = {
function(source, selectedPlayer, input)
if not exports.qbx_core:HasPermission(source, config.eventPerms.kick) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.kick) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
DropPlayer(selectedPlayer.id, input)
end,
function(source, selectedPlayer, input)
if not exports.qbx_core:HasPermission(source, config.eventPerms.ban) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.ban) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
local banDuration = (input[2] or 0) * 3600 + (input[3] or 0) * 86400 + (input[4] or 0) * 2629743
DropPlayer(selectedPlayer.id, locale('player_options.administration.banreason', input[1], os.date('%c', os.time() + banDuration)))
MySQL.Async.insert('INSERT INTO bans (name, license, discord, ip, reason, expire, bannedby) VALUES (?, ?, ?, ?, ?, ?, ?)', {
Expand All @@ -67,7 +67,7 @@ local administrationOptions = {
})
end,
function(source, selectedPlayer, input)
if not exports.qbx_core:HasPermission(source, config.eventPerms.changePerms) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.changePerms) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if input == 'remove' then exports.qbx_core:RemovePermission(selectedPlayer.id) else exports.qbx_core:AddPermission(selectedPlayer.id, input) end
end,
}
Expand Down Expand Up @@ -112,7 +112,7 @@ local playerDataOptions = {
RegisterNetEvent('qbx_admin:server:changePlayerData', function(selected, selectedPlayer, input)
local target = exports.qbx_core:GetPlayer(selectedPlayer.id)

if not exports.qbx_core:HasPermission(source, config.eventPerms.changePlayerData) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.changePlayerData) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not target then return end

playerDataOptions[selected](target, input)
Expand All @@ -122,7 +122,7 @@ RegisterNetEvent('qbx_admin:server:giveAllWeapons', function(weaponType, playerI
local src = playerID or source
local target = exports.qbx_core:GetPlayer(src)

if not exports.qbx_core:HasPermission(source, config.eventPerms.giveAllWeapons) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.giveAllWeapons) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end

for i = 1, #config.weaponList[weaponType], 1 do
if not exports.ox_inventory:Items()[config.weaponList[weaponType][i]] then return end
Expand All @@ -134,7 +134,7 @@ lib.callback.register('qbx_admin:callback:getradiolist', function(source, freque
local list = exports['pma-voice']:getPlayersInRadioChannel(tonumber(frequency))
local players = {}

if not exports.qbx_core:HasPermission(source, config.eventPerms.getRadioList) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.getRadioList) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end

for targetSource, _ in pairs(list) do -- cheers Knight who shall not be named
local player = exports.qbx_core:GetPlayer(targetSource)
Expand All @@ -147,7 +147,7 @@ lib.callback.register('qbx_admin:callback:getradiolist', function(source, freque
end)

lib.callback.register('qbx_admin:server:getPlayers', function(source)
if not exports.qbx_core:HasPermission(source, config.eventPerms.useMenu) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.useMenu) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end

local players = {}
for k, v in pairs(exports.qbx_core:GetQBPlayers()) do
Expand Down Expand Up @@ -176,7 +176,7 @@ lib.callback.register('qbx_admin:server:getPlayers', function(source)
end)

lib.callback.register('qbx_admin:server:getPlayer', function(source, playerToGet)
if not exports.qbx_core:HasPermission(source, config.eventPerms.useMenu) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not IsPlayerAceAllowed(source, config.eventPerms.useMenu) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end

local playerData = exports.qbx_core:GetPlayer(playerToGet).PlayerData
local player = {
Expand All @@ -202,7 +202,7 @@ lib.callback.register('qbx_admin:server:getPlayer', function(source, playerToGet
end)

lib.callback.register('qbx_admin:server:clothingMenu', function(source, target)
if not exports.qbx_core:HasPermission(source, config.eventPerms.clothingMenu) then
if not IsPlayerAceAllowed(source, config.eventPerms.clothingMenu) then
exports.qbx_core:Notify(source, locale('error.no_perms'), 'error')
return false
end
Expand All @@ -213,7 +213,7 @@ lib.callback.register('qbx_admin:server:clothingMenu', function(source, target)
end)

lib.callback.register('qbx_admin:server:canUseMenu', function(source)
if not exports.qbx_core:HasPermission(source, config.eventPerms.useMenu) then
if not IsPlayerAceAllowed(source, config.eventPerms.useMenu) then
exports.qbx_core:Notify(source, locale('error.no_perms'), 'error')
return false
end
Expand All @@ -224,4 +224,4 @@ end)
lib.callback.register('qbx_admin:server:spawnVehicle', function(source, model)
local hash = joaat(model)
return SpawnVehicle(source, hash, nil, true)
end)
end)

0 comments on commit ee248c5

Please sign in to comment.