Refactor: Metadata. meta to metadata

This commit is contained in:
P Gergő
2023-03-12 18:32:56 +01:00
parent fc687084eb
commit a00183deba
5 changed files with 32 additions and 32 deletions
+1 -1
View File
@@ -389,7 +389,7 @@ CREATE TABLE `users` (
`job` varchar(20) DEFAULT 'unemployed', `job` varchar(20) DEFAULT 'unemployed',
`job_grade` int(11) DEFAULT 0, `job_grade` int(11) DEFAULT 0,
`loadout` longtext DEFAULT NULL, `loadout` longtext DEFAULT NULL,
`meta` LONGTEXT NULL DEFAULT NULL, `metadata` LONGTEXT NULL DEFAULT NULL,
`position` longtext NULL DEFAULT NULL, `position` longtext NULL DEFAULT NULL,
`firstname` varchar(16) DEFAULT NULL, `firstname` varchar(16) DEFAULT NULL,
`lastname` varchar(16) DEFAULT NULL, `lastname` varchar(16) DEFAULT NULL,
+1 -1
View File
@@ -15,7 +15,7 @@ CREATE TABLE `users` (
`job` VARCHAR(20) NULL DEFAULT 'unemployed', `job` VARCHAR(20) NULL DEFAULT 'unemployed',
`job_grade` INT NULL DEFAULT 0, `job_grade` INT NULL DEFAULT 0,
`loadout` LONGTEXT NULL DEFAULT NULL, `loadout` LONGTEXT NULL DEFAULT NULL,
`meta` LONGTEXT NULL DEFAULT NULL, `metadata` LONGTEXT NULL DEFAULT NULL,
`position` longtext NULL DEFAULT NULL, `position` longtext NULL DEFAULT NULL,
PRIMARY KEY (`identifier`) PRIMARY KEY (`identifier`)
+19 -19
View File
@@ -4,7 +4,7 @@ local DoesEntityExist = DoesEntityExist
local GetEntityCoords = GetEntityCoords local GetEntityCoords = GetEntityCoords
local GetEntityHeading = GetEntityHeading local GetEntityHeading = GetEntityHeading
function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, weight, job, loadout, name, coords, meta) function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, weight, job, loadout, name, coords, metadata)
local targetOverrides = Config.PlayerFunctionOverride and Core.PlayerFunctionOverrides[Config.PlayerFunctionOverride] or {} local targetOverrides = Config.PlayerFunctionOverride and Core.PlayerFunctionOverrides[Config.PlayerFunctionOverride] or {}
local self = {} local self = {}
@@ -22,7 +22,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
self.variables = {} self.variables = {}
self.weight = weight self.weight = weight
self.maxWeight = Config.MaxWeight self.maxWeight = Config.MaxWeight
self.meta = meta self.metadata = metadata
if Config.Multichar then self.license = 'license'.. identifier:sub(identifier:find(':'), identifier:len()) else self.license = 'license:'..identifier end if Config.Multichar then self.license = 'license'.. identifier:sub(identifier:find(':'), identifier:len()) else self.license = 'license:'..identifier end
ExecuteCommand(('add_principal identifier.%s group.%s'):format(self.license, self.group)) ExecuteCommand(('add_principal identifier.%s group.%s'):format(self.license, self.group))
@@ -33,7 +33,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
stateBag:set("job", self.job, true) stateBag:set("job", self.job, true)
stateBag:set("group", self.group, true) stateBag:set("group", self.group, true)
stateBag:set("name", self.name, true) stateBag:set("name", self.name, true)
stateBag:set("meta", self.meta, true) stateBag:set("metadata", self.metadata, true)
function self.triggerEvent(eventName, ...) function self.triggerEvent(eventName, ...)
TriggerClientEvent(eventName, self.source, ...) TriggerClientEvent(eventName, self.source, ...)
@@ -586,14 +586,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
return print("[^1ERROR^7] xPlayer.getMeta ^5index^7 should be ^5string^7!") return print("[^1ERROR^7] xPlayer.getMeta ^5index^7 should be ^5string^7!")
end end
if self.meta[index] then if self.metadata[index] then
if subIndex and type(self.meta[index]) == "table" then if subIndex and type(self.metadata[index]) == "table" then
local _type = type(subIndex) local _type = type(subIndex)
if _type == "string" then if _type == "string" then
if self.meta[index][subIndex] then if self.metadata[index][subIndex] then
return self.meta[index][subIndex] return self.metadata[index][subIndex]
end end
return print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not esxist on ^5%s^7!"):format(subIndex, index)) return print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not esxist on ^5%s^7!"):format(subIndex, index))
@@ -602,8 +602,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
if _type == "table" then if _type == "table" then
local returnValues = {} local returnValues = {}
for i = 1, #subIndex do for i = 1, #subIndex do
if self.meta[index][subIndex[i]] then if self.metadata[index][subIndex[i]] then
returnValues[subIndex[i]] = self.meta[index][subIndex[i]] returnValues[subIndex[i]] = self.metadata[index][subIndex[i]]
else else
print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not esxist on ^5%s^7!"):format(subIndex[i], index)) print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not esxist on ^5%s^7!"):format(subIndex[i], index))
end end
@@ -614,14 +614,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end end
return self.meta[index] return self.metadata[index]
else else
return print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not exist!"):format(index)) return print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not exist!"):format(index))
end end
end end
return self.meta return self.metadata
end end
function self.setMeta(index, value, subValue) function self.setMeta(index, value, subValue)
@@ -645,19 +645,19 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
return print(("[^1ERROR^7] xPlayer.setMeta ^5%s^7 should be ^5number^7 or ^5string^7 or ^5table^7!"):format(value)) return print(("[^1ERROR^7] xPlayer.setMeta ^5%s^7 should be ^5number^7 or ^5string^7 or ^5table^7!"):format(value))
end end
self.meta[index] = value self.metadata[index] = value
else else
if _type ~= "string" then if _type ~= "string" then
return print(("[^1ERROR^7] xPlayer.setMeta ^5value^7 should be ^5string^7 as a subIndex!"):format(value)) return print(("[^1ERROR^7] xPlayer.setMeta ^5value^7 should be ^5string^7 as a subIndex!"):format(value))
end end
self.meta[index][value] = subValue self.metadata[index][value] = subValue
end end
self.triggerEvent('esx:updatePlayerData', 'meta', self.meta) self.triggerEvent('esx:updatePlayerData', 'metadata', self.metadata)
Player(self.source).state:set('meta', self.meta, true) Player(self.source).state:set('metadata', self.metadata, true)
end end
function self.clearMeta(index) function self.clearMeta(index)
@@ -673,13 +673,13 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
return return
end end
if not self.meta[index] then if not self.metadata[index] then
return print(("[^1ERROR^7] xPlayer.clearMeta ^5%s^7 not exist!"):format(index)) return print(("[^1ERROR^7] xPlayer.clearMeta ^5%s^7 not exist!"):format(index))
end end
self.meta[index] = nil self.metadata[index] = nil
self.triggerEvent('esx:updatePlayerData', 'meta', self.meta) self.triggerEvent('esx:updatePlayerData', 'metadata', self.metadata)
Player(self.source).state:set('meta', self.meta, true) Player(self.source).state:set('metadata', self.metadata, true)
end end
for fnName,fn in pairs(targetOverrides) do for fnName,fn in pairs(targetOverrides) do
+2 -2
View File
@@ -157,7 +157,7 @@ function Core.SavePlayer(xPlayer, cb)
} }
MySQL.prepare( MySQL.prepare(
'UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ?, `meta` = ? WHERE `identifier` = ?', 'UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ?, `metadata` = ? WHERE `identifier` = ?',
parameters, parameters,
function(affectedRows) function(affectedRows)
if affectedRows == 1 then if affectedRows == 1 then
@@ -195,7 +195,7 @@ function Core.SavePlayers(cb)
end end
MySQL.prepare( MySQL.prepare(
"UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ?, `meta` = ? WHERE `identifier` = ?", "UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ?, `metadata` = ? WHERE `identifier` = ?",
parameters, parameters,
function(results) function(results)
if not results then if not results then
+9 -9
View File
@@ -3,7 +3,7 @@ SetGameType('ESX Legacy')
local oneSyncState = GetConvar('onesync', 'off') local oneSyncState = GetConvar('onesync', 'off')
local newPlayer = 'INSERT INTO `users` SET `accounts` = ?, `identifier` = ?, `group` = ?' local newPlayer = 'INSERT INTO `users` SET `accounts` = ?, `identifier` = ?, `group` = ?'
local loadPlayer = 'SELECT `accounts`, `job`, `job_grade`, `group`, `position`, `inventory`, `skin`, `loadout`, `meta`' local loadPlayer = 'SELECT `accounts`, `job`, `job_grade`, `group`, `position`, `inventory`, `skin`, `loadout`, `metadata`'
if Config.Multichar then if Config.Multichar then
newPlayer = newPlayer .. ', `firstname` = ?, `lastname` = ?, `dateofbirth` = ?, `sex` = ?, `height` = ?' newPlayer = newPlayer .. ', `firstname` = ?, `lastname` = ?, `dateofbirth` = ?, `sex` = ?, `height` = ?'
@@ -121,7 +121,7 @@ if not Config.Multichar then
end end
function loadESXPlayer(identifier, playerId, isNew) function loadESXPlayer(identifier, playerId, isNew)
local userData = {accounts = {}, inventory = {}, job = {}, loadout = {}, playerName = GetPlayerName(playerId), weight = 0, meta = {}} local userData = {accounts = {}, inventory = {}, job = {}, loadout = {}, playerName = GetPlayerName(playerId), weight = 0, metadata = {}}
local result = MySQL.prepare.await(loadPlayer, {identifier}) local result = MySQL.prepare.await(loadPlayer, {identifier})
local job, grade, jobObject, gradeObject = result.job, tostring(result.job_grade) local job, grade, jobObject, gradeObject = result.job, tostring(result.job_grade)
local foundAccounts, foundItems = {}, {} local foundAccounts, foundItems = {}, {}
@@ -280,13 +280,13 @@ function loadESXPlayer(identifier, playerId, isNew)
end end
end end
if result.meta and result.meta ~= '' then if result.metadata and result.metadata ~= '' then
local meta = json.decode(result.meta) local metadata = json.decode(result.metadata)
userData.meta = meta userData.metadata = metadata
end end
local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job,
userData.loadout, userData.playerName, userData.coords, userData.meta) userData.loadout, userData.playerName, userData.coords, userData.metadata)
ESX.Players[playerId] = xPlayer ESX.Players[playerId] = xPlayer
Core.playersByIdentifier[identifier] = xPlayer Core.playersByIdentifier[identifier] = xPlayer
@@ -322,7 +322,7 @@ function loadESXPlayer(identifier, playerId, isNew)
dateofbirth = xPlayer.get("dateofbirth") or "01/01/2000", dateofbirth = xPlayer.get("dateofbirth") or "01/01/2000",
height = xPlayer.get("height") or 120, height = xPlayer.get("height") or 120,
dead = false, dead = false,
meta = xPlayer.getMeta() metadata = xPlayer.getMeta()
}, isNew, }, isNew,
userData.skin) userData.skin)
@@ -594,7 +594,7 @@ ESX.RegisterServerCallback('esx:getPlayerData', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source) local xPlayer = ESX.GetPlayerFromId(source)
cb({identifier = xPlayer.identifier, accounts = xPlayer.getAccounts(), inventory = xPlayer.getInventory(), job = xPlayer.getJob(), cb({identifier = xPlayer.identifier, accounts = xPlayer.getAccounts(), inventory = xPlayer.getInventory(), job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(), money = xPlayer.getMoney(), position = xPlayer.getCoords(true), meta = xPlayer.getMeta()}) loadout = xPlayer.getLoadout(), money = xPlayer.getMoney(), position = xPlayer.getCoords(true), metadata = xPlayer.getMeta()})
end) end)
ESX.RegisterServerCallback('esx:isUserAdmin', function(source, cb) ESX.RegisterServerCallback('esx:isUserAdmin', function(source, cb)
@@ -609,7 +609,7 @@ ESX.RegisterServerCallback('esx:getOtherPlayerData', function(source, cb, target
local xPlayer = ESX.GetPlayerFromId(target) local xPlayer = ESX.GetPlayerFromId(target)
cb({identifier = xPlayer.identifier, accounts = xPlayer.getAccounts(), inventory = xPlayer.getInventory(), job = xPlayer.getJob(), cb({identifier = xPlayer.identifier, accounts = xPlayer.getAccounts(), inventory = xPlayer.getInventory(), job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(), money = xPlayer.getMoney(), position = xPlayer.getCoords(true), meta = xPlayer.getMeta()}) loadout = xPlayer.getLoadout(), money = xPlayer.getMoney(), position = xPlayer.getCoords(true), metadata = xPlayer.getMeta()})
end) end)
ESX.RegisterServerCallback('esx:getPlayerNames', function(source, cb, players) ESX.RegisterServerCallback('esx:getPlayerNames', function(source, cb, players)