Skip to content

Commit

Permalink
Update Class Whitelists plugin (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
wowm0d committed Jun 8, 2020
1 parent 79ffd1e commit a40806b
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions class_whitelists.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,25 @@ ix.lang.AddTable("english", {

local playerMeta = FindMetaTable("Player")

function playerMeta:HasClassWhitelist(class)
local data = ix.class.list[class]

if (data) then
if (data.isDefault) then
return true
end

local clientData = self:GetData("classWhitelists", {})

return clientData[Schema.folder] and clientData[Schema.folder][data.uniqueID]
end

return false
end

if (SERVER) then
function playerMeta:SetClassWhitelisted(class, whitelisted)
if (!whitelisted) then
if (whitelisted != true) then
whitelisted = nil
end

Expand All @@ -43,7 +59,7 @@ if (SERVER) then
if (data) then
local classWhitelists = self:GetData("classWhitelists", {})
classWhitelists[Schema.folder] = classWhitelists[Schema.folder] or {}
classWhitelists[Schema.folder][data.uniqueID] = whitelisted and true or nil
classWhitelists[Schema.folder][data.uniqueID] = whitelisted

self:SetData("classWhitelists", classWhitelists)
self:SaveData()
Expand All @@ -55,22 +71,6 @@ if (SERVER) then
end
end

function playerMeta:HasClassWhitelist(class)
local data = ix.class.list[class]

if (data) then
if (data.isDefault) then
return true
end

local ixData = self:GetData("classWhitelists", {})

return ixData[Schema.folder] and ixData[Schema.folder][data.uniqueID] == true or false
end

return false
end

do
local COMMAND = {}
COMMAND.arguments = {ix.type.player, ix.type.text}
Expand Down Expand Up @@ -149,21 +149,20 @@ do
query:Callback(function(result)
if (istable(result) and #result > 0) then
local data = util.JSONToTable(result[1].data or "[]")
local whitelists = data.whitelists and data.whitelists[Schema.folder]

if (!whitelists or !whitelists[class.uniqueID]) then
return
end
local whitelists = data.classWhitelists and data["classWhitelists"][Schema.folder]

whitelists[class.uniqueID] = nil
if (whitelists and whitelists[class.uniqueID]) then
whitelists[class.uniqueID] = nil
data["classWhitelists"][Schema.folder] = whitelists

local updateQuery = mysql:Update("ix_players")
updateQuery:Update("data", util.TableToJSON(data))
updateQuery:Where("steamid", steamID64)
updateQuery:Execute()
local updateQuery = mysql:Update("ix_players")
updateQuery:Update("data", util.TableToJSON(data))
updateQuery:Where("steamid", steamID64)
updateQuery:Execute()

for _, v in ipairs(player.GetAll()) do
v:NotifyLocalized("unclasswhitelist", client:GetName(), target, L(class.name, v))
for _, v in ipairs(player.GetAll()) do
v:NotifyLocalized("unclasswhitelist", client:GetName(), target, L(class.name, v))
end
end
end
end)
Expand Down

0 comments on commit a40806b

Please sign in to comment.