vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Plugin = { |
||
3 | metaInformations = { |
||
4 | name = "GuildAdsPlayerTracker", |
||
5 | guildadsCompatible = 100, |
||
6 | } |
||
7 | |||
8 | getCommands = function() |
||
9 | return { |
||
10 | [GUILDADSPLAYERTRACKER_CMD_LOC] = { |
||
11 | [1] = { ["key"]="continent", |
||
12 | ["fout"]=GuildAdsPlugin.serializeInteger, |
||
13 | ["fin"]=GuildAdsPlugin.unserializeInteger } |
||
14 | } ... |
||
15 | } |
||
16 | }; |
||
17 | end; |
||
18 | |||
19 | getAdTypes = function() |
||
20 | end |
||
21 | |||
22 | -- others functions that can be defined |
||
23 | -- those functions will be called when the event occured |
||
24 | onChannelJoin(); |
||
25 | onChannelLeave(); |
||
26 | onShowAd(tooltip, adtype, ad) |
||
27 | onShowContextMenu(adtype, ad) |
||
28 | onOnline(playerName, status) |
||
29 | onUpdateInventory(owner, slot) |
||
30 | onAddGlobal(owner, adtype, ad) |
||
31 | onRemoveGlobal(owner, adtype, id) |
||
32 | onAddMy(adtype, ad) |
||
33 | onRemoveMy(adtype, id) |
||
34 | onShowAd(tooltip, adtype, ad) |
||
35 | onShowContextMenu(adtype, ad) |
||
36 | } |
||
37 | ]] |
||
38 | |||
39 | local pluginsToRegister = {}; |
||
40 | |||
41 | GuildAdsPlugin = { |
||
42 | |||
43 | debugOn = false; |
||
44 | |||
45 | PluginsList = {}; |
||
46 | |||
47 | addMenuEnabled = false; |
||
48 | |||
49 | EVENT_ONLINE = GAS_EVENT_ONLINE; |
||
50 | EVENT_UPDATEINVENTORY = GAS_EVENT_UPDATEINVENTORY; |
||
51 | EVENT_ADDGLOBAL = GAS_EVENT_ADDGLOBAL; |
||
52 | EVENT_REMOVEGLOBAL = GAS_EVENT_REMOVEGLOBAL; |
||
53 | EVENT_ADDMY = GAS_EVENT_ADDMY; |
||
54 | EVENT_REMOVEMY = GAS_EVENT_REMOVEMY; |
||
55 | |||
56 | EVENT_ONSHOWAD = "ShowAd"; |
||
57 | EVENT_ONSHOWCONTEXTMENU = "ShowContextMenu"; |
||
58 | |||
59 | -- currentTime() |
||
60 | currentTime = currentTime; |
||
61 | |||
62 | -- timeToString(time) |
||
63 | timeToString = timeToString; |
||
64 | |||
65 | -- isOnline(playername) |
||
66 | isOnline = GAS_IsOnline; |
||
67 | |||
68 | -- getAccountId() |
||
69 | getAccountId = GAS_GetAccountId; |
||
70 | |||
71 | -- getInventory(owner) |
||
72 | getInventory = GAS_ProfileGetInventory; |
||
73 | |||
74 | -- getProfile(owner) |
||
75 | getProfile = GAS_ProfileGet; |
||
76 | |||
77 | -- getUpdatedDate(owner) |
||
78 | getUpdatedDate = GAS_ProfileGetUpdatedDate; |
||
79 | |||
80 | -- getPlayersByAccount(accountid) |
||
81 | getPlayersByAccount = GAS_PlayersByAccount; |
||
82 | |||
83 | -- getMyAds() |
||
84 | getMyAds = GAS_GetMyAds; |
||
85 | |||
86 | -- getGlobalAds() |
||
87 | getGlobalAds = GAS_GetAds; |
||
88 | |||
89 | -- addMyAd(adtype, text, color, ref, name, texture, count) |
||
90 | addMyAd = GAS_AddMyAd; |
||
91 | |||
92 | -- editMyAd(adtype, id, text, color, ref, name, texture, count) |
||
93 | editMyAd = GAS_EditMyAd; |
||
94 | |||
95 | -- removeMyAd(adtype, id) |
||
96 | removeMyAd = GAS_RemoveMyAd; |
||
97 | |||
98 | -- enableMyAd(adtype, id) |
||
99 | enableMyAd = GAS_EnableMyAd; |
||
100 | |||
101 | -- GAS_DisableMyAd |
||
102 | disableMyAd = GAS_DisableMyAd; |
||
103 | |||
104 | -- GAS_AddAd |
||
105 | addGlobalAd = GAS_AddAd; |
||
106 | |||
107 | -- removeGlobalAdByOwnerAndId(owner, adtype, id) |
||
108 | removeGlobalAdByOwnerAndId = GAS_RemoveByOwnerAndId; |
||
109 | |||
110 | -- removeGlobalAdByOwner(owner, adtype) |
||
111 | removeGlobalAdByOwner = GAS_RemoveByOwner; |
||
112 | |||
113 | -- getSkillText(SkillId) |
||
114 | getSkillText = GAS_GetSkillText; |
||
115 | |||
116 | -- getClassText(ClassId) |
||
117 | getClassText = GAS_GetClassText; |
||
118 | |||
119 | -- getRaceText(RaceId) |
||
120 | getRaceText = GAS_GetRaceText; |
||
121 | |||
122 | -- getItemInfo |
||
123 | getItemInfo = GAS_GetItemInfo; |
||
124 | |||
125 | -- SerializeObj |
||
126 | serializeObj = GAC_SerializeObj; |
||
127 | unserializeObj = GAC_UnserializeObj; |
||
128 | |||
129 | -- SerializeString |
||
130 | serializeString = GAC_SerializeString; |
||
131 | unserializeString = GAC_UnserializeString; |
||
132 | |||
133 | -- SerializeInteger |
||
134 | serializeInteger = GAC_SerializeInteger; |
||
135 | unserializeInteger = GAC_UnserializeInteger; |
||
136 | |||
137 | -- SerializeColor |
||
138 | serializeColor = GAC_SerializeColor; |
||
139 | unserializeColor = GAC_UnserializeColor; |
||
140 | |||
141 | isPluginValid = function(plugin) |
||
142 | -- Every plugin needs to be a table |
||
143 | if type(plugin) ~= "table" then |
||
144 | return false, "Plugin type check failed."; |
||
145 | end |
||
146 | |||
147 | -- Check metainformations |
||
148 | if type(plugin.metaInformations) == "table" then |
||
149 | local metainfo = plugin.metaInformations; |
||
150 | -- check name |
||
151 | if type(metainfo.name)~="string" then |
||
152 | return false, "Plugin name check failed."; |
||
153 | end |
||
154 | -- check version |
||
155 | if type(metainfo.guildadsCompatible)~="number" or metainfo.guildadsCompatible>GUILDADS_VERSION then |
||
156 | return false, "Plugin incompatible with this version of GuildAds"; |
||
157 | end |
||
158 | else |
||
159 | return false, "Plugin Metainformations check failed."; |
||
160 | end |
||
161 | |||
162 | return true; |
||
163 | end; |
||
164 | |||
165 | _register = function(plugin) |
||
166 | local valid, errorMessage = GuildAdsPlugin.isPluginValid (plugin); |
||
167 | if valid then |
||
168 | -- register commands |
||
169 | if type(plugin.getCommands)=="function" then |
||
170 | local commands = plugin.getCommands(); |
||
171 | for command, spec in commands do |
||
172 | local status, errorMessage = GuildAdsPlugin.registerCommand(command, spec[1], spec[2]); |
||
173 | if not status then |
||
174 | return false, errorMessage; |
||
175 | end |
||
176 | end |
||
177 | end |
||
178 | |||
179 | -- register adtypes |
||
180 | if type(plugin.getAdTypes)=="function" then |
||
181 | local adtypes = plugin.getAdTypes(); |
||
182 | for adtype, spec in adtypes do |
||
183 | local status, errorMessage = GAC_RegisterAdtype(adtype, spec[1], spec[2]); |
||
184 | if not status then |
||
185 | return false, errorMessage; |
||
186 | end |
||
187 | end |
||
188 | end |
||
189 | |||
190 | local pluginName = plugin.metaInformations.name; |
||
191 | |||
192 | -- add plugin to GuildAdsPlugin.PluginsList |
||
193 | GuildAdsPlugin.PluginsList[pluginName] = plugin; |
||
194 | |||
195 | -- set debug function |
||
196 | plugin.debug = function(message) |
||
197 | GuildAdsPlugin.debug(pluginName..":"..message); |
||
198 | end |
||
199 | |||
200 | -- call onChannelJoin() ?? |
||
201 | |||
202 | return true; |
||
203 | else |
||
204 | return false, errorMessage; |
||
205 | end |
||
206 | end; |
||
207 | |||
208 | register = function(plugin) |
||
209 | if pluginsToRegister then |
||
210 | tinsert(pluginsToRegister, plugin) |
||
211 | return true; |
||
212 | else |
||
213 | return GuildAdsPlugin._register(plugin); |
||
214 | end |
||
215 | end; |
||
216 | |||
217 | UIregister = function(plugin) |
||
218 | status, errorMessage = GuildAdsPlugin.register(plugin); |
||
219 | if not status then |
||
220 | if errorMessage then |
||
221 | error(errorMessage,2); |
||
222 | else |
||
223 | error("error", 2); |
||
224 | end |
||
225 | end |
||
226 | end; |
||
227 | |||
228 | deregister = function(plugin) |
||
229 | local valid, errorMessage = GuildAdsPlugin.isPluginValid (plugin); |
||
230 | if valid then |
||
231 | GuildAdsPlugin.PluginsList[plugin.metaInformations.name] = nil; |
||
232 | -- call onChannelLeave() |
||
233 | return true; |
||
234 | else |
||
235 | return false, errorMessage; |
||
236 | end |
||
237 | end; |
||
238 | |||
239 | registerCommand = function(command, serializeInfo, onMessage) |
||
240 | return GAC_RegisterCommand(command, serializeInfo, onMessage); |
||
241 | end; |
||
242 | |||
243 | deregisterCommand = function(command) |
||
244 | return GAC_UnregisterCommand(command); |
||
245 | end; |
||
246 | |||
247 | registerAdtype = function(adtype, serializeInfo, onMessage) |
||
248 | return GAC_RegisterAdtype(adtype, serializeInfo, onMessage); |
||
249 | end; |
||
250 | |||
251 | deregisterAdtype = function(adtype) |
||
252 | return GAC_UnregisterAdtype(adtype); |
||
253 | end; |
||
254 | |||
255 | addContextMenu = function(menu) |
||
256 | if GuildAdsPlugin.addMenuEnabled and menu and menu.text then |
||
257 | UIDropDownMenu_AddButton(menu, 1); |
||
258 | return true; |
||
259 | else |
||
260 | return false; |
||
261 | end |
||
262 | end; |
||
263 | |||
264 | -- send(who, obj, delay) |
||
265 | send = function(who, obj, delay) |
||
266 | if obj.command and GAC_IsRegisteredCommand(obj.command) then |
||
267 | SimpleComm_SendMessage(who, obj, delay); |
||
268 | return true; |
||
269 | else |
||
270 | return false; |
||
271 | end |
||
272 | end; |
||
273 | |||
274 | -- sendRaw |
||
275 | sendRaw = function(who, message, delay) |
||
276 | if type(message) == "string" then |
||
277 | SimpleComm_SendRawMessage(who, message, delay); |
||
278 | return true; |
||
279 | else |
||
280 | return false; |
||
281 | end |
||
282 | end; |
||
283 | |||
284 | -- setDebug |
||
285 | setDebug = function(status) |
||
286 | if status then |
||
287 | GuildAdsPlugin.debugOn = true; |
||
288 | else |
||
289 | GuildAdsPlugin.debugOn = false; |
||
290 | end |
||
291 | end; |
||
292 | |||
293 | -- debug |
||
294 | debug = function(message, raw) |
||
295 | if GuildAdsPlugin.debugOn then |
||
296 | if raw then |
||
297 | ChatFrame1:AddMessage(message, 1.0, 0.25, 0.75); |
||
298 | else |
||
299 | ChatFrame1:AddMessage("GuildAdsPlugin:"..message, 1.0, 0.25, 0.75); |
||
300 | end |
||
301 | end |
||
302 | end |
||
303 | }; |
||
304 | |||
305 | local EventIdToMethod = { |
||
306 | [GuildAdsPlugin.EVENT_ONLINE] = "onOnline"; |
||
307 | [GuildAdsPlugin.EVENT_UPDATEINVENTORY] = "onUpdateInventory"; |
||
308 | [GuildAdsPlugin.EVENT_ADDGLOBAL] = "onAddGlobal"; |
||
309 | [GuildAdsPlugin.EVENT_REMOVEGLOBAL] = "onRemoveGlobal"; |
||
310 | [GuildAdsPlugin.EVENT_ADDMY] = "onAddMy"; |
||
311 | [GuildAdsPlugin.EVENT_REMOVEMY] = "onRemoveMy"; |
||
312 | [GuildAdsPlugin.EVENT_ONSHOWAD] = "onShowAd"; |
||
313 | [GuildAdsPlugin.EVENT_ONSHOWCONTEXTMENU] = "onShowContextMenu"; |
||
314 | } |
||
315 | |||
316 | local function pluginToRealCommand(command) |
||
317 | return "P"..command; |
||
318 | end |
||
319 | |||
320 | local function realToPluginCommand(command) |
||
321 | local iStart, iEnd, realCommand = string.find(command, "P(.*)"); |
||
322 | if (iStart) then |
||
323 | return realCommand; |
||
324 | else |
||
325 | return false; |
||
326 | end |
||
327 | end |
||
328 | |||
329 | local function methodToEventId(method) |
||
330 | for ltype, lmethod in EventIdToMethod do |
||
331 | if method == lmethod then |
||
332 | return ltype; |
||
333 | end |
||
334 | end |
||
335 | return nil; |
||
336 | end |
||
337 | |||
338 | function GuildAdsPlugin_RegisterPlugins() |
||
339 | -- register plugins |
||
340 | for _, plugin in ipairs(pluginsToRegister) do |
||
341 | local status, errorMessage = GuildAdsPlugin._register(plugin); |
||
342 | if not status then |
||
343 | local pluginName; |
||
344 | if plugin.metaInformations and plugin.metaInformations.name then |
||
345 | pluginName = plugin.metaInformations.name..": "; |
||
346 | else |
||
347 | pluginName = "GuildAds(unknown plugin):"; |
||
348 | end |
||
349 | if errorMessage then |
||
350 | message(pluginName..errorMessage); |
||
351 | else |
||
352 | message(pluginName.."error"); |
||
353 | end |
||
354 | end |
||
355 | end |
||
356 | |||
357 | -- GuildAdsPlugin.register : register immediatly |
||
358 | pluginsToRegister = nil; |
||
359 | end |
||
360 | |||
361 | function GuildAdsPlugin_OnInit() |
||
362 | -- call onInit |
||
363 | for pluginName, plugin in GuildAdsPlugin.PluginsList do |
||
364 | if type(plugin.onInit) == "function" then |
||
365 | plugin.onInit(); |
||
366 | end |
||
367 | end |
||
368 | end |
||
369 | |||
370 | function GuildAdsPlugin_OnChannelJoin() |
||
371 | for pluginName, plugin in GuildAdsPlugin.PluginsList do |
||
372 | if type(plugin.onChannelJoin) == "function" then |
||
373 | plugin.onChannelJoin(); |
||
374 | end |
||
375 | end |
||
376 | end |
||
377 | |||
378 | function GuildAdsPlugin_OnChannelLeave() |
||
379 | for pluginName, plugin in GuildAdsPlugin.PluginsList do |
||
380 | if type(plugin.onChannelJoin) == "function" then |
||
381 | plugin.onChannelLeave(); |
||
382 | end |
||
383 | end |
||
384 | end |
||
385 | |||
386 | function GuildAdsPlugin_OnShowAd(tooltip, adtype, ad) |
||
387 | for pluginName, plugin in GuildAdsPlugin.PluginsList do |
||
388 | if type(plugin.onShowAd) == "function" then |
||
389 | plugin.onShowAd(tooltip, adtype, ad); |
||
390 | end |
||
391 | end |
||
392 | end |
||
393 | |||
394 | function GuildAdsPlugin_OnShowContextMenu(adtype, ad) |
||
395 | for listenerName, plugin in GuildAdsPlugin.PluginsList do |
||
396 | if type(plugin.onShowContextMenu) == "function" then |
||
397 | --[[ |
||
398 | info = { }; |
||
399 | info.text = listenerName; |
||
400 | UIDropDownMenu_AddButton(menu, 1); |
||
401 | ]] |
||
402 | GuildAdsPlugin.addMenuEnabled = true; |
||
403 | plugin.onShowContextMenu(adtype, ad); |
||
404 | GuildAdsPlugin.addMenuEnabled = nil; |
||
405 | end |
||
406 | end |
||
407 | end |
||
408 | |||
409 | function GuildAdsPlugin_OnEvent(ltype, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) |
||
410 | local method = EventIdToMethod[ltype]; |
||
411 | for pluginName, plugin in GuildAdsPlugin.PluginsList do |
||
412 | if type(plugin[method]) == "function" then |
||
413 | plugin[method](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); |
||
414 | end |
||
415 | end |
||
416 | end |