AdiButtonAuras

AdiButtonAuras

404k Downloads

[user rules] Forbidden API, which ones?!

BanditTech opened this issue ยท 4 comments

commented

I am having an issue where attempting to configure custom rules is giving me constant errors because of forbidden API calls. This portion of the addon could be greatly improved with a few better examples of what is possible within the allowed API.

One example, when attempting to ensure my spell is not highlighted outside of combat, UnitIsDead(units.player) is an error, because it is a forbidden API. but instead UnitIsDeadOrGhost(units.player) works fine.

Also determing the unitpowertype is forbidden. So I needed to use This Post Here to find the power to use on a per class basis.

Here is an example issue

Here is the rule I made for highlighting when DP is ready to cast

return Configure {

  -- Unique Id
  "Devouring Plague",

  -- Description
  "Hint when energy to cast and debuff missing",

  -- Spells to modify
  {
        335467 -- Devouring Plague
  },

  -- Unit(s) to watch
  "enemy,player",

  -- Event(s) to watch
  { "UNIT_AURA" },

  -- Callback
  function(units, model)
      if (UnitPower(units.player,13) >= 50) and not GetDebuff('enemy',335467) then
          model.flash = true
      end
  end

} 

But it will not let me add UNIT_POWER to the event list, so that it will update with power changes.

Interface\AddOns\AdiButtonAuras\core\Overlays.lua:327: Attempt to register unknown event "UNIT_POWER" 
[string "=[C]"]: in function `RegisterEvent'

And although it at least lets me register UNIT_POWER_FREQUENT, it does not do anything differently as far as the end result. The trigger still waits till an aura changes on the target.

Is the power change events something this cannot do?

Similarly, UnitExists is another forbidden function :P

commented
Workaround for the forbidden events

instead of trying to use the actual event which is forbidden, I just used UNIT_HEALTH which updates constantly.

return Configure {

  -- Unique Id
  "Devouring Plague",

  -- Description
  "Hint when energy to cast, other dots up and debuff missing",

  -- Spells to modify
  {
        335467 -- Devouring Plague
  },

  -- Unit(s) to watch
  "enemy,player",

  -- Event(s) to watch
  { "UNIT_AURA", "UNIT_HEALTH" },

  -- Callback
  function(units, model)
      if (UnitHealth(units.enemy)>=1) and (UnitPower(units.player,13) >= 50) and not GetDebuff('enemy',335467) then
          model.flash = true
      end
  end

} 

Now it will update the moment the energy changes occur, and it will not display when you do not have a target! :D

commented

I spoke too soon, the GetDebuff part is not working as I thought :P hehe

Since it was a negated statement its just always firing when you have the energy. and UnitDebuffs is another protected function :(

commented

There is no such a thing like forbidden events in ABA. We try to register whatever you provided as the event argument and if the event does not exist, the game greets you with an error. Maybe reading forum posts from 2014 is not a good idea on getting up to speed with 2020 API. Try https://wow.gamepedia.com/UNIT_POWER_UPDATE (this is what UNIT_POWER was renamed to in 2018 btw).

We do however limit what from the WoW API is available to custom rules by using an explicit allow-list. This is to prevent harm by using code from unknown sources in your custom rules. Do not confuse this with the forbidden API calls, which are Blizzard restrictions and apply to all addons!

You can also use ABA's own API in custom rules (however not all of those make sense in a Configure rule as some of them are just shortcuts for Configure).

Actually all this is part of the docs.

Most of the other stuff is just syntax errors on your side. See Configure:

Wrong:

-- Unit(s) to watch
  "enemy,player",

Right:

-- Unit(s) to watch
  {"enemy", "player"},

You are using the units table wrong: "enemy" and "ally" are resolved automatically, to get the resulting real unit, you use it like units.ally or unit.enemy. Beware though - those might resolve to an empty string, so you have to consider this when you are using them depending on the API you use (i.e. UnitHealth('') returns 0). So GetDebuff("enemy", 335467) is wrong, GetDebuff(units.enemy, 335467) is the proper way to call this.

UnitDebuffs does not exist in the WoW API, and you should not use UnitDebuff in ABA but rather it's own methods as that's the whole point of ABA.

So, long story short:

return Configure {

	-- Unique Id
	"Devouring Plague",

	-- Description
	"Hint when energy to cast, other dots up and debuff missing",

	-- Spells to modify
	335467, -- Devouring Plague

	-- Unit(s) to watch
	{ "enemy", "player" },

	-- Event(s) to watch
	{ "UNIT_AURA", "UNIT_POWER_UPDATE" },

	-- Callback
	function(units, model)
		local foe = units.enemy
		if foe ~= '' and UnitPower('player', 13) >= 50 and not GetDebuff(foe, 335467) then
			model.flash = true
		end
	end
}

And if you don't want flash out of combat, maybe try this:

Untitled

commented

very much appreciated! I really love the customization without putting stuff all over the screen.

I ended up with this:
return Configure {

  -- Unique Id
  "Devouring Plague",

  -- Description
  "Hint when energy to cast, other dots up and debuff missing",

  -- Spells to modify
  335467, -- Devouring Plague

  -- Unit(s) to watch
  { "enemy",  "player" },

  -- Event(s) to watch
  { "UNIT_AURA", "UNIT_POWER_UPDATE" },

  -- Callback
  function(units, model)
    local foe = units.enemy
    local power = UnitPower('player', 13)
    if foe ~= '' then
      if power >= 50 and GetDebuff(foe, 589) and GetDebuff(foe, 34914) and not GetDebuff(foe, 335467) then
        model.flash = true
      elseif power >= 90 then
        model.flash = true
      elseif power >= 50 then
        model.hint = true
      end
    end
  end

}

Very helpful addon! :D