Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Blacklist - by Rinu
- -- v1.3
- Blacklist = LibStub("AceAddon-3.0"):NewAddon("Blacklist", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0")
- local defaults = {
- profile = {
- list = {},
- removedList = {},
- sync = true,
- recvsync = true,
- ignore = false,
- },
- }
- function Blacklist:OnInitialize()
- self.version = 1.0
- self.dbi = LibStub("AceDB-3.0"):New("BlacklistDB", defaults, true)
- self.db = self.dbi.profile
- self.block = {}
- -- hook the update function
- self:RawHook("FriendsFrame_Update", self.FriendsFrame_Update, true)
- self:RegisterEvent("CHAT_MSG_ADDON", "CHAT_MSG_ADDON")
- self:RegisterEvent("PLAYER_ENTERING_WORLD", "SyncData")
- self:RegisterEvent("RAID_ROSTER_UPDATE", "CheckBlacklist")
- self:RegisterEvent("PARTY_MEMBERS_CHANGED", "CheckBlacklist")
- self:RegisterChatCommand("blacklist", function(arg)
- if arg == "sync" then
- if self.db.sync == true then
- self.db.sync = false
- print("Blacklist: Sync off")
- else
- self.db.sync = true
- print("Blacklist: Sync on")
- end
- elseif arg == "recvsync" then
- if self.db.recvsync == true then
- self.db.recvsync = false
- print("Blacklist: Recieve Sync off")
- else
- self.db.recvsync = true
- print("Blacklist: Recieve Sync on")
- end
- elseif arg == "ignore" then
- if self.db.ignore == true then
- self.db.ignore = false
- print("Blacklist: Ignore off")
- else
- self.db.ignore = true
- print("Blacklist: Ignore on")
- end
- else
- print("Blacklist:")
- print("/blacklist sync - Send your list to other players of your guild.")
- print("/blacklist recvsync - Update your list with data of other players of your guild.")
- print("/blacklist ignore - Ignore players added by yourself.")
- end
- end)
- StaticPopupDialogs["ADD_BLACKLIST"] = {
- text = "Add Player to the Black List",
- button1 = ACCEPT,
- button2 = CANCEL,
- hasEditBox = 1,
- maxLetters = 12,
- OnAccept = function(f)
- if self.db.list[f.editBox:GetText()] == nil and f.editBox:GetText():find(" ") == nil then
- if self.db.removedList[f.editBox:GetText()] ~= nil then
- self.db.removedList[f.editBox:GetText()] = nil
- end
- self.db.list[f.editBox:GetText()] = "";
- self.listCount = self.listCount + 1
- if self.db.sync then
- SendAddonMessage("BLACKLIST", f.editBox:GetText() .. " ", "GUILD")
- end
- self:Update()
- end
- end,
- OnShow = function(self)
- self.editBox:SetFocus();
- end,
- OnHide = function(self)
- ChatEdit_FocusActiveWindow();
- self.editBox:SetText("");
- end,
- EditBoxOnEnterPressed = function(f)
- local parent = f:GetParent();
- if self.db.list[parent.editBox:GetText()] == nil and parent:GetText():find(" ") == nil then
- if self.db.removedList[parent.editBox:GetText()] ~= nil then
- self.db.removedList[parent.editBox:GetText()] = nil
- end
- self.db.list[parent.editBox:GetText()] = "";
- self.listCount = self.listCount + 1
- if self.db.sync then
- SendAddonMessage("BLACKLIST", parent.editBox:GetText() .. " ", "GUILD")
- end
- parent:Hide()
- self:Update()
- end
- end,
- EditBoxOnEscapePressed = function(self)
- self:GetParent():Hide();
- end,
- timeout = 0,
- exclusive = 1,
- whileDead = 1,
- hideOnEscape = 1
- };
- StaticPopupDialogs["SET_BLACKLISTNOTE"] = {
- text = "Set Blacklist Note:",
- button1 = ACCEPT,
- button2 = CANCEL,
- hasEditBox = 1,
- maxLetters = 48,
- haseditBox = 1,
- OnAccept = function(f)
- self.db.list[self.selectedNote] = f.editBox:GetText()
- if self.db.sync then
- SendAddonMessage("BLACKLIST", self.selectedNote .. " " .. f.editBox:GetText(), "GUILD")
- end
- self:Update()
- end,
- OnShow = function(f)
- if self.db.list[self.selectedNote] ~= nil then
- f.editBox:SetText(Blacklist.db.list[self.selectedNote])
- end
- f.editBox:SetFocus();
- end,
- OnHide = function(self)
- ChatEdit_FocusActiveWindow();
- self.editBox:SetText("");
- end,
- EditBoxOnEnterPressed = function(f)
- local parent = f:GetParent();
- self.db.list[self.selectedNote] = parent.editBox:GetText();
- if self.db.sync then
- SendAddonMessage("BLACKLIST", self.selectedNote .. " " .. parent.editBox:GetText(), "GUILD")
- end
- self:Update()
- parent:Hide();
- end,
- EditBoxOnEscapePressed = function(self)
- self:GetParent():Hide();
- end,
- timeout = 0,
- exclusive = 1,
- whileDead = 1,
- hideOnEscape = 1
- };
- self.listCount = 0
- for k,v in pairs(self.db.list) do
- self.listCount = self.listCount + 1
- end
- self:OnShow()
- self:Create()
- end
- function Blacklist:CheckBlacklist()
- local found = false
- if GetNumRaidMembers() > 0 then
- for i = 1, GetNumRaidMembers() do
- local playername, _, _, _, _, _, _, _, _, _, _ = GetRaidRosterInfo(i)
- if self.db.list[playername] ~= nil and self.block[playername] == nil then
- local note = ""
- if self.db.list[playername] ~= "" then
- note = " (" .. self.db.list[playername] .. ")"
- end
- self.block[playername] = true
- print("|cffff1111Blacklist: " .. playername .. " is on your blacklist!" .. note .. "|r")
- found = true
- end
- end
- else
- if UnitName("party1") == nil then
- self.block = {}
- end
- for i = 1, 4 do
- local playername = UnitName("party" .. i)
- if self.db.list[playername] ~= nil and self.block[playername] == nil then
- local note = ""
- if self.db.list[playername] ~= "" then
- note = " (" .. self.db.list[playername] .. ")"
- end
- self.block[playername] = true
- print("|cffff1111Blacklist: " .. playername .. " is on your blacklist!" .. note .. "|r")
- found = true
- end
- end
- end
- -- play the sound only once
- if found == true then
- PlaySound("AuctionWindowOpen")
- end
- end
- function Blacklist:SyncData()
- if self.db.recvsync then
- SendAddonMessage("BLACKLIST", "Sync", "GUILD")
- end
- end
- function Blacklist:CHAT_MSG_ADDON(_, prefix, message, distType, sender)
- if prefix ~= "BLACKLIST" or sender == UnitName("player") or message == nil then return end
- if message == "Sync" and self.db.sync then
- for k,v in pairs(self.db.list) do
- SendAddonMessage("BLACKLIST", k .. " " .. v, "WHISPER", sender)
- end
- elseif message == "Clear" then
- self.db.list = {}
- self:Update()
- else
- if self.db.recvsync then
- local delimiter = message:find(" ")
- if delimiter ~= nil then
- local arg1 = message:sub(1, delimiter - 1)
- if arg1 == "Remove" then
- local name = message:sub(delimiter + 1, -1)
- if self.db.list[name] ~= nil then
- self.db.list[name] = nil
- self.db.removedList[name] = true
- self.listCount = self.listCount - 1
- end
- else
- local name = arg1
- local note = message:sub(delimiter + 1, -1)
- if self.db.removedList[name] == nil then
- if self.db.list[name] == nil then
- self.db.list[name] = note
- self.listCount = self.listCount + 1
- self:Update()
- else
- if self.db.list[name] == " " and note ~= " " then
- self.db.list[name] = note
- self.listCount = self.listCount + 1
- self:Update()
- end
- end
- end
- end
- end
- end
- end
- end
- function Blacklist:OnShow()
- self.frame = CreateFrame("Frame", "BlackListFrame", FriendsFrame)
- self.frame:SetAllPoints(FriendsFrame)
- -- buttons
- self.add = CreateFrame("Button", "BlackListFrameAddPlayer", BlackListFrame, "UIPanelButtonTemplate")
- self.add:SetPoint("BOTTOMLEFT", BlackListFrame, 17, 81)
- self.add:SetWidth(131)
- self.add:SetHeight(21)
- self.add:SetText("Add Player")
- self.add:SetFrameLevel(self.frame:GetFrameLevel() + 3)
- self.add:SetScript("OnClick", function()
- if (UnitCanCooperate("player", "target")) then
- local name = UnitName("target")
- if self.db.sync then
- SendAddonMessage("BLACKLIST", name .. " ", "GUILD")
- end
- tinsert(self.db.list, name)
- self.listCount = self.listCount + 1
- if self.db.removedList[name] ~= nil then
- self.db.removedList[name] = nil
- end
- if self.db.ignore then
- AddIgnore(name)
- end
- self:Update()
- PlaySound("UChatScrollButton")
- else
- StaticPopup_Show("ADD_BLACKLIST")
- end
- end)
- self.delete = CreateFrame("Button", "BlackListFrameDeletePlayer", BlackListFrame, "UIPanelButtonTemplate")
- self.delete:SetPoint("LEFT", BlackListFrameAddPlayer, "RIGHT", 62, 0)
- self.delete:SetWidth(131)
- self.delete:SetHeight(21)
- self.delete:SetText("Remove Player")
- self.delete:SetFrameLevel(self.frame:GetFrameLevel() + 3)
- self.delete:SetScript("OnClick", function()
- local name = getglobal("BlackListFrameIgnoreButton" .. self.selectedIndex .. "Name"):GetText()
- self.db.list[name] = nil
- self.db.removedList[name] = true
- self.listCount = self.listCount - 1
- if self.db.ignore then
- DelIgnore(name)
- end
- if self.db.sync then
- SendAddonMessage("BLACKLIST", "Remove " .. name, "GUILD")
- end
- self:Update()
- end)
- -- add the blacklist to the friendframe tabs
- tinsert(FRIENDSFRAME_SUBFRAMES, "BlackListFrame")
- -- blacklist tab
- self.tab4 = CreateFrame("Button", "FriendsTabHeaderTab4", FriendsTabHeader, "TabButtonTemplate")
- self.tab4:SetPoint("LEFT", FriendsTabHeaderTab3, "RIGHT")
- self.tab4:SetText("Blacklist")
- self.tab4:SetID(4)
- self.tab4:SetWidth(60)
- self.tab4:SetScript("OnClick", function(f)
- PanelTemplates_DeselectTab(f)
- PanelTemplates_Tab_OnClick(f, FriendsTabHeader);
- FriendsFrame_Update();
- PlaySound("igMainMenuOptionCheckBoxOn");
- end)
- PanelTemplates_SetNumTabs(FriendsTabHeader, 4)
- PanelTemplates_UpdateTabs(FriendsTabHeader)
- PanelTemplates_TabResize(self.tab4, 0);
- self.scroll = CreateFrame("ScrollFrame", "BlacklistScroll", self.frame, "FauxScrollFrameTemplate")
- self.scroll:SetPoint("TOPLEFT", self.frame, "TOPLEFT", -68, -100)
- self.scroll:SetPoint("BOTTOMRIGHT", self.frame, "BOTTOMRIGHT", -68, 105)
- self.scroll:SetScript("OnVerticalScroll", function(self, offset)
- FauxScrollFrame_OnVerticalScroll(self, offset, 16, function() Blacklist:Update() end)
- if self.selectedIndex ~= nil then
- self.data[self.selectedIndex].entry:UnlockHighlight()
- self.selectedIndex = nil
- end
- end)
- end
- function Blacklist:Update()
- FauxScrollFrame_Update(self.scroll, self.listCount, 19, 16)
- local function pairsByKeys(t, f)
- local a = {}
- for n in pairs(t) do table.insert(a, n) end
- table.sort(a, f)
- local i = 0 -- iterator variable
- local iter = function () -- iterator function
- i = i + 1
- if a[i] == nil then return nil
- else return a[i], t[a[i]]
- end
- end
- return iter
- end
- for i = 1, #self.data do
- getglobal("BlackListFrameIgnoreButton" .. i):Hide()
- end
- local i = 1
- for k,v in pairsByKeys(self.db.list) do
- if i > FauxScrollFrame_GetOffset(self.scroll) then
- local id = i - FauxScrollFrame_GetOffset(self.scroll)
- if id < 20 then
- getglobal("BlackListFrameIgnoreButton" .. id .. "Note"):SetScript("OnClick", function()
- self.selectedNote = k
- StaticPopup_Show("SET_BLACKLISTNOTE")
- end)
- local note = v
- if note:len() > 80 then note = note:sub(1, 80) .. "..." end
- getglobal("BlackListFrameIgnoreButton" .. id .. "Name"):SetText(k)
- getglobal("BlackListFrameIgnoreButton" .. id .. "NoteText"):SetText(note)
- getglobal("BlackListFrameIgnoreButton" .. id):Show()
- end
- end
- i = i + 1
- end
- end
- function Blacklist:Create()
- self.selectedIndex = nil
- self.selectedNote = nil
- self.data = {}
- for i = 1, 19 do
- local entry = CreateFrame("Button", "BlackListFrameIgnoreButton" .. i, BlackListFrame, "FriendsFrameIgnoreButtonTemplate")
- if i == 1 then
- entry:SetPoint("TOPLEFT", BlackListFrame, 23, -100)
- else
- entry:SetPoint("TOP", self.data[i - 1].entry, "BOTTOM")
- end
- entry:SetWidth(298)
- entry:SetHeight(16)
- local index = i
- entry:SetScript("OnClick", function(f)
- if self.selectedIndex ~= nil then
- self.data[self.selectedIndex].entry:UnlockHighlight()
- end
- f:LockHighlight()
- self.selectedIndex = index
- end)
- -- note text
- local notetext = entry:CreateFontString("BlackListFrameIgnoreButton" .. i .. "NoteText", "OVERLAY")
- notetext:SetPoint("RIGHT", entry, "RIGHT", -10, 0)
- notetext:SetHeight(16)
- notetext:SetFontObject(GameFontNormalSmall)
- notetext:SetJustifyH("LEFT")
- notetext:SetTextColor(1, 1, 1, 1)
- -- note button
- local note = CreateFrame("Button", "BlackListFrameIgnoreButton" .. i .. "Note", entry)
- note:SetPoint("RIGHT", entry, "LEFT", 8, 0)
- note:SetWidth(7)
- note:SetHeight(8)
- note:SetNormalTexture("Interface\\FriendsFrame\\UI-FriendsFrame-Note")
- note:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
- tinsert(self.data, { entry = entry, note = note, notetext = notetext })
- end
- end
- function Blacklist:FriendsFrame_Update()
- if (FriendsFrame.selectedTab == 1 and FriendsTabHeader.selectedTab == 4) then
- FriendsTabHeader:Show();
- FriendsFrameTopLeft:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-TopLeft-bnet");
- FriendsFrameTopRight:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-TopRight-bnet");
- FriendsFrameBottomRight:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-Pending-BotRight");
- FriendsFrameBottomLeft:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-Pending-BotLeft");
- FriendsFrameTitleText:SetText("Black List");
- FriendsFrame_ShowSubFrame("BlackListFrame");
- Blacklist:Update()
- else
- Blacklist.hooks.FriendsFrame_Update()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement