forked from Jhn-git/Layerbeacon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayerbeacon_Handlers_AFK.lua
More file actions
76 lines (61 loc) · 2.44 KB
/
Layerbeacon_Handlers_AFK.lua
File metadata and controls
76 lines (61 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-- Layerbeacon_Handlers_AFK.lua
-- Ensure references
Layerbeacon = Layerbeacon or {}
Layerbeacon.Handlers = Layerbeacon.Handlers or {}
-- 1. Track Party Members
function Layerbeacon.Handlers.TrackPartyMembers()
local currentTime = GetTime()
-- Get current party members
local currentParty = Layerbeacon.Handlers.GetCurrentPartyMembers()
-- Update join times
local updatedParty = Layerbeacon.Handlers.UpdateJoinTimes(
Layerbeacon.Handlers.partyMembers,
currentParty,
currentTime
)
-- Detect players who left
local playersWhoLeft = Layerbeacon.Handlers.GetPlayersWhoLeft(
Layerbeacon.Handlers.partyMembers,
updatedParty
)
for _, playerName in ipairs(playersWhoLeft) do
Layerbeacon.Handlers.DebugPrintf("Player %s left. Removing from tracking.", playerName)
Layerbeacon.Handlers.leftPartyList[playerName] = currentTime
end
-- Update the party members list
Layerbeacon.Handlers.partyMembers = updatedParty
end
-- 2. Auto-Kick on New Player Join
function Layerbeacon.Handlers.AutoKickOnNewPlayer()
local currentTime = GetTime()
local afkTimeout = Layerbeacon.Config.AFK_TIMEOUT
for playerName, joinTime in pairs(Layerbeacon.Handlers.partyMembers) do
if (currentTime - joinTime) > afkTimeout then
-- Check for AFK player
Layerbeacon.Handlers.DebugPrintf("Player %s is AFK for too long. Kicking...", playerName)
Layerbeacon.Handlers.KickPlayer(playerName)
return -- Kick one player per event to avoid excessive disruption
end
end
end
-- 3. Kick Player Securely
function Layerbeacon.Handlers.KickPlayer(playerName)
if not playerName or playerName == "" then
Layerbeacon.Handlers.DebugPrintf("Invalid player name.")
return
end
if not UnitIsGroupLeader("player") then
Layerbeacon.Handlers.DebugPrintf("Cannot kick %s: You are not the group leader.", playerName)
return
end
if InCombatLockdown() then
Layerbeacon.Handlers.DebugPrintf("Cannot kick %s: Combat lockdown active.", playerName)
return
end
kickButton:SetAttribute("macrotext", "/uninvite " .. playerName)
kickButton:Click()
-- Remove player from tracking
Layerbeacon.Handlers.partyMembers[playerName] = nil
Layerbeacon.Handlers.leftPartyList[playerName] = GetTime()
Layerbeacon.Handlers.DebugPrintf("Kicked player %s for being AFK.", playerName)
end