Skip to content

Instantly share code, notes, and snippets.

@Mitch528
Created March 20, 2014 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mitch528/9667298 to your computer and use it in GitHub Desktop.
Save Mitch528/9667298 to your computer and use it in GitHub Desktop.
Permissions Plugin for SharpStar
perms = {}
local permissions = nil
local properties = PluginProperties("permissions.lua", plugindir)
properties:Load()
permissions = properties:GetPropertyArray("permissions")
if permissions == nil then
permissions = PluginPropertyArray()
properties.Properties:Add("permissions", permissions)
end
function perms.hasPermission(permission, player)
local client = getPlayerClientByName(player)
if client == nil then
return false
end
player = client.Server.Player.UUID
local plrPerm = perms.getPermissionByUuid(player)
if plrPerm == nil then
return false
end
return plrPerm[string.lower(permission)] ~= nil and plrPerm[string.lower(permission)]
end
function perms.removePermission(permission, player)
local client = getPlayerClientByName(player)
if client == nil then
return false
end
player = client.Server.Player.UUID
local plrPerm = perms.getPermissionByUuid(player)
if plrPerm == nil then
return false
end
if plrPerm[string.lower(permission)] ~= nil then
plrPerm:Remove(string.lower(permission))
end
properties:Save()
end
function perms.addPermission(permission, player)
local client = getPlayerClientByName(player)
if client == nil then
return false
end
player = client.Server.Player.UUID
local plrPerm = perms.getPermissionByUuid(player)
if plrPerm == nil then
plrPerm = PluginPropertyObject()
plrPerm:Add(PluginProperty("uuid", player))
plrPerm:Add(PluginProperty(string.lower(permission), true))
permissions:Add(plrPerm)
else
plrPerm:Add(PluginProperty(string.lower(permission), true))
end
properties:Save()
end
function perms.getPermissionByUuid(uuid)
local plrPerm = nil
for i = 1, permissions.Count do
local perm = properties:GetByIndex(permissions, i - 1)
if perm["uuid"]:ToObject(ctype(String)) == uuid then
plrPerm = perm
end
end
return plrPerm
end
function perms.reloadPermissions()
permissions:Load()
end
function getPlayerClientByName(playerName)
playerName = string.lower(playerName)
local clients = GetPlayerClients()
local clientToReturn = nil
for i = 1, clients.length do
local clientName = string.lower(clients[i - 1].Server.Player.Name)
if clientName == playerName then
clientToReturn = clients[i - 1]
break
end
end
return clientToReturn
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment