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_grade` int(11) DEFAULT 0,
`loadout` longtext DEFAULT NULL,
`meta` LONGTEXT NULL DEFAULT NULL,
`metadata` LONGTEXT NULL DEFAULT NULL,
`position` longtext NULL DEFAULT NULL,
`firstname` 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_grade` INT NULL DEFAULT 0,
`loadout` LONGTEXT NULL DEFAULT NULL,
`meta` LONGTEXT NULL DEFAULT NULL,
`metadata` LONGTEXT NULL DEFAULT NULL,
`position` longtext NULL DEFAULT NULL,
PRIMARY KEY (`identifier`)
+19 -19
View File
@@ -4,7 +4,7 @@ local DoesEntityExist = DoesEntityExist
local GetEntityCoords = GetEntityCoords
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 self = {}
@@ -22,7 +22,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
self.variables = {}
self.weight = weight
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
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("group", self.group, true)
stateBag:set("name", self.name, true)
stateBag:set("meta", self.meta, true)
stateBag:set("metadata", self.metadata, true)
function self.triggerEvent(eventName, ...)
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!")
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)
if _type == "string" then
if self.meta[index][subIndex] then
return self.meta[index][subIndex]
if self.metadata[index][subIndex] then
return self.metadata[index][subIndex]
end
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
local returnValues = {}
for i = 1, #subIndex do
if self.meta[index][subIndex[i]] then
returnValues[subIndex[i]] = self.meta[index][subIndex[i]]
if self.metadata[index][subIndex[i]] then
returnValues[subIndex[i]] = self.metadata[index][subIndex[i]]
else
print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not esxist on ^5%s^7!"):format(subIndex[i], index))
end
@@ -614,14 +614,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
return self.meta[index]
return self.metadata[index]
else
return print(("[^1ERROR^7] xPlayer.getMeta ^5%s^7 not exist!"):format(index))
end
end
return self.meta
return self.metadata
end
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))
end
self.meta[index] = value
self.metadata[index] = value
else
if _type ~= "string" then
return print(("[^1ERROR^7] xPlayer.setMeta ^5value^7 should be ^5string^7 as a subIndex!"):format(value))
end
self.meta[index][value] = subValue
self.metadata[index][value] = subValue
end
self.triggerEvent('esx:updatePlayerData', 'meta', self.meta)
Player(self.source).state:set('meta', self.meta, true)
self.triggerEvent('esx:updatePlayerData', 'metadata', self.metadata)
Player(self.source).state:set('metadata', self.metadata, true)
end
function self.clearMeta(index)
@@ -673,13 +673,13 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
return
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))
end
self.meta[index] = nil
self.triggerEvent('esx:updatePlayerData', 'meta', self.meta)
Player(self.source).state:set('meta', self.meta, true)
self.metadata[index] = nil
self.triggerEvent('esx:updatePlayerData', 'metadata', self.metadata)
Player(self.source).state:set('metadata', self.metadata, true)
end
for fnName,fn in pairs(targetOverrides) do
+2 -2
View File
@@ -157,7 +157,7 @@ function Core.SavePlayer(xPlayer, cb)
}
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,
function(affectedRows)
if affectedRows == 1 then
@@ -195,7 +195,7 @@ function Core.SavePlayers(cb)
end
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,
function(results)
if not results then
+9 -9
View File
@@ -3,7 +3,7 @@ SetGameType('ESX Legacy')
local oneSyncState = GetConvar('onesync', 'off')
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
newPlayer = newPlayer .. ', `firstname` = ?, `lastname` = ?, `dateofbirth` = ?, `sex` = ?, `height` = ?'
@@ -121,7 +121,7 @@ if not Config.Multichar then
end
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 job, grade, jobObject, gradeObject = result.job, tostring(result.job_grade)
local foundAccounts, foundItems = {}, {}
@@ -280,13 +280,13 @@ function loadESXPlayer(identifier, playerId, isNew)
end
end
if result.meta and result.meta ~= '' then
local meta = json.decode(result.meta)
userData.meta = meta
if result.metadata and result.metadata ~= '' then
local metadata = json.decode(result.metadata)
userData.metadata = metadata
end
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
Core.playersByIdentifier[identifier] = xPlayer
@@ -322,7 +322,7 @@ function loadESXPlayer(identifier, playerId, isNew)
dateofbirth = xPlayer.get("dateofbirth") or "01/01/2000",
height = xPlayer.get("height") or 120,
dead = false,
meta = xPlayer.getMeta()
metadata = xPlayer.getMeta()
}, isNew,
userData.skin)
@@ -594,7 +594,7 @@ ESX.RegisterServerCallback('esx:getPlayerData', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
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)
ESX.RegisterServerCallback('esx:isUserAdmin', function(source, cb)
@@ -609,7 +609,7 @@ ESX.RegisterServerCallback('esx:getOtherPlayerData', function(source, cb, target
local xPlayer = ESX.GetPlayerFromId(target)
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)
ESX.RegisterServerCallback('esx:getPlayerNames', function(source, cb, players)