Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.84 KB | None | 0 0
  1. -- Blacklist - by Rinu
  2. -- v1.3
  3.  
  4. Blacklist = LibStub("AceAddon-3.0"):NewAddon("Blacklist", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0")
  5.  
  6. local defaults = {
  7. profile = {
  8. list = {},
  9. removedList = {},
  10. sync = true,
  11. recvsync = true,
  12. ignore = false,
  13. },
  14. }
  15.  
  16. function Blacklist:OnInitialize()
  17. self.version = 1.0
  18.  
  19. self.dbi = LibStub("AceDB-3.0"):New("BlacklistDB", defaults, true)
  20. self.db = self.dbi.profile
  21.  
  22. self.block = {}
  23.  
  24. -- hook the update function
  25. self:RawHook("FriendsFrame_Update", self.FriendsFrame_Update, true)
  26.  
  27. self:RegisterEvent("CHAT_MSG_ADDON", "CHAT_MSG_ADDON")
  28. self:RegisterEvent("PLAYER_ENTERING_WORLD", "SyncData")
  29. self:RegisterEvent("RAID_ROSTER_UPDATE", "CheckBlacklist")
  30. self:RegisterEvent("PARTY_MEMBERS_CHANGED", "CheckBlacklist")
  31.  
  32. self:RegisterChatCommand("blacklist", function(arg)
  33. if arg == "sync" then
  34. if self.db.sync == true then
  35. self.db.sync = false
  36. print("Blacklist: Sync off")
  37. else
  38. self.db.sync = true
  39. print("Blacklist: Sync on")
  40. end
  41. elseif arg == "recvsync" then
  42. if self.db.recvsync == true then
  43. self.db.recvsync = false
  44. print("Blacklist: Recieve Sync off")
  45. else
  46. self.db.recvsync = true
  47. print("Blacklist: Recieve Sync on")
  48. end
  49. elseif arg == "ignore" then
  50. if self.db.ignore == true then
  51. self.db.ignore = false
  52. print("Blacklist: Ignore off")
  53. else
  54. self.db.ignore = true
  55. print("Blacklist: Ignore on")
  56. end
  57. else
  58. print("Blacklist:")
  59. print("/blacklist sync - Send your list to other players of your guild.")
  60. print("/blacklist recvsync - Update your list with data of other players of your guild.")
  61. print("/blacklist ignore - Ignore players added by yourself.")
  62. end
  63. end)
  64.  
  65. StaticPopupDialogs["ADD_BLACKLIST"] = {
  66. text = "Add Player to the Black List",
  67. button1 = ACCEPT,
  68. button2 = CANCEL,
  69. hasEditBox = 1,
  70. maxLetters = 12,
  71. OnAccept = function(f)
  72. if self.db.list[f.editBox:GetText()] == nil and f.editBox:GetText():find(" ") == nil then
  73. if self.db.removedList[f.editBox:GetText()] ~= nil then
  74. self.db.removedList[f.editBox:GetText()] = nil
  75. end
  76.  
  77. self.db.list[f.editBox:GetText()] = "";
  78. self.listCount = self.listCount + 1
  79.  
  80. if self.db.sync then
  81. SendAddonMessage("BLACKLIST", f.editBox:GetText() .. " ", "GUILD")
  82. end
  83.  
  84. self:Update()
  85. end
  86. end,
  87. OnShow = function(self)
  88. self.editBox:SetFocus();
  89. end,
  90. OnHide = function(self)
  91. ChatEdit_FocusActiveWindow();
  92. self.editBox:SetText("");
  93. end,
  94. EditBoxOnEnterPressed = function(f)
  95. local parent = f:GetParent();
  96. if self.db.list[parent.editBox:GetText()] == nil and parent:GetText():find(" ") == nil then
  97. if self.db.removedList[parent.editBox:GetText()] ~= nil then
  98. self.db.removedList[parent.editBox:GetText()] = nil
  99. end
  100.  
  101. self.db.list[parent.editBox:GetText()] = "";
  102. self.listCount = self.listCount + 1
  103.  
  104. if self.db.sync then
  105. SendAddonMessage("BLACKLIST", parent.editBox:GetText() .. " ", "GUILD")
  106. end
  107.  
  108. parent:Hide()
  109. self:Update()
  110. end
  111. end,
  112. EditBoxOnEscapePressed = function(self)
  113. self:GetParent():Hide();
  114. end,
  115. timeout = 0,
  116. exclusive = 1,
  117. whileDead = 1,
  118. hideOnEscape = 1
  119. };
  120.  
  121. StaticPopupDialogs["SET_BLACKLISTNOTE"] = {
  122. text = "Set Blacklist Note:",
  123. button1 = ACCEPT,
  124. button2 = CANCEL,
  125. hasEditBox = 1,
  126. maxLetters = 48,
  127. haseditBox = 1,
  128. OnAccept = function(f)
  129. self.db.list[self.selectedNote] = f.editBox:GetText()
  130.  
  131. if self.db.sync then
  132. SendAddonMessage("BLACKLIST", self.selectedNote .. " " .. f.editBox:GetText(), "GUILD")
  133. end
  134.  
  135. self:Update()
  136. end,
  137. OnShow = function(f)
  138. if self.db.list[self.selectedNote] ~= nil then
  139. f.editBox:SetText(Blacklist.db.list[self.selectedNote])
  140. end
  141.  
  142. f.editBox:SetFocus();
  143. end,
  144. OnHide = function(self)
  145. ChatEdit_FocusActiveWindow();
  146. self.editBox:SetText("");
  147. end,
  148. EditBoxOnEnterPressed = function(f)
  149. local parent = f:GetParent();
  150. self.db.list[self.selectedNote] = parent.editBox:GetText();
  151.  
  152. if self.db.sync then
  153. SendAddonMessage("BLACKLIST", self.selectedNote .. " " .. parent.editBox:GetText(), "GUILD")
  154. end
  155.  
  156. self:Update()
  157. parent:Hide();
  158. end,
  159. EditBoxOnEscapePressed = function(self)
  160. self:GetParent():Hide();
  161. end,
  162. timeout = 0,
  163. exclusive = 1,
  164. whileDead = 1,
  165. hideOnEscape = 1
  166. };
  167.  
  168. self.listCount = 0
  169. for k,v in pairs(self.db.list) do
  170. self.listCount = self.listCount + 1
  171. end
  172.  
  173. self:OnShow()
  174. self:Create()
  175. end
  176.  
  177. function Blacklist:CheckBlacklist()
  178. local found = false
  179.  
  180. if GetNumRaidMembers() > 0 then
  181. for i = 1, GetNumRaidMembers() do
  182. local playername, _, _, _, _, _, _, _, _, _, _ = GetRaidRosterInfo(i)
  183.  
  184. if self.db.list[playername] ~= nil and self.block[playername] == nil then
  185. local note = ""
  186. if self.db.list[playername] ~= "" then
  187. note = " (" .. self.db.list[playername] .. ")"
  188. end
  189.  
  190. self.block[playername] = true
  191.  
  192. print("|cffff1111Blacklist: " .. playername .. " is on your blacklist!" .. note .. "|r")
  193. found = true
  194. end
  195. end
  196. else
  197. if UnitName("party1") == nil then
  198. self.block = {}
  199. end
  200.  
  201. for i = 1, 4 do
  202. local playername = UnitName("party" .. i)
  203.  
  204. if self.db.list[playername] ~= nil and self.block[playername] == nil then
  205. local note = ""
  206. if self.db.list[playername] ~= "" then
  207. note = " (" .. self.db.list[playername] .. ")"
  208. end
  209.  
  210. self.block[playername] = true
  211.  
  212. print("|cffff1111Blacklist: " .. playername .. " is on your blacklist!" .. note .. "|r")
  213. found = true
  214. end
  215. end
  216. end
  217.  
  218. -- play the sound only once
  219. if found == true then
  220. PlaySound("AuctionWindowOpen")
  221. end
  222. end
  223.  
  224. function Blacklist:SyncData()
  225. if self.db.recvsync then
  226. SendAddonMessage("BLACKLIST", "Sync", "GUILD")
  227. end
  228. end
  229.  
  230. function Blacklist:CHAT_MSG_ADDON(_, prefix, message, distType, sender)
  231. if prefix ~= "BLACKLIST" or sender == UnitName("player") or message == nil then return end
  232.  
  233. if message == "Sync" and self.db.sync then
  234. for k,v in pairs(self.db.list) do
  235. SendAddonMessage("BLACKLIST", k .. " " .. v, "WHISPER", sender)
  236. end
  237. elseif message == "Clear" then
  238. self.db.list = {}
  239. self:Update()
  240. else
  241. if self.db.recvsync then
  242. local delimiter = message:find(" ")
  243.  
  244. if delimiter ~= nil then
  245. local arg1 = message:sub(1, delimiter - 1)
  246.  
  247. if arg1 == "Remove" then
  248. local name = message:sub(delimiter + 1, -1)
  249.  
  250. if self.db.list[name] ~= nil then
  251. self.db.list[name] = nil
  252. self.db.removedList[name] = true
  253.  
  254. self.listCount = self.listCount - 1
  255. end
  256. else
  257. local name = arg1
  258. local note = message:sub(delimiter + 1, -1)
  259.  
  260. if self.db.removedList[name] == nil then
  261. if self.db.list[name] == nil then
  262. self.db.list[name] = note
  263. self.listCount = self.listCount + 1
  264. self:Update()
  265. else
  266. if self.db.list[name] == " " and note ~= " " then
  267. self.db.list[name] = note
  268. self.listCount = self.listCount + 1
  269. self:Update()
  270. end
  271. end
  272. end
  273. end
  274. end
  275. end
  276. end
  277. end
  278.  
  279. function Blacklist:OnShow()
  280. self.frame = CreateFrame("Frame", "BlackListFrame", FriendsFrame)
  281. self.frame:SetAllPoints(FriendsFrame)
  282.  
  283. -- buttons
  284. self.add = CreateFrame("Button", "BlackListFrameAddPlayer", BlackListFrame, "UIPanelButtonTemplate")
  285. self.add:SetPoint("BOTTOMLEFT", BlackListFrame, 17, 81)
  286. self.add:SetWidth(131)
  287. self.add:SetHeight(21)
  288. self.add:SetText("Add Player")
  289. self.add:SetFrameLevel(self.frame:GetFrameLevel() + 3)
  290.  
  291. self.add:SetScript("OnClick", function()
  292. if (UnitCanCooperate("player", "target")) then
  293. local name = UnitName("target")
  294. if self.db.sync then
  295. SendAddonMessage("BLACKLIST", name .. " ", "GUILD")
  296. end
  297.  
  298. tinsert(self.db.list, name)
  299. self.listCount = self.listCount + 1
  300.  
  301. if self.db.removedList[name] ~= nil then
  302. self.db.removedList[name] = nil
  303. end
  304.  
  305. if self.db.ignore then
  306. AddIgnore(name)
  307. end
  308.  
  309. self:Update()
  310. PlaySound("UChatScrollButton")
  311. else
  312. StaticPopup_Show("ADD_BLACKLIST")
  313. end
  314. end)
  315.  
  316. self.delete = CreateFrame("Button", "BlackListFrameDeletePlayer", BlackListFrame, "UIPanelButtonTemplate")
  317. self.delete:SetPoint("LEFT", BlackListFrameAddPlayer, "RIGHT", 62, 0)
  318. self.delete:SetWidth(131)
  319. self.delete:SetHeight(21)
  320. self.delete:SetText("Remove Player")
  321. self.delete:SetFrameLevel(self.frame:GetFrameLevel() + 3)
  322.  
  323. self.delete:SetScript("OnClick", function()
  324. local name = getglobal("BlackListFrameIgnoreButton" .. self.selectedIndex .. "Name"):GetText()
  325.  
  326. self.db.list[name] = nil
  327. self.db.removedList[name] = true
  328.  
  329. self.listCount = self.listCount - 1
  330.  
  331. if self.db.ignore then
  332. DelIgnore(name)
  333. end
  334.  
  335. if self.db.sync then
  336. SendAddonMessage("BLACKLIST", "Remove " .. name, "GUILD")
  337. end
  338.  
  339. self:Update()
  340. end)
  341.  
  342. -- add the blacklist to the friendframe tabs
  343. tinsert(FRIENDSFRAME_SUBFRAMES, "BlackListFrame")
  344.  
  345. -- blacklist tab
  346. self.tab4 = CreateFrame("Button", "FriendsTabHeaderTab4", FriendsTabHeader, "TabButtonTemplate")
  347.  
  348. self.tab4:SetPoint("LEFT", FriendsTabHeaderTab3, "RIGHT")
  349. self.tab4:SetText("Blacklist")
  350. self.tab4:SetID(4)
  351. self.tab4:SetWidth(60)
  352.  
  353. self.tab4:SetScript("OnClick", function(f)
  354. PanelTemplates_DeselectTab(f)
  355. PanelTemplates_Tab_OnClick(f, FriendsTabHeader);
  356. FriendsFrame_Update();
  357. PlaySound("igMainMenuOptionCheckBoxOn");
  358. end)
  359.  
  360. PanelTemplates_SetNumTabs(FriendsTabHeader, 4)
  361. PanelTemplates_UpdateTabs(FriendsTabHeader)
  362.  
  363. PanelTemplates_TabResize(self.tab4, 0);
  364.  
  365. self.scroll = CreateFrame("ScrollFrame", "BlacklistScroll", self.frame, "FauxScrollFrameTemplate")
  366. self.scroll:SetPoint("TOPLEFT", self.frame, "TOPLEFT", -68, -100)
  367. self.scroll:SetPoint("BOTTOMRIGHT", self.frame, "BOTTOMRIGHT", -68, 105)
  368. self.scroll:SetScript("OnVerticalScroll", function(self, offset)
  369. FauxScrollFrame_OnVerticalScroll(self, offset, 16, function() Blacklist:Update() end)
  370.  
  371. if self.selectedIndex ~= nil then
  372. self.data[self.selectedIndex].entry:UnlockHighlight()
  373. self.selectedIndex = nil
  374. end
  375. end)
  376. end
  377.  
  378. function Blacklist:Update()
  379. FauxScrollFrame_Update(self.scroll, self.listCount, 19, 16)
  380.  
  381. local function pairsByKeys(t, f)
  382. local a = {}
  383. for n in pairs(t) do table.insert(a, n) end
  384. table.sort(a, f)
  385. local i = 0 -- iterator variable
  386. local iter = function () -- iterator function
  387. i = i + 1
  388. if a[i] == nil then return nil
  389. else return a[i], t[a[i]]
  390. end
  391. end
  392. return iter
  393. end
  394.  
  395.  
  396. for i = 1, #self.data do
  397. getglobal("BlackListFrameIgnoreButton" .. i):Hide()
  398. end
  399.  
  400. local i = 1
  401. for k,v in pairsByKeys(self.db.list) do
  402. if i > FauxScrollFrame_GetOffset(self.scroll) then
  403. local id = i - FauxScrollFrame_GetOffset(self.scroll)
  404.  
  405. if id < 20 then
  406. getglobal("BlackListFrameIgnoreButton" .. id .. "Note"):SetScript("OnClick", function()
  407. self.selectedNote = k
  408. StaticPopup_Show("SET_BLACKLISTNOTE")
  409. end)
  410.  
  411. local note = v
  412. if note:len() > 80 then note = note:sub(1, 80) .. "..." end
  413.  
  414. getglobal("BlackListFrameIgnoreButton" .. id .. "Name"):SetText(k)
  415. getglobal("BlackListFrameIgnoreButton" .. id .. "NoteText"):SetText(note)
  416. getglobal("BlackListFrameIgnoreButton" .. id):Show()
  417. end
  418. end
  419.  
  420. i = i + 1
  421. end
  422. end
  423.  
  424. function Blacklist:Create()
  425. self.selectedIndex = nil
  426. self.selectedNote = nil
  427. self.data = {}
  428.  
  429. for i = 1, 19 do
  430. local entry = CreateFrame("Button", "BlackListFrameIgnoreButton" .. i, BlackListFrame, "FriendsFrameIgnoreButtonTemplate")
  431.  
  432. if i == 1 then
  433. entry:SetPoint("TOPLEFT", BlackListFrame, 23, -100)
  434. else
  435. entry:SetPoint("TOP", self.data[i - 1].entry, "BOTTOM")
  436. end
  437.  
  438. entry:SetWidth(298)
  439. entry:SetHeight(16)
  440.  
  441. local index = i
  442.  
  443. entry:SetScript("OnClick", function(f)
  444. if self.selectedIndex ~= nil then
  445. self.data[self.selectedIndex].entry:UnlockHighlight()
  446. end
  447.  
  448. f:LockHighlight()
  449. self.selectedIndex = index
  450. end)
  451.  
  452. -- note text
  453. local notetext = entry:CreateFontString("BlackListFrameIgnoreButton" .. i .. "NoteText", "OVERLAY")
  454. notetext:SetPoint("RIGHT", entry, "RIGHT", -10, 0)
  455. notetext:SetHeight(16)
  456. notetext:SetFontObject(GameFontNormalSmall)
  457. notetext:SetJustifyH("LEFT")
  458. notetext:SetTextColor(1, 1, 1, 1)
  459.  
  460. -- note button
  461. local note = CreateFrame("Button", "BlackListFrameIgnoreButton" .. i .. "Note", entry)
  462. note:SetPoint("RIGHT", entry, "LEFT", 8, 0)
  463.  
  464. note:SetWidth(7)
  465. note:SetHeight(8)
  466.  
  467. note:SetNormalTexture("Interface\\FriendsFrame\\UI-FriendsFrame-Note")
  468. note:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
  469.  
  470. tinsert(self.data, { entry = entry, note = note, notetext = notetext })
  471. end
  472. end
  473.  
  474. function Blacklist:FriendsFrame_Update()
  475. if (FriendsFrame.selectedTab == 1 and FriendsTabHeader.selectedTab == 4) then
  476. FriendsTabHeader:Show();
  477. FriendsFrameTopLeft:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-TopLeft-bnet");
  478. FriendsFrameTopRight:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-TopRight-bnet");
  479. FriendsFrameBottomRight:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-Pending-BotRight");
  480. FriendsFrameBottomLeft:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-Pending-BotLeft");
  481. FriendsFrameTitleText:SetText("Black List");
  482. FriendsFrame_ShowSubFrame("BlackListFrame");
  483. Blacklist:Update()
  484. else
  485. Blacklist.hooks.FriendsFrame_Update()
  486. end
  487. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement