Skip to content

Commit a14260f

Browse files
authored
feat: diagnostic comments (#562)
* feat: diagnostic comments * fix(bridge/qb/server/player): return type * fix: RandomInt and RandomStr * fix(bridge/qb/server/functions): set missing param instead of diagnostic * fix(functions): HasPlayerGotGroup optional param * fix(moduke/utils): avoid redundant return value * fix(bridge/qb/shared/main): revert RandomInt and RandomStr changes * fix(server/functions): remove pcall
1 parent e1d2b17 commit a14260f

16 files changed

+60
-18
lines changed

bridge/qb/client/main.lua

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ qbCoreCompat.Shared.Jobs = GetJobs()
1111
qbCoreCompat.Shared.Gangs = GetGangs()
1212
qbCoreCompat.Functions = require 'bridge.qb.client.functions'
1313

14+
---@diagnostic disable: deprecated
15+
1416
---@deprecated use https://overextended.github.io/docs/ox_lib/Callback/Lua/Client/ instead
1517
qbCoreCompat.ClientCallbacks = {}
1618

bridge/qb/server/functions.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function functions.SpawnVehicle(source, model, coords, warp)
3737
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, true)
3838
while not DoesEntityExist(veh) do Wait(0) end
3939
if warp then
40-
while GetVehiclePedIsIn(ped) ~= veh do
40+
while GetVehiclePedIsIn(ped, false) ~= veh do
4141
Wait(0)
4242
TaskWarpPedIntoVehicle(ped, veh, -1)
4343
end
@@ -436,6 +436,7 @@ function functions.AddPlayerMethod(ids, methodName, handler)
436436
end
437437
elseif idType == 'table' and table.type(ids) == 'array' then
438438
for i = 1, #ids do
439+
---@diagnostic disable-next-line: deprecated
439440
functions.AddPlayerMethod(ids[i], methodName, handler)
440441
end
441442
end
@@ -457,15 +458,18 @@ function functions.AddPlayerField(ids, fieldName, data)
457458
if idType == 'number' then
458459
if ids == -1 then
459460
for _, v in pairs(QBX.Players) do
461+
---@diagnostic disable-next-line: undefined-field
460462
v.Functions.AddField(fieldName, data)
461463
end
462464
else
463465
if not QBX.Players[ids] then return end
464466

467+
---@diagnostic disable-next-line: undefined-field
465468
QBX.Players[ids].Functions.AddField(fieldName, data)
466469
end
467470
elseif idType == 'table' and table.type(ids) == 'array' then
468471
for i = 1, #ids do
472+
---@diagnostic disable-next-line: deprecated
469473
functions.AddPlayerField(ids[i], fieldName, data)
470474
end
471475
end
@@ -520,7 +524,7 @@ function functions.GetSource(identifier)
520524
end
521525

522526
---@param source Source|string source or identifier of the player
523-
---@return Player
527+
---@return Player?
524528
function functions.GetPlayer(source)
525529
return AddDeprecatedFunctions(exports.qbx_core:GetPlayer(source))
526530
end
@@ -687,4 +691,4 @@ function functions.GetCoreVersion(InvokingResource)
687691
return exports.qbx_core:GetCoreVersion(InvokingResource)
688692
end
689693

690-
return functions
694+
return functions

bridge/qb/server/main.lua

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require 'bridge.qb.server.events'
66
local convertItems = require 'bridge.qb.shared.compat'.convertItems
77
convertItems(require '@ox_inventory.data.items', require 'shared.items')
88

9+
---@diagnostic disable-next-line: lowercase-global
910
qbCoreCompat = {}
1011

1112
qbCoreCompat.Config = lib.table.merge(require 'config.server', require 'config.shared')
@@ -20,6 +21,8 @@ qbCoreCompat.UsableItems = QBX.UsableItems
2021
qbCoreCompat.Functions = require 'bridge.qb.server.functions'
2122
qbCoreCompat.Commands = require 'bridge.qb.server.commands'
2223

24+
---@diagnostic disable: deprecated
25+
2326
---@deprecated Call lib.print.debug() instead
2427
qbCoreCompat.Debug = lib.print.debug
2528

bridge/qb/server/player.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ end
8686
---Will cause major issues!
8787
---@param playerData PlayerData
8888
---@param Offline boolean
89-
---@return Player player
89+
---@return Player?
9090
function playerObj.CreatePlayer(playerData, Offline)
91-
AddDeprecatedFunctions(exports.qbx_core:CreatePlayer(playerData, Offline))
91+
return AddDeprecatedFunctions(exports.qbx_core:CreatePlayer(playerData, Offline))
9292
end
9393

9494
---Save player info to database (make sure citizenid is the primary key in your database)

bridge/qb/shared/main.lua

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ qbShared.StarterItems = {}
7171
if type(starterItems) == 'table' then
7272
for i = 1, #starterItems do
7373
local item = starterItems[i]
74+
75+
---@diagnostic disable-next-line: deprecated
7476
qbShared.StarterItems[item.name] = {
7577
amount = item.amount,
7678
item = item.name,
@@ -85,12 +87,16 @@ qbShared.CommaValue = lib.math.groupdigits
8587
qbShared.RandomStr = function(length)
8688
if length <= 0 then return '' end
8789
local pattern = math.random(2) == 1 and 'a' or 'A'
90+
91+
---@diagnostic disable-next-line: deprecated
8892
return qbShared.RandomStr(length - 1) .. lib.string.random(pattern)
8993
end
9094

9195
---@deprecated use lib.string.random from ox_lib
9296
qbShared.RandomInt = function(length)
9397
if length <= 0 then return '' end
98+
99+
---@diagnostic disable-next-line: deprecated
94100
return qbShared.RandomInt(length - 1) .. lib.string.random('1')
95101
end
96102

client/events.lua

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
2121
end)
2222

2323
---@param value boolean
24+
---@diagnostic disable-next-line: param-type-mismatch
2425
AddStateBagChangeHandler('PVPEnabled', nil, function(bagName, _, value)
2526
if bagName == 'global' then
2627
SetCanAttackFriendly(cache.ped, value, false)
@@ -150,6 +151,7 @@ end)
150151

