Wait till ingame addons are loaded before hooking.

CrazyDutchGuy [06-28-14 - 17:03]
Wait till ingame addons are loaded before hooking.
Filename
LibSort-1.0/LibSort-1.0.lua
diff --git a/LibSort-1.0/LibSort-1.0.lua b/LibSort-1.0/LibSort-1.0.lua
index 9fdeede..80be463 100644
--- a/LibSort-1.0/LibSort-1.0.lua
+++ b/LibSort-1.0/LibSort-1.0.lua
@@ -118,8 +118,18 @@ function LibSort:ProcessInventory(inventoryType)
 	end
 end

-ZO_PreHook(PLAYER_INVENTORY, "ApplySort", function(self, inventoryType) LibSort:ProcessInventory(inventoryType) end)
-LibSort:SetupArrows()
+function LibSort:Loaded(event, name)
+   	if name ~= "ZO_Ingame" then return end
+
+		ZO_PreHook(PLAYER_INVENTORY, "ApplySort", function(self, inventoryType) LibSort:ProcessInventory(inventoryType) end)
+		LibSort:SetupArrows()
+
+		EVENT_MANAGER:UnregisterForEvent("LibSortLoaded", EVENT_ADD_ON_LOADED)
+	end
+end
+
+EVENT_MANAGER:RegisterForEvent("LibSortLoaded", EVENT_ADD_ON_LOADED, function(...) LibSort:Loaded(...) end)
+
 --------- API ---------

 function LibSort:Unregister(addonName, name)