add blacklist

Leandro Silva [04-04-20 - 22:25]
add blacklist
Filename
Inviter.lua
LeoDolmenRunner.lua
LeoDolmenRunner.txt
diff --git a/Inviter.lua b/Inviter.lua
index 147eded..1d1eb7b 100644
--- a/Inviter.lua
+++ b/Inviter.lua
@@ -7,7 +7,7 @@ local Inviter = {
 function Inviter:Kick()
     if not Inviter.started then return end
     for name, data in pairs(Inviter.kickList) do
-        if data ~= nil and GetTimeStamp() - data.added > LeoDolmenRunner.settings.inviter.kickDelay then
+        if data ~= nil and (data.added == 0 or GetTimeStamp() - data.added > LeoDolmenRunner.settings.inviter.kickDelay) then
             for i = 1, GetGroupSize() do
                 local tag = GetGroupUnitTagByIndex(i)
                 if GetUnitName(tag) == name then
@@ -36,6 +36,12 @@ function Inviter:CheckOfflines()
             LeoDolmenRunner.debug("Removing " .. name .. " from kick list, back online")
             Inviter.kickList[name] = nil
         end
+        if self:IsPlayerInBlacklist(name) then
+            Inviter.kickList[name] = {
+                unitTag = unitTag,
+                added  = 0
+            }
+        end
     end
 end

@@ -56,8 +62,12 @@ function Inviter:ChatMessage(type, from, message)

     if message ~= Inviter.message or from == nil or from == "" then return end

-    LeoDolmenRunner.log(zo_strformat("Inviting <<1>>", from))
     from = from:gsub("%^.+", "")
+    if self:IsPlayerInBlacklist(from) then
+        LeoDolmenRunner.log("Can't invite " .. from .. ": in the blacklist")
+        return
+    end
+    LeoDolmenRunner.log(zo_strformat("Inviting <<1>>", from))
     GroupInviteByName(from)
 end

@@ -76,6 +86,60 @@ function Inviter:Stop()
     LeoDolmenRunnerWindowInviterPanelStartStopLabel:SetText("Start")
 end

+local orig_GroupListRow_OnMouseUp = ZO_GroupListRow_OnMouseUp
+function ZO_GroupListRow_OnMouseUp(control, button, upInside)
+    orig_GroupListRow_OnMouseUp(control, button, upInside)
+    if button == MOUSE_BUTTON_INDEX_RIGHT and upInside then
+        AddMenuItem("LDR: Add to blacklist", function()
+            local data = ZO_ScrollList_GetData(control)
+            LeoDolmenRunner.log("Adding " .. data.characterName .. " to the blacklist")
+            table.insert(LeoDolmenRunner.settings.inviter.blacklist, data.characterName)
+        end)
+        ShowMenu(control)
+    end
+end
+
+function Inviter:DisplayBlacklist(name)
+    LeoDolmenRunner.log("Blacklist:")
+    for i, char in ipairs(LeoDolmenRunner.settings.inviter.blacklist) do
+        d(tostring(i) .. ") " .. char)
+    end
+end
+
+function Inviter:ClearBlacklist()
+    LeoDolmenRunner.log("Clearing the blacklist")
+    LeoDolmenRunner.settings.inviter.blacklist = {}
+end
+
+function Inviter:AddPlayerToBlacklist(name)
+    if (self:IsPlayerInBlacklist(name)) then return end
+    table.insert(LeoDolmenRunner.settings.inviter.blacklist, name)
+end
+
+function Inviter:RemovePlayerFromBlacklist(name)
+    local pos = tonumber(name)
+    if pos ~= nil and pos <= #LeoDolmenRunner.settings.inviter.blacklist then
+        LeoDolmenRunner.log("Removing " .. LeoDolmenRunner.settings.inviter.blacklist[pos] .. " from the blacklist")
+        table.remove(LeoDolmenRunner.settings.inviter.blacklist, pos)
+        return
+    end
+
+    for i, char in pairs(LeoDolmenRunner.settings.inviter.blacklist) do
+        if char == name then
+            LeoDolmenRunner.log("Removing " .. char .. " from the blacklist")
+            table.remove(LeoDolmenRunner.settings.inviter.blacklist, i)
+            return
+        end
+    end
+end
+
+function Inviter:IsPlayerInBlacklist(name)
+    for _, char in pairs(LeoDolmenRunner.settings.inviter.blacklist) do
+        if char == name then return true end
+    end
+    return false
+end
+
 function Inviter:Start(message)
     if not IsUnitSoloOrGroupLeader("player") then
         LeoDolmenRunner.log("You need to be group leader to invite.")
diff --git a/LeoDolmenRunner.lua b/LeoDolmenRunner.lua
index 851c0da..158db70 100644
--- a/LeoDolmenRunner.lua
+++ b/LeoDolmenRunner.lua
@@ -1,7 +1,7 @@
 LeoDolmenRunner = {
     name = "LeoDolmenRunner",
     displayName = "Leo's Dolmen Runner",
-    version = "1.1.4",
+    version = "1.1.5",
     chatPrefix = "|c39B027LeoDolmenRunner|r: ",
     isDebug = false,
     defaults = {
@@ -14,7 +14,8 @@ LeoDolmenRunner = {
         inviter = {
             maxSize = 24,
             autoKick = false,
-            kickDelay = 10
+            kickDelay = 10,
+            blacklist = {}
         }
     }
 }
@@ -58,10 +59,11 @@ function LDR:Initialize()

     SLASH_COMMANDS["/ldr"] = function(cmd)
         local options = {}
-        local searchResult = { string.match(cmd,"^(%S*)%s*(.-)$") }
-        for i,v in pairs(searchResult) do
+        local i = 1
+        for v in string.gmatch(cmd,"[^%s]+") do
             if (v ~= nil and v ~= "") then
                 options[i] = string.lower(v)
+                i = i + 1
             end
         end

@@ -86,6 +88,10 @@ function LDR:Initialize()
         elseif options[1] == "stop" then LDR.runner:Stop()
         elseif options[1] == "cw" then LDR.runner:CW()
         elseif options[1] == "ccw" then LDR.runner:CCW()
+        elseif options[1] == "bl" and #options == 1 then LDR.inviter:DisplayBlacklist()
+        elseif options[1] == "bl" and #options == 2 and options[2] == "clear" then LDR.inviter:ClearBlacklist()
+        elseif options[1] == "bl" and #options == 3 and options[2] == "add" then LDR.inviter:AddPlayerToBlacklist(options[3])
+        elseif options[1] == "bl" and #options == 3 and options[2] == "rem" then LDR.inviter:RemovePlayerFromBlacklist(options[3])
         elseif options[1] == "debug" and #options == 2 then LDR.isDebug = options[2] == "on"
         elseif options[1] == "ai" and #options == 2 and options[2] == "stop" then LDR.inviter:Stop()
         elseif string.len(options[1]) == 1 then LDR.inviter:Start(options[1])
@@ -115,6 +121,8 @@ local function OnAddOnLoaded(event, addonName)
     EVENT_MANAGER:UnregisterForEvent(LDR.name, EVENT_ADD_ON_LOADED)
     LDR.settings = LibSavedVars:NewAccountWide( LDR.name .. "_Data", "Account", LDR.defaults )

+    if not LeoDolmenRunner.settings.inviter.blacklist then LeoDolmenRunner.settings.inviter.blacklist = {} end
+
     LDR:Initialize()

     CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", OnSettingsControlsCreated)
diff --git a/LeoDolmenRunner.txt b/LeoDolmenRunner.txt
index 118946d..85cfe63 100644
--- a/LeoDolmenRunner.txt
+++ b/LeoDolmenRunner.txt
@@ -1,7 +1,7 @@
 ## Title: Leo's Dolmen Runner
 ## APIVersion: 100029 100030
-## Version: 1.1.4
-## AddOnVersion: 114
+## Version: 1.1.5
+## AddOnVersion: 115
 ## Author: |c39B027@LeandroSilva|r
 ## SavedVariables: LeoDolmenRunner_Data
 ## DependsOn: LibFeedback LibAddonMenu-2.0 LibSavedVars