151152
---@param bagName string
152153
---@param value string
154+
---@diagnostic disable-next-line: param-type-mismatch
153155
AddStateBagChangeHandler('me', nil, function(bagName, _, value)
154156
if not value then return end
155157

client/main.lua

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
QBX = {}
2+
3+
---@diagnostic disable-next-line: missing-fields
24
QBX.PlayerData = {}
35
QBX.Shared = require 'shared.main'
46
QBX.IsLoggedIn = false
@@ -37,6 +39,7 @@ function GetLocations()
3739
return QBX.Shared.Locations
3840
end
3941

42+
---@diagnostic disable-next-line: deprecated
4043
exports('GetLocations', GetLocations)
4144

4245
AddStateBagChangeHandler('isLoggedIn', ('player:%s'):format(cache.serverId), function(_, _, value)

modules/playerdata.lua

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ QBX = {} -- luacheck: ignore
44
QBX.PlayerData = exports.qbx_core:GetPlayerData() or {}
55

66
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
7+
---@diagnostic disable-next-line: missing-fields
78
QBX.PlayerData = {}
89
end)
910

modules/utils.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
---@diagnostic disable: deprecated
2+
13
lib.print.warn('This resource is still using the deprecated qbx_core utils!')
24
lib.print.warn('If you are the author, please update to use the new lib module. If you are not, please tell them to update!')
35

@@ -147,12 +149,14 @@ if isServer then
147149
model = type(model) == 'string' and joaat(model) or (model --[[@as integer]])
148150
local ped = GetPlayerPed(source)
149151

150-
return qbx.spawnVehicle({
152+
local netId, _ = qbx.spawnVehicle({
151153
model = model,
152154
spawnSource = coords or ped,
153155
warp = warp and ped or nil,
154156
props = props,
155157
})
158+
159+
return netId
156160
end
157161

158162

server/commands.lua

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ lib.addCommand('addpermission', {
6666
return
6767
end
6868

69+
---@diagnostic disable-next-line: deprecated
6970
AddPermission(player.PlayerData.source, permission)
7071
end)
7172

@@ -84,6 +85,7 @@ lib.addCommand('removepermission', {
8485
return
8586
end
8687

88+
---@diagnostic disable-next-line: deprecated
8789
RemovePermission(player.PlayerData.source, permission)
8890
end)
8991

server/events.lua

+3
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,17 @@ local function playerStateBagCheck(bagName, meta, value)
212212
end)
213213
end
214214

215+
---@diagnostic disable-next-line: param-type-mismatch
215216
AddStateBagChangeHandler('hunger', nil, function(bagName, _, value)
216217
playerStateBagCheck(bagName, 'hunger', value)
217218
end)
218219

220+
---@diagnostic disable-next-line: param-type-mismatch
219221
AddStateBagChangeHandler('thirst', nil, function(bagName, _, value)
220222
playerStateBagCheck(bagName, 'thirst', value)
221223
end)
222224

225+
---@diagnostic disable-next-line: param-type-mismatch
223226
AddStateBagChangeHandler('stress', nil, function(bagName, _, value)
224227
playerStateBagCheck(bagName, 'stress', value)
225228
end)

server/functions.lua

+17-10
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ function AddPermission(source, permission)
235235
end
236236

237237
---@deprecated use cfg ACEs instead
238+
---@diagnostic disable-next-line: deprecated
238239
exports('AddPermission', AddPermission)
239240

240241
---@deprecated use cfg ACEs instead
@@ -250,6 +251,8 @@ function RemovePermission(source, permission)
250251
end
251252
else
252253
local hasUpdated = false
254+
255+
---@diagnostic disable-next-line: deprecated
253256
for _, v in pairs(serverConfig.permissions) do
254257
if IsPlayerAceAllowed(source --[[@as string]], v) then
255258
lib.removePrincipal('player.' .. source, 'group.' .. v)
@@ -265,6 +268,7 @@ function RemovePermission(source, permission)
265268
end
266269

267270
---@deprecated use cfg ACEs instead
271+
---@diagnostic disable-next-line: deprecated
268272
exports('RemovePermission', RemovePermission)
269273

270274
-- Checking for Permission Level
@@ -285,13 +289,16 @@ function HasPermission(source, permission)
285289
end
286290

287291
---@deprecated use IsPlayerAceAllowed
292+
---@diagnostic disable-next-line: deprecated
288293
exports('HasPermission', HasPermission)
289294

290295
---@deprecated use cfg ACEs instead
291296
---@param source Source
292297
---@return table<string, boolean>
293298
function GetPermission(source)
294299
local perms = {}
300+
301+
---@diagnostic disable-next-line: deprecated
295302
for _, v in pairs (serverConfig.permissions) do
296303
if IsPlayerAceAllowed(source --[[@as string]], v) then
297304
perms[v] = true
@@ -301,6 +308,7 @@ function GetPermission(source)
301308
end
302309

303310
---@deprecated use cfg ACEs instead
311+
---@diagnostic disable-next-line: deprecated
304312
exports('GetPermission', GetPermission)
305313

306314
-- Opt in or out of admin reports
@@ -407,16 +415,15 @@ exports('GetCoreVersion', GetCoreVersion)
407415
---@param origin string reason
408416
local function ExploitBan(playerId, origin)
409417
local name = GetPlayerName(playerId)
410-
local success, errorResult = pcall(
411-
storage.insertBan({
412-
name = name,
413-
license = GetPlayerIdentifierByType(playerId --[[@as string]], 'license2') or GetPlayerIdentifierByType(playerId --[[@as string]], 'license'),
414-
discordId = GetPlayerIdentifierByType(playerId --[[@as string]], 'discord'),
415-
ip = GetPlayerIdentifierByType(playerId --[[@as string]], 'ip'),
416-
reason = origin,
417-
expiration = 2147483647,
418-
bannedBy = 'Anti Cheat'
419-
}))
418+
local success, errorResult = storage.insertBan({
419+
name = name,
420+
license = GetPlayerIdentifierByType(playerId --[[@as string]], 'license2') or GetPlayerIdentifierByType(playerId --[[@as string]], 'license'),
421+
discordId = GetPlayerIdentifierByType(playerId --[[@as string]], 'discord'),
422+
ip = GetPlayerIdentifierByType(playerId --[[@as string]], 'ip'),
423+
reason = origin,
424+
expiration = 2147483647,
425+
bannedBy = 'Anti Cheat'
426+
})
420427
if not success then lib.print.error(errorResult) end
421428
DropPlayer(playerId --[[@as string]], locale('info.exploit_banned', serverConfig.discord))
422429
logger.log({

server/main.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@ function GetLocations()
113113
return QBX.Shared.Locations
114114
end
115115

116-
exports('GetLocations', GetLocations)
116+
---@diagnostic disable-next-line: deprecated
117+
exports('GetLocations', GetLocations)

server/player.lua

+1
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ exports('RemovePlayerFromGang', removePlayerFromGang)
419419
---@return Player player
420420
function CheckPlayerData(source, playerData)
421421
playerData = playerData or {}
422+
---@diagnostic disable-next-line: param-type-mismatch
422423
local playerState = Player(source)?.state
423424
local Offline = true
424425
if source then

shared/functions.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
---@param filter string | string[] | table<string, number>
2626
---@param playerData table
27-
---@param primary boolean Check only for primary job/gang
27+
---@param primary? boolean Check only for primary job/gang
2828
---@return boolean
2929
function HasPlayerGotGroup(filter, playerData, primary)
3030
local groups = not primary and GetPlayerGroups(playerData)

types.lua

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---@meta
22

3+
---@alias NotificationPosition 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' | 'center-right' | 'center-left'
4+
---@alias NotificationType 'info' | 'warning' | 'success' | 'error'
5+
36
---@class ErrorResult
47
---@field code string
58
---@field message string

0 commit comments

Comments
 (0)