Skip to content

Commit

Permalink
Implement cooldowns
Browse files Browse the repository at this point in the history
  • Loading branch information
coleminer0112 committed Oct 16, 2023
1 parent 19cc872 commit ce1d80d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
27 changes: 18 additions & 9 deletions server/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ Citizen.CreateThread(function()
end)

RegisterServerEvent("EasyAdmin:kickPlayer", function(playerId,reason)
if DoesPlayerHavePermission(source, "player.kick") and not CachedPlayers[playerId].immune then
if DoesPlayerHavePermission(source, "player.kick") and CheckAdminCooldown(source, "kick") and not CachedPlayers[playerId].immune then
SetAdminCooldown(source, "kick")
reason = formatShortcuts(reason)
SendWebhookMessage(moderationNotification,string.format(GetLocalisedText("adminkickedplayer"), getName(source, false, true), getName(playerId, true, true), reason), "kick", 16711680)
PrintDebugMessage("Kicking Player "..getName(source, true).." for "..reason, 3)
Expand All @@ -290,7 +291,8 @@ Citizen.CreateThread(function()
end)

RegisterServerEvent("EasyAdmin:requestSpectate", function(playerId)
if DoesPlayerHavePermission(source, "player.spectate") then
if DoesPlayerHavePermission(source, "player.spectate") and CheckAdminCooldown(source, "spectate") then
SetAdminCooldown(source, "spectate")
PrintDebugMessage("Player "..getName(source,true).." Requested Spectate to "..getName(playerId,true), 3)
local tgtCoords = GetEntityCoords(GetPlayerPed(playerId))
TriggerClientEvent("EasyAdmin:requestSpectate", source, playerId, tgtCoords)
Expand Down Expand Up @@ -405,7 +407,8 @@ Citizen.CreateThread(function()
end)

RegisterServerEvent("EasyAdmin:TeleportPlayerToCoords", function(playerId,tgtCoords)
if DoesPlayerHavePermission(source, "player.teleport.single") then
if DoesPlayerHavePermission(source, "player.teleport.single") and CheckAdminCooldown(source, "teleport") then
SetAdminCooldown(source, "teleport")
PrintDebugMessage("Player "..getName(source,true).." requsted teleport to "..tgtCoords.x..", "..tgtCoords.y..", "..tgtCoords.z, 3)
local preferredWebhook = detailNotification ~= "false" and detailNotification or moderationNotification
local playerName = getName(playerId, true, true)
Expand All @@ -418,7 +421,8 @@ Citizen.CreateThread(function()
end)

RegisterServerEvent("EasyAdmin:TeleportAdminToPlayer", function(id)
if not CachedPlayers[id].dropped and DoesPlayerHavePermission(source, "player.teleport.single") then
if not CachedPlayers[id].dropped and DoesPlayerHavePermission(source, "player.teleport.single") and CheckAdminCooldown(source, "teleport") then
SetAdminCooldown(source, "teleport")
local tgtPed = GetPlayerPed(id)
local tgtCoords = GetEntityCoords(tgtPed)
local preferredWebhook = detailNotification ~= "false" and detailNotification or moderationNotification
Expand Down Expand Up @@ -446,7 +450,8 @@ Citizen.CreateThread(function()
exports('slapPlayer', slapPlayer)

RegisterServerEvent("EasyAdmin:SlapPlayer", function(playerId,slapAmount)
if DoesPlayerHavePermission(source, "player.slap") and slapPlayer(playerId, slapAmount) then
if DoesPlayerHavePermission(source, "player.slap") and CheckAdminCooldown(source, "slap") and slapPlayer(playerId, slapAmount) then
SetAdminCooldown(source, "slap")
PrintDebugMessage("Player "..getName(source,true).." slapped "..getName(playerId,true).." for "..slapAmount.." HP", 3)
local preferredWebhook = detailNotification ~= "false" and detailNotification or moderationNotification
SendWebhookMessage(preferredWebhook,string.format(GetLocalisedText("adminslappedplayer"), getName(source, false, true), getName(playerId, true, true), slapAmount), "slap", 16777214)
Expand All @@ -472,10 +477,11 @@ Citizen.CreateThread(function()
exports('freezePlayer', freezePlayer)

RegisterServerEvent("EasyAdmin:FreezePlayer", function(playerId,toggle)
if DoesPlayerHavePermission(source, "player.freeze") and not CachedPlayers[playerId].immune then
if DoesPlayerHavePermission(source, "player.freeze") and not CachedPlayers[playerId].immune and CheckAdminCooldown(source, "freeze") then
local preferredWebhook = detailNotification ~= "false" and detailNotification or moderationNotification
freezePlayer(playerId, toggle)
if toggle then
SetAdminCooldown(source, "freeze")
SendWebhookMessage(preferredWebhook,string.format(GetLocalisedText("adminfrozeplayer"), getName(source, false, true), getName(playerId, true, true)), "freeze", 16777214)
PrintDebugMessage("Player "..getName(source,true).." froze "..getName(playerId,true), 3)
else
Expand Down Expand Up @@ -507,7 +513,8 @@ Citizen.CreateThread(function()
invokingResource = "`"..GetInvokingResource().."`"
end

if DoesPlayerHavePermission(source, "player.screenshot") then
if DoesPlayerHavePermission(source, "player.screenshot") and CheckAdminCooldown(source, "screenshot") then
SetAdminCooldown(source, "screenshot")
scrinprogress = true
thistemporaryevent = RegisterServerEvent("EasyAdmin:TookScreenshot", function(result)
if result == "ERROR" then return false end
Expand Down Expand Up @@ -540,7 +547,8 @@ Citizen.CreateThread(function()

RegisterServerEvent("EasyAdmin:mutePlayer", function(playerId)
local src = source
if DoesPlayerHavePermission(src,"player.mute") and not CachedPlayers[playerId].immune then
if DoesPlayerHavePermission(src,"player.mute") and not CachedPlayers[playerId].immune and CheckAdminCooldown(source, "mute") then
SetAdminCooldown(source, "mute")
local muted = mutePlayer(playerId, not MutedPlayers[playerId])

if muted then
Expand Down Expand Up @@ -667,7 +675,8 @@ Citizen.CreateThread(function()

RegisterServerEvent("EasyAdmin:warnPlayer", function(id, reason)
local src = source
if DoesPlayerHavePermission(src,"player.warn") and not CachedPlayers[id].immune then
if DoesPlayerHavePermission(src,"player.warn") and not CachedPlayers[id].immune and CheckAdminCooldown(source, "warn") then
SetAdminCooldown(source, "warn")
reason = formatShortcuts(reason)
local maxWarnings = GetConvarInt("ea_maxWarnings", 3)
if not WarnedPlayers[id] then
Expand Down
12 changes: 8 additions & 4 deletions server/banlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
blacklist = {}

RegisterServerEvent("EasyAdmin:banPlayer", function(playerId,reason,expires)
if playerId ~= nil then
if playerId ~= nil and CheckAdminCooldown(source, "ban") then
if (DoesPlayerHavePermission(source, "player.ban.temporary") or DoesPlayerHavePermission(source, "player.ban.permanent")) and CachedPlayers[playerId] and not CachedPlayers[playerId].immune then
SetAdminCooldown(source, "ban")
local bannedIdentifiers = CachedPlayers[playerId].identifiers or getAllPlayerIdentifiers(playerId)
local username = CachedPlayers[playerId].name or getName(playerId, true)
if expires and expires < os.time() then
Expand All @@ -39,8 +40,9 @@ RegisterServerEvent("EasyAdmin:banPlayer", function(playerId,reason,expires)
end)

RegisterServerEvent("EasyAdmin:offlinebanPlayer", function(playerId,reason,expires)
if playerId ~= nil and not CachedPlayers[playerId].immune then
if playerId ~= nil and not CachedPlayers[playerId].immune and CheckAdminCooldown(source, "ban") then
if (DoesPlayerHavePermission(source, "player.ban.temporary") or DoesPlayerHavePermission(source, "player.ban.permanent")) and not CachedPlayers[playerId].immune then
SetAdminCooldown(source, "ban")
local bannedIdentifiers = CachedPlayers[playerId].identifiers or getAllPlayerIdentifiers(playerId)
local username = CachedPlayers[playerId].name or getName(playerId, true)
if expires and expires < os.time() then
Expand Down Expand Up @@ -131,7 +133,8 @@ RegisterServerEvent("EasyAdmin:requestBanlist", function()
end)

RegisterCommand("unban", function(source, args, rawCommand)
if args[1] and DoesPlayerHavePermission(source, "player.ban.remove") then
if args[1] and DoesPlayerHavePermission(source, "player.ban.remove") and CheckAdminCooldown(source, "unban") then
SetAdminCooldown(source, "unban")
PrintDebugMessage("Player "..getName(source,true).." Unbanned "..args[1], 3)
if tonumber(args[1]) then
UnbanId(tonumber(args[1]))
Expand Down Expand Up @@ -183,7 +186,8 @@ end
exports('fetchBan', fetchBan)

RegisterServerEvent("EasyAdmin:unbanPlayer", function(banId)
if DoesPlayerHavePermission(source, "player.ban.remove") then
if DoesPlayerHavePermission(source, "player.ban.remove") and CheckAdminCooldown(source, "unban") then
SetAdminCooldown(source, "unban")
local thisBan = fetchBan(banId)
local ret = unbanPlayer(banId)
if ret then
Expand Down

0 comments on commit ce1d80d

Please sign in to comment.