mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-28 17:01:14 +00:00
feat(commands): centralize admin permissions via Config.AdminGroups
This commit is contained in:
@@ -1,6 +1,22 @@
|
||||
local adminGroups = {}
|
||||
if Config.AdminGroups then
|
||||
for groupName, enabled in pairs(Config.AdminGroups) do
|
||||
if enabled then
|
||||
adminGroups[#adminGroups + 1] = groupName
|
||||
end
|
||||
end
|
||||
else
|
||||
adminGroups = { "admin" }
|
||||
end
|
||||
|
||||
local userAndAdminGroups = { "user" }
|
||||
for _, v in ipairs(adminGroups) do
|
||||
userAndAdminGroups[#userAndAdminGroups + 1] = v
|
||||
end
|
||||
|
||||
ESX.RegisterCommand(
|
||||
{ "setcoords", "tp" },
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
xPlayer.setCoords({ x = args.x, y = args.y, z = args.z })
|
||||
if Config.AdminLogging then
|
||||
@@ -27,7 +43,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"setjob",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
if not ESX.DoesJobExist(args.job, args.grade) then
|
||||
return showError(TranslateCap("command_setjob_invalid"))
|
||||
@@ -68,7 +84,7 @@ local upgrades = Config.SpawnVehMaxUpgrades and {
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"car",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
if not xPlayer then
|
||||
return showError("[^1ERROR^7] The xPlayer value is nil")
|
||||
@@ -132,7 +148,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
{ "cardel", "dv" },
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
local ped = GetPlayerPed(xPlayer.source)
|
||||
local pedVehicle = GetVehiclePedIsIn(ped, false)
|
||||
@@ -168,7 +184,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
{ "fix", "repair" },
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
local xTarget = args.playerId
|
||||
local ped = GetPlayerPed(xTarget.source)
|
||||
@@ -202,7 +218,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"setaccountmoney",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
if not args.playerId.getAccount(args.account) then
|
||||
return showError(TranslateCap("command_giveaccountmoney_invalid"))
|
||||
@@ -232,7 +248,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"giveaccountmoney",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
if not args.playerId.getAccount(args.account) then
|
||||
return showError(TranslateCap("command_giveaccountmoney_invalid"))
|
||||
@@ -262,7 +278,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"removeaccountmoney",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
if not args.playerId.getAccount(args.account) then
|
||||
return showError(TranslateCap("command_removeaccountmoney_invalid"))
|
||||
@@ -293,7 +309,7 @@ ESX.RegisterCommand(
|
||||
if not Config.CustomInventory then
|
||||
ESX.RegisterCommand(
|
||||
"giveitem",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
args.playerId.addInventoryItem(args.item, args.count)
|
||||
if Config.AdminLogging then
|
||||
@@ -323,7 +339,7 @@ if not Config.CustomInventory then
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"giveweapon",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
if args.playerId.hasWeapon(args.weapon) then
|
||||
return showError(TranslateCap("command_giveweapon_hasalready"))
|
||||
@@ -353,7 +369,7 @@ if not Config.CustomInventory then
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"giveammo",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
if not args.playerId.hasWeapon(args.weapon) then
|
||||
return showError(TranslateCap("command_giveammo_noweapon_found"))
|
||||
@@ -383,7 +399,7 @@ if not Config.CustomInventory then
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"giveweaponcomponent",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args, showError)
|
||||
if args.playerId.hasWeapon(args.weaponName) then
|
||||
local component = ESX.GetWeaponComponent(args.weaponName, args.componentName)
|
||||
@@ -427,7 +443,7 @@ ESX.RegisterCommand({ "clear", "cls" }, "user", function(xPlayer)
|
||||
xPlayer.triggerEvent("chat:clear")
|
||||
end, false, { help = TranslateCap("command_clear") })
|
||||
|
||||
ESX.RegisterCommand({ "clearall", "clsall" }, "admin", function(xPlayer)
|
||||
ESX.RegisterCommand({ "clearall", "clsall" }, adminGroups, function(xPlayer)
|
||||
TriggerClientEvent("chat:clear", -1)
|
||||
if Config.AdminLogging then
|
||||
ESX.DiscordLogFields("UserActions", "Clear Chat /clearall Triggered!", "pink", {
|
||||
@@ -437,12 +453,12 @@ ESX.RegisterCommand({ "clearall", "clsall" }, "admin", function(xPlayer)
|
||||
end
|
||||
end, true, { help = TranslateCap("command_clearall") })
|
||||
|
||||
ESX.RegisterCommand("refreshjobs", "admin", function()
|
||||
ESX.RegisterCommand("refreshjobs", adminGroups, function()
|
||||
ESX.RefreshJobs()
|
||||
end, true, { help = TranslateCap("command_clearall") })
|
||||
|
||||
if not Config.CustomInventory then
|
||||
ESX.RegisterCommand("refreshitems", "admin", function(xPlayer)
|
||||
ESX.RegisterCommand("refreshitems", adminGroups, function(xPlayer)
|
||||
local itemCount = ESX.RefreshItems()
|
||||
|
||||
xPlayer.showNotification(Translate("command_refreshitems_success", itemCount), true, false, 140)
|
||||
@@ -450,7 +466,7 @@ if not Config.CustomInventory then
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"clearinventory",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
for _, v in ipairs(args.playerId.inventory) do
|
||||
if v.count > 0 then
|
||||
@@ -478,7 +494,7 @@ if not Config.CustomInventory then
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"clearloadout",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
for i = #args.playerId.loadout, 1, -1 do
|
||||
args.playerId.removeWeapon(args.playerId.loadout[i].name)
|
||||
@@ -505,7 +521,7 @@ end
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"setgroup",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
if not args.playerId then
|
||||
args.playerId = xPlayer.source
|
||||
@@ -537,7 +553,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"save",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(_, args)
|
||||
Core.SavePlayer(args.playerId)
|
||||
print(("[^2Info^0] Saved Player - ^5%s^0"):format(args.playerId.source))
|
||||
@@ -552,26 +568,26 @@ ESX.RegisterCommand(
|
||||
}
|
||||
)
|
||||
|
||||
ESX.RegisterCommand("saveall", "admin", function()
|
||||
ESX.RegisterCommand("saveall", adminGroups, function()
|
||||
Core.SavePlayers()
|
||||
end, true, { help = TranslateCap("command_saveall") })
|
||||
|
||||
ESX.RegisterCommand("group", { "user", "admin" }, function(xPlayer, _, _)
|
||||
ESX.RegisterCommand("group", userAndAdminGroups, function(xPlayer, _, _)
|
||||
print(("%s, you are currently: ^5%s^0"):format(xPlayer.getName(), xPlayer.getGroup()))
|
||||
end, true)
|
||||
|
||||
ESX.RegisterCommand("job", { "user", "admin" }, function(xPlayer, _, _)
|
||||
ESX.RegisterCommand("job", userAndAdminGroups, function(xPlayer, _, _)
|
||||
local job = xPlayer.getJob()
|
||||
|
||||
print(("%s, your job is: ^5%s^0 - ^5%s^0 - ^5%s^0"):format(xPlayer.getName(), job.name, job.grade_label, job.onDuty and "On Duty" or "Off Duty"))
|
||||
end, false)
|
||||
|
||||
ESX.RegisterCommand("info", { "user", "admin" }, function(xPlayer)
|
||||
ESX.RegisterCommand("info", userAndAdminGroups, function(xPlayer)
|
||||
local job = xPlayer.getJob().name
|
||||
print(("^2ID: ^5%s^0 | ^2Name: ^5%s^0 | ^2Group: ^5%s^0 | ^2Job: ^5%s^0"):format(xPlayer.source, xPlayer.getName(), xPlayer.getGroup(), job))
|
||||
end, false)
|
||||
|
||||
ESX.RegisterCommand("playtime", { "user", "admin" }, function(xPlayer)
|
||||
ESX.RegisterCommand("playtime", userAndAdminGroups, function(xPlayer)
|
||||
local playtime = xPlayer.getPlayTime()
|
||||
local days = math.floor(playtime / 86400)
|
||||
local hours = math.floor((playtime % 86400) / 3600)
|
||||
@@ -579,7 +595,7 @@ ESX.RegisterCommand("playtime", { "user", "admin" }, function(xPlayer)
|
||||
print(("Playtime: ^5%s^0 Days | ^5%s^0 Hours | ^5%s^0 Minutes"):format(days, hours, minutes))
|
||||
end, false)
|
||||
|
||||
ESX.RegisterCommand("coords", "admin", function(xPlayer)
|
||||
ESX.RegisterCommand("coords", adminGroups, function(xPlayer)
|
||||
local ped = GetPlayerPed(xPlayer.source)
|
||||
local coords = GetEntityCoords(ped, false)
|
||||
local heading = GetEntityHeading(ped)
|
||||
@@ -587,7 +603,7 @@ ESX.RegisterCommand("coords", "admin", function(xPlayer)
|
||||
print(("Coords - Vector4: ^5%s^0"):format(vector4(coords.x, coords.y, coords.z, heading)))
|
||||
end, false)
|
||||
|
||||
ESX.RegisterCommand("tpm", "admin", function(xPlayer)
|
||||
ESX.RegisterCommand("tpm", adminGroups, function(xPlayer)
|
||||
xPlayer.triggerEvent("esx:tpm")
|
||||
if Config.AdminLogging then
|
||||
ESX.DiscordLogFields("UserActions", "Admin Teleport /tpm Triggered!", "pink", {
|
||||
@@ -599,7 +615,7 @@ end, false)
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"goto",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
local targetCoords = args.playerId.getCoords()
|
||||
local srcDim = GetPlayerRoutingBucket(xPlayer.source)
|
||||
@@ -630,7 +646,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"bring",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
local targetCoords = args.playerId.getCoords()
|
||||
local playerCoords = xPlayer.getCoords()
|
||||
@@ -662,7 +678,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"kill",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
args.playerId.triggerEvent("esx:killPlayer")
|
||||
if Config.AdminLogging then
|
||||
@@ -685,7 +701,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"freeze",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
args.playerId.triggerEvent("esx:freezePlayer", "freeze")
|
||||
if Config.AdminLogging then
|
||||
@@ -708,7 +724,7 @@ ESX.RegisterCommand(
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"unfreeze",
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
args.playerId.triggerEvent("esx:freezePlayer", "unfreeze")
|
||||
if Config.AdminLogging then
|
||||
@@ -729,7 +745,7 @@ ESX.RegisterCommand(
|
||||
}
|
||||
)
|
||||
|
||||
ESX.RegisterCommand("noclip", "admin", function(xPlayer)
|
||||
ESX.RegisterCommand("noclip", adminGroups, function(xPlayer)
|
||||
xPlayer.triggerEvent("esx:noclip")
|
||||
if Config.AdminLogging then
|
||||
ESX.DiscordLogFields("UserActions", "Admin NoClip /noclip Triggered!", "pink", {
|
||||
@@ -739,7 +755,7 @@ ESX.RegisterCommand("noclip", "admin", function(xPlayer)
|
||||
end
|
||||
end, false)
|
||||
|
||||
ESX.RegisterCommand("players", "admin", function()
|
||||
ESX.RegisterCommand("players", adminGroups, function()
|
||||
local xPlayers = ESX.GetExtendedPlayers() -- Returns all xPlayers
|
||||
print(("^5%s^2 online player(s)^0"):format(#xPlayers))
|
||||
for i = 1, #xPlayers do
|
||||
@@ -750,7 +766,7 @@ end, true)
|
||||
|
||||
ESX.RegisterCommand(
|
||||
{"setdim", "setbucket"},
|
||||
"admin",
|
||||
adminGroups,
|
||||
function(xPlayer, args)
|
||||
SetPlayerRoutingBucket(args.playerId.source, args.dimension)
|
||||
if Config.AdminLogging then
|
||||
|
||||
Reference in New Issue
Block a user