Skip to content

Commit 66d9435

Browse files
committed
Editor command
1 parent 6cd10e6 commit 66d9435

File tree

2 files changed

+56
-36
lines changed

2 files changed

+56
-36
lines changed

server/editor.lua

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
RegisterCommand('qbeditor', function(source)
2+
local files = {
3+
config = LoadResourceFile('qb-core', 'shared/json/config.json'),
4+
gangs = LoadResourceFile('qb-core', 'shared/json/gangs.json'),
5+
items = LoadResourceFile('qb-core', 'shared/json/items.json'),
6+
jobs = LoadResourceFile('qb-core', 'shared/json/jobs.json'),
7+
playerdata = LoadResourceFile('qb-core', 'shared/json/player_defaults.json'),
8+
vehicles = LoadResourceFile('qb-core', 'shared/json/vehicles.json'),
9+
weapons = LoadResourceFile('qb-core', 'shared/json/weapons.json'),
10+
}
11+
12+
local allData = {}
13+
for key, fileContent in pairs(files) do
14+
if not fileContent then
15+
print('^1[QBCore] Failed to load ' .. key .. ' JSON File')
16+
else
17+
allData[key] = json.decode(fileContent)
18+
end
19+
end
20+
21+
TriggerClientEvent('qb-core:client:configEditor', source, allData)
22+
end, true)
23+
24+
RegisterNetEvent('qb-core:server:configEditor', function(fileName, fileData)
25+
local src = source
26+
local Player = QBCore.Functions.GetPlayer(src)
27+
if not Player then return end
28+
if not QBCore.Functions.HasPermission('god') then
29+
local filePaths = {
30+
['config'] = 'shared/json/config.json',
31+
['gangs'] = 'shared/json/gangs.json',
32+
['items'] = 'shared/json/items.json',
33+
['jobs'] = 'shared/json/jobs.json',
34+
['playerdata'] = 'shared/json/player_defaults.json',
35+
['vehicles'] = 'shared/json/vehicles.json',
36+
['weapons'] = 'shared/json/weapons.json'
37+
}
38+
local filePath = filePaths[fileName]
39+
if not filePath then
40+
print('^1[QBCore] Invalid file name: ' .. fileName)
41+
return
42+
end
43+
local encodedData = json.encode(fileData, { indent = true })
44+
local saved = SaveResourceFile('qb-core', filePath, encodedData, -1)
45+
if saved then
46+
print('^2[QBCore] Player ' .. GetPlayerName(src) .. ' (ID: ' .. src .. ') successfully saved ' .. fileName .. ' configuration')
47+
TriggerClientEvent('QBCore:Notify', src, 'Configuration saved successfully', 'success')
48+
else
49+
print('^1[QBCore] Failed to save ' .. fileName .. ' configuration')
50+
TriggerClientEvent('QBCore:Notify', src, 'Failed to save configuration', 'error')
51+
end
52+
else
53+
print('^1[QBCore] Player ' .. GetPlayerName(src) .. ' (ID: ' .. src .. ') attempted to save ' .. fileName .. ' configuration without permission')
54+
TriggerClientEvent('QBCore:Notify', src, 'You don\'t have permission to edit configs', 'error')
55+
end
56+
end)

server/main.lua

-36
Original file line numberDiff line numberDiff line change
@@ -72,39 +72,3 @@ AddEventHandler('playerDropped', function(reason)
7272
end
7373
QBCore.Player_Buckets[license] = nil
7474
end)
75-
76-
-- Config Editor
77-
78-
RegisterNetEvent('qb-core:server:configEditor', function(fileName, fileData)
79-
local src = source
80-
local Player = QBCore.Functions.GetPlayer(src)
81-
if not Player then return end
82-
if not QBCore.Functions.HasPermission('god') then
83-
local filePaths = {
84-
['config'] = 'shared/json/config.json',
85-
['gangs'] = 'shared/json/gangs.json',
86-
['items'] = 'shared/json/items.json',
87-
['jobs'] = 'shared/json/jobs.json',
88-
['playerdata'] = 'shared/json/player_defaults.json',
89-
['vehicles'] = 'shared/json/vehicles.json',
90-
['weapons'] = 'shared/json/weapons.json'
91-
}
92-
local filePath = filePaths[fileName]
93-
if not filePath then
94-
print('^1[QBCore] Invalid file name: ' .. fileName)
95-
return
96-
end
97-
local encodedData = json.encode(fileData, { indent = true })
98-
local saved = SaveResourceFile('qb-core', filePath, encodedData, -1)
99-
if saved then
100-
print('^2[QBCore] Player ' .. GetPlayerName(src) .. ' (ID: ' .. src .. ') successfully saved ' .. fileName .. ' configuration')
101-
TriggerClientEvent('QBCore:Notify', src, 'Configuration saved successfully', 'success')
102-
else
103-
print('^1[QBCore] Failed to save ' .. fileName .. ' configuration')
104-
TriggerClientEvent('QBCore:Notify', src, 'Failed to save configuration', 'error')
105-
end
106-
else
107-
print('^1[QBCore] Player ' .. GetPlayerName(src) .. ' (ID: ' .. src .. ') attempted to save ' .. fileName .. ' configuration without permission')
108-
TriggerClientEvent('QBCore:Notify', src, 'You don\'t have permission to edit configs', 'error')
109-
end
110-
end)

0 commit comments

Comments
 (0)