|
| 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) |
0 commit comments