From d0d36309cfd8859386d3140bc20ba39447dcc3a5 Mon Sep 17 00:00:00 2001 From: "D. Sidiropoulos" Date: Tue, 11 Jun 2024 23:52:27 +0200 Subject: [PATCH 1/3] feat (BuffBlock.lua): add additional slash commands /bb, /buffblock and /BuffBlock --- BuffBlock.lua | 254 +++++++++++++++++++++++++------------------------- 1 file changed, 129 insertions(+), 125 deletions(-) diff --git a/BuffBlock.lua b/BuffBlock.lua index d7e866b..5cd84f5 100644 --- a/BuffBlock.lua +++ b/BuffBlock.lua @@ -2,155 +2,159 @@ local BB_PlayerName = nil; local BB_default = {}; local BuffBlockMenuObjects = {} local BuffBlockMenuStrings = { - [00]= "Battle Shout", - [01]= "Blessing of Salvation", - [02]= "Greater Blessing of Salvation", - [03]= "Divine Spirit", - [04]= "Prayer of Spirit", - [05]= "Arcane Intellect", - [06]= "Arcane Brilliance", - [07]= "Blessing of Protection" + [00] = "Battle Shout", + [01] = "Blessing of Salvation", + [02] = "Greater Blessing of Salvation", + [03] = "Divine Spirit", + [04] = "Prayer of Spirit", + [05] = "Arcane Intellect", + [06] = "Arcane Brilliance", + [07] = "Blessing of Protection" } function BuffBlock_OnLoad() - this:RegisterEvent("PLAYER_AURAS_CHANGED"); - this:RegisterEvent("VARIABLES_LOADED"); - DEFAULT_CHAT_FRAME:AddMessage("Buff Block, by Armilus. /BB for options", 1, 1, 0.5); - SLASH_BB1 = "/BB"; - SlashCmdList["BB"] = BuffBlock_Command; + this:RegisterEvent("PLAYER_AURAS_CHANGED"); + this:RegisterEvent("VARIABLES_LOADED"); + DEFAULT_CHAT_FRAME:AddMessage("Buff Block, by Armilus. /BB for options", 1, 1, 0.5); + + SLASH_BB1 = "/BB" + SLASH_BB2 = "/bb" + SLASH_BB3 = "/buffblock" + SLASH_BB4 = "/BuffBlock" + SlashCmdList.BB = BuffBlock_Command end function BuffBlock_Init() - BB_PlayerName = UnitName("player").." of "..GetCVar("realmName"); - + BB_PlayerName = UnitName("player") .. " of " .. GetCVar("realmName"); + if (BUFF_CONFIG == nil) then - BUFF_CONFIG = {}; + BUFF_CONFIG = {}; end - - if (BUFF_CONFIG[BB_PlayerName] == nil) then - BUFF_CONFIG[BB_PlayerName] = BB_default; + + if (BUFF_CONFIG[BB_PlayerName] == nil) then + BUFF_CONFIG[BB_PlayerName] = BB_default; end end function BuffBlock_OnEvent() - if (event == "PLAYER_AURAS_CHANGED") then - Kill_Buffs(); - elseif (event == "VARIABLES_LOADED") then - BuffBlock_Init(); - end + if (event == "PLAYER_AURAS_CHANGED") then + Kill_Buffs(); + elseif (event == "VARIABLES_LOADED") then + BuffBlock_Init(); + end end function BuffBlock_Command() - if BuffBlockOptions:IsShown() then - BuffBlockOptions:Hide(); - else - BuffBlockOptions:Show(); - end + if BuffBlockOptions:IsShown() then + BuffBlockOptions:Hide(); + else + BuffBlockOptions:Show(); + end end function BuffBlock_GetOption(num) - local labelString = getglobal(this:GetName().."Text"); - local label = BuffBlockMenuStrings[num] or ""; - BuffBlockMenuObjects[num] = this - - if num == 00 and BUFF_CONFIG[BB_PlayerName].BATTLESHOUT - or num == 01 and BUFF_CONFIG[BB_PlayerName].SALVATION - or num == 02 and BUFF_CONFIG[BB_PlayerName].GREATERSALVATION - or num == 03 and BUFF_CONFIG[BB_PlayerName].DIVINESPIRIT - or num == 04 and BUFF_CONFIG[BB_PlayerName].PRAYEROFSPIRIT - or num == 05 and BUFF_CONFIG[BB_PlayerName].ARCANEINTELLECT - or num == 06 and BUFF_CONFIG[BB_PlayerName].ARCANEBRILLIANCE - or num == 07 and BUFF_CONFIG[BB_PlayerName].BLESSINGOFPROTECTION - or nil then - this:SetChecked(true); - else - this:SetChecked(nil); - end - labelString:SetText(label); + local labelString = getglobal(this:GetName() .. "Text"); + local label = BuffBlockMenuStrings[num] or ""; + BuffBlockMenuObjects[num] = this + + if num == 00 and BUFF_CONFIG[BB_PlayerName].BATTLESHOUT + or num == 01 and BUFF_CONFIG[BB_PlayerName].SALVATION + or num == 02 and BUFF_CONFIG[BB_PlayerName].GREATERSALVATION + or num == 03 and BUFF_CONFIG[BB_PlayerName].DIVINESPIRIT + or num == 04 and BUFF_CONFIG[BB_PlayerName].PRAYEROFSPIRIT + or num == 05 and BUFF_CONFIG[BB_PlayerName].ARCANEINTELLECT + or num == 06 and BUFF_CONFIG[BB_PlayerName].ARCANEBRILLIANCE + or num == 07 and BUFF_CONFIG[BB_PlayerName].BLESSINGOFPROTECTION + or nil then + this:SetChecked(true); + else + this:SetChecked(nil); + end + labelString:SetText(label); end function BuffBlock_SetOption(num) - local checked = this:GetChecked() - if num == 00 then - if checked then - BUFF_CONFIG[BB_PlayerName].BATTLESHOUT = 1 - DEFAULT_CHAT_FRAME:AddMessage("Blocking "..BuffBlockMenuStrings[num]); - else - BUFF_CONFIG[BB_PlayerName].BATTLESHOUT = nil - DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking "..BuffBlockMenuStrings[num]); - end - elseif num == 01 then - if checked then - BUFF_CONFIG[BB_PlayerName].SALVATION = 1 - DEFAULT_CHAT_FRAME:AddMessage("Blocking "..BuffBlockMenuStrings[num]); - else - BUFF_CONFIG[BB_PlayerName].SALVATION = nil - DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking "..BuffBlockMenuStrings[num]); - end - elseif num == 02 then - if checked then - BUFF_CONFIG[BB_PlayerName].GREATERSALVATION = 1 - DEFAULT_CHAT_FRAME:AddMessage("Blocking "..BuffBlockMenuStrings[num]); - else - BUFF_CONFIG[BB_PlayerName].GREATERSALVATION = nil - DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking "..BuffBlockMenuStrings[num]); - end - elseif num == 03 then - if checked then - BUFF_CONFIG[BB_PlayerName].DIVINESPIRIT = 1 - DEFAULT_CHAT_FRAME:AddMessage("Blocking "..BuffBlockMenuStrings[num]); - else - BUFF_CONFIG[BB_PlayerName].DIVINESPIRIT = nil - DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking "..BuffBlockMenuStrings[num]); - end - elseif num == 04 then - if checked then - BUFF_CONFIG[BB_PlayerName].PRAYEROFSPIRIT = 1 - DEFAULT_CHAT_FRAME:AddMessage("Blocking "..BuffBlockMenuStrings[num]); - else - BUFF_CONFIG[BB_PlayerName].PRAYEROFSPIRIT = nil - DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking "..BuffBlockMenuStrings[num]); - end - elseif num == 05 then - if checked then - BUFF_CONFIG[BB_PlayerName].ARCANEINTELLECT = 1 - DEFAULT_CHAT_FRAME:AddMessage("Blocking "..BuffBlockMenuStrings[num]); - else - BUFF_CONFIG[BB_PlayerName].ARCANEINTELLECT = nil - DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking "..BuffBlockMenuStrings[num]); - end - elseif num == 06 then - if checked then - BUFF_CONFIG[BB_PlayerName].ARCANEBRILLIANCE = 1 - DEFAULT_CHAT_FRAME:AddMessage("Blocking "..BuffBlockMenuStrings[num]); - else - BUFF_CONFIG[BB_PlayerName].ARCANEBRILLIANCE = nil - DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking "..BuffBlockMenuStrings[num]); - end - elseif num == 07 then - if checked then - BUFF_CONFIG[BB_PlayerName].BLESSINGOFPROTECTION = 1 - DEFAULT_CHAT_FRAME:AddMessage("Blocking "..BuffBlockMenuStrings[num]); - else - BUFF_CONFIG[BB_PlayerName].BLESSINGOFPROTECTION = nil - DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking "..BuffBlockMenuStrings[num]); - end - end + local checked = this:GetChecked() + if num == 00 then + if checked then + BUFF_CONFIG[BB_PlayerName].BATTLESHOUT = 1 + DEFAULT_CHAT_FRAME:AddMessage("Blocking " .. BuffBlockMenuStrings[num]); + else + BUFF_CONFIG[BB_PlayerName].BATTLESHOUT = nil + DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking " .. BuffBlockMenuStrings[num]); + end + elseif num == 01 then + if checked then + BUFF_CONFIG[BB_PlayerName].SALVATION = 1 + DEFAULT_CHAT_FRAME:AddMessage("Blocking " .. BuffBlockMenuStrings[num]); + else + BUFF_CONFIG[BB_PlayerName].SALVATION = nil + DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking " .. BuffBlockMenuStrings[num]); + end + elseif num == 02 then + if checked then + BUFF_CONFIG[BB_PlayerName].GREATERSALVATION = 1 + DEFAULT_CHAT_FRAME:AddMessage("Blocking " .. BuffBlockMenuStrings[num]); + else + BUFF_CONFIG[BB_PlayerName].GREATERSALVATION = nil + DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking " .. BuffBlockMenuStrings[num]); + end + elseif num == 03 then + if checked then + BUFF_CONFIG[BB_PlayerName].DIVINESPIRIT = 1 + DEFAULT_CHAT_FRAME:AddMessage("Blocking " .. BuffBlockMenuStrings[num]); + else + BUFF_CONFIG[BB_PlayerName].DIVINESPIRIT = nil + DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking " .. BuffBlockMenuStrings[num]); + end + elseif num == 04 then + if checked then + BUFF_CONFIG[BB_PlayerName].PRAYEROFSPIRIT = 1 + DEFAULT_CHAT_FRAME:AddMessage("Blocking " .. BuffBlockMenuStrings[num]); + else + BUFF_CONFIG[BB_PlayerName].PRAYEROFSPIRIT = nil + DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking " .. BuffBlockMenuStrings[num]); + end + elseif num == 05 then + if checked then + BUFF_CONFIG[BB_PlayerName].ARCANEINTELLECT = 1 + DEFAULT_CHAT_FRAME:AddMessage("Blocking " .. BuffBlockMenuStrings[num]); + else + BUFF_CONFIG[BB_PlayerName].ARCANEINTELLECT = nil + DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking " .. BuffBlockMenuStrings[num]); + end + elseif num == 06 then + if checked then + BUFF_CONFIG[BB_PlayerName].ARCANEBRILLIANCE = 1 + DEFAULT_CHAT_FRAME:AddMessage("Blocking " .. BuffBlockMenuStrings[num]); + else + BUFF_CONFIG[BB_PlayerName].ARCANEBRILLIANCE = nil + DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking " .. BuffBlockMenuStrings[num]); + end + elseif num == 07 then + if checked then + BUFF_CONFIG[BB_PlayerName].BLESSINGOFPROTECTION = 1 + DEFAULT_CHAT_FRAME:AddMessage("Blocking " .. BuffBlockMenuStrings[num]); + else + BUFF_CONFIG[BB_PlayerName].BLESSINGOFPROTECTION = nil + DEFAULT_CHAT_FRAME:AddMessage("Stopped blocking " .. BuffBlockMenuStrings[num]); + end + end end function IsShieldEquipped() - local slot = GetInventorySlotInfo("SecondaryHandSlot") - local link = GetInventoryItemLink("player", slot) - if link then - local found, _, id, name = string.find(link, "item:(%d+):.*%[(.*)%]") - if found then - local _,_,_,_,_,itemType = GetItemInfo(tonumber(id)) - if(itemType == "Shields") then - return true - end - end - end - return false + local slot = GetInventorySlotInfo("SecondaryHandSlot") + local link = GetInventoryItemLink("player", slot) + if link then + local found, _, id, name = string.find(link, "item:(%d+):.*%[(.*)%]") + if found then + local _, _, _, _, _, itemType = GetItemInfo(tonumber(id)) + if (itemType == "Shields") then + return true + end + end + end + return false end function Kill_Buffs() From 6829cb460cb3f66d024b327c809ff6e2d746402e Mon Sep 17 00:00:00 2001 From: "D. Sidiropoulos" Date: Tue, 11 Jun 2024 23:53:02 +0200 Subject: [PATCH 2/3] fix (BuffBlock.lua): when scanning buffs we now check that texture is non-nil --- BuffBlock.lua | 124 +++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/BuffBlock.lua b/BuffBlock.lua index 5cd84f5..6267ea9 100644 --- a/BuffBlock.lua +++ b/BuffBlock.lua @@ -158,65 +158,67 @@ function IsShieldEquipped() end function Kill_Buffs() - local i = 0; - while not (GetPlayerBuff(i, "HELPFUL") == -1) do - local buffIndex, untilCancelled = GetPlayerBuff(i, "HELPFUL") - local texture = GetPlayerBuffTexture(buffIndex); - - --DEFAULT_CHAT_FRAME:AddMessage("DEBUG: "..texture, 1, 1, 0.5); - - if BUFF_CONFIG[BB_PlayerName].BATTLESHOUT then - if (string.find(texture,"BattleShout")) then - CancelPlayerBuff(buffIndex); - DEFAULT_CHAT_FRAME:AddMessage("Blocked "..BuffBlockMenuStrings[00], 1, 1, 0.5); - end - end - if BUFF_CONFIG[BB_PlayerName].SALVATION then - if (string.lower(UnitClass("player")) ~= "warrior" or (IsShieldEquipped() and GetShapeshiftFormInfo(2))) then - if (string.find(texture,"SealOfSalvation")) then - CancelPlayerBuff(buffIndex); - DEFAULT_CHAT_FRAME:AddMessage("Blocked "..BuffBlockMenuStrings[01], 1, 1, 0.5); - end - end - end - if BUFF_CONFIG[BB_PlayerName].GREATERSALVATION then - if (string.lower(UnitClass("player")) ~= "warrior" or (IsShieldEquipped() and GetShapeshiftFormInfo(2))) then - if (string.find(texture,"GreaterBlessingofSalvation")) then - CancelPlayerBuff(buffIndex); - DEFAULT_CHAT_FRAME:AddMessage("Blocked "..BuffBlockMenuStrings[02], 1, 1, 0.5); - end - end - end - if BUFF_CONFIG[BB_PlayerName].DIVINESPIRIT then - if (string.find(texture,"DivineSpirit")) then - CancelPlayerBuff(buffIndex); - DEFAULT_CHAT_FRAME:AddMessage("Blocked "..BuffBlockMenuStrings[03], 1, 1, 0.5); - end - end - if BUFF_CONFIG[BB_PlayerName].PRAYEROFSPIRIT then - if (string.find(texture,"PrayerofSpirit")) then - CancelPlayerBuff(buffIndex); - DEFAULT_CHAT_FRAME:AddMessage("Blocked "..BuffBlockMenuStrings[04], 1, 1, 0.5); - end - end - if BUFF_CONFIG[BB_PlayerName].ARCANEINTELLECT then - if (string.find(texture,"MagicalSentry")) then - CancelPlayerBuff(buffIndex); - DEFAULT_CHAT_FRAME:AddMessage("Blocked "..BuffBlockMenuStrings[05], 1, 1, 0.5); - end - end - if BUFF_CONFIG[BB_PlayerName].ARCANEBRILLIANCE then - if (string.find(texture,"ArcaneIntellect")) then - CancelPlayerBuff(buffIndex); - DEFAULT_CHAT_FRAME:AddMessage("Blocked "..BuffBlockMenuStrings[06], 1, 1, 0.5); - end - end - if BUFF_CONFIG[BB_PlayerName].BLESSINGOFPROTECTION then - if (string.find(texture,"SealOfProtection")) then - CancelPlayerBuff(buffIndex); - DEFAULT_CHAT_FRAME:AddMessage("Blocked "..BuffBlockMenuStrings[07], 1, 1, 0.5); - end - end - i = i + 1; - end + local i = 0; + while not (GetPlayerBuff(i, "HELPFUL") == -1) do + local buffIndex, untilCancelled = GetPlayerBuff(i, "HELPFUL") + local texture = GetPlayerBuffTexture(buffIndex); + + --DEFAULT_CHAT_FRAME:AddMessage("DEBUG: "..texture, 1, 1, 0.5); + if texture then + if BUFF_CONFIG[BB_PlayerName].BATTLESHOUT then + if (string.find(texture, "BattleShout")) then + CancelPlayerBuff(buffIndex); + DEFAULT_CHAT_FRAME:AddMessage("Blocked " .. BuffBlockMenuStrings[00], 1, 1, 0.5); + end + end + if BUFF_CONFIG[BB_PlayerName].SALVATION then + if (string.lower(UnitClass("player")) ~= "warrior" or (IsShieldEquipped() and GetShapeshiftFormInfo(2))) then + if (string.find(texture, "SealOfSalvation")) then + CancelPlayerBuff(buffIndex); + DEFAULT_CHAT_FRAME:AddMessage("Blocked " .. BuffBlockMenuStrings[01], 1, 1, 0.5); + end + end + end + if BUFF_CONFIG[BB_PlayerName].GREATERSALVATION then + if (string.lower(UnitClass("player")) ~= "warrior" or (IsShieldEquipped() and GetShapeshiftFormInfo(2))) then + if (string.find(texture, "GreaterBlessingofSalvation")) then + CancelPlayerBuff(buffIndex); + DEFAULT_CHAT_FRAME:AddMessage("Blocked " .. BuffBlockMenuStrings[02], 1, 1, 0.5); + end + end + end + if BUFF_CONFIG[BB_PlayerName].DIVINESPIRIT then + if (string.find(texture, "DivineSpirit")) then + CancelPlayerBuff(buffIndex); + DEFAULT_CHAT_FRAME:AddMessage("Blocked " .. BuffBlockMenuStrings[03], 1, 1, 0.5); + end + end + if BUFF_CONFIG[BB_PlayerName].PRAYEROFSPIRIT then + if (string.find(texture, "PrayerofSpirit")) then + CancelPlayerBuff(buffIndex); + DEFAULT_CHAT_FRAME:AddMessage("Blocked " .. BuffBlockMenuStrings[04], 1, 1, 0.5); + end + end + if BUFF_CONFIG[BB_PlayerName].ARCANEINTELLECT then + if (string.find(texture, "MagicalSentry")) then + CancelPlayerBuff(buffIndex); + DEFAULT_CHAT_FRAME:AddMessage("Blocked " .. BuffBlockMenuStrings[05], 1, 1, 0.5); + end + end + if BUFF_CONFIG[BB_PlayerName].ARCANEBRILLIANCE then + if (string.find(texture, "ArcaneIntellect")) then + CancelPlayerBuff(buffIndex); + DEFAULT_CHAT_FRAME:AddMessage("Blocked " .. BuffBlockMenuStrings[06], 1, 1, 0.5); + end + end + if BUFF_CONFIG[BB_PlayerName].BLESSINGOFPROTECTION then + if (string.find(texture, "SealOfProtection")) then + CancelPlayerBuff(buffIndex); + DEFAULT_CHAT_FRAME:AddMessage("Blocked " .. BuffBlockMenuStrings[07], 1, 1, 0.5); + end + end + end + + i = i + 1; + end end From 1a46f7c46981718356d8e2138a666caef65cff35 Mon Sep 17 00:00:00 2001 From: "D. Sidiropoulos" Date: Tue, 11 Jun 2024 23:53:50 +0200 Subject: [PATCH 3/3] feat (.gitignore) --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file