summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/HookNotify/HookNotify.lua
blob: 519d837fe47177c269fc324504da7a02f88094f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344

-- Global variables
PLUGIN = {}	-- Reference to own plugin object





function Initialize(Plugin)
	PLUGIN = Plugin
	
	Plugin:SetName("HookNotify")
	Plugin:SetVersion(1)
	
	PluginManager = cRoot:Get():GetPluginManager()
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_TO_PICKUPS);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATING);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_COLLECT_PICKUP);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_DISCONNECT);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_HANDSHAKE);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLED);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_LOGIN);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BREAKING_BLOCK);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BROKEN_BLOCK);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_EATING);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_JOINED);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_LEFT_CLICK);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_MOVING);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_PLACED_BLOCK);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_PLACING_BLOCK);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICK);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_SHOOTING);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_SPAWNED);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_TOSSING_ITEM);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USED_BLOCK);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USED_ITEM);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_BLOCK);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_POST_CRAFTING);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_PRE_CRAFTING);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_UPDATED_SIGN);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_UPDATING_SIGN);
	PluginManager:AddHook(Plugin, cPluginManager.HOOK_WEATHER_CHANGED);
	
	LOGINFO("HookNotify plugin is installed, beware, the log output may be quite large!");
	LOGINFO("You want this plugin enabled only when developing another plugin, not for regular gameplay.");
	
	return true
end





function LogHook(FnName, ...)
	LOG(FnName .. "(");
	for i, v in ipairs(arg) do
		local vt = tostring(v);
		local TypeString = type(v);
		if (type(v) == "userdata") then
			TypeString = tolua.type(v);
		end;
		LOG("  " .. tostring(i) .. ": " .. TypeString .. ": " .. tostring(v));
	end
	LOG(")");
end





function OnBlockToPickups(...)
	LOG("************************");
	LogHook("OnBlockToPickups", unpack(arg));
	LOG("========================");
end;





function OnChat(...)
	LogHook("OnChat", unpack(arg));
end





function OnChunkGenerated(...)
	LogHook("OnChunkGenerated", unpack(arg));
end





function OnChunkGenerating(...)
	LogHook("OnChunkGenerating", unpack(arg));
end





function OnPlayerUsingItem(...)
	LogHook("OnPlayerUsingItem", unpack(arg));
end





function OnCollectPickup(...)
	LogHook("OnCollectPickup", unpack(arg));
end




function OnCraftingNoRecipe(...)
	LogHook("OnCraftingNoRecipe", unpack(arg));
end





function OnDisconnect(...)
	LogHook("OnDisconnect", unpack(arg));
end





function OnHandshake(...)
	LogHook("OnHandshake", unpack(arg));
end





function OnKilled(...)
	LogHook("OnKilled", unpack(arg));
end





function OnLogin(...)
	LogHook("OnLogin", unpack(arg));
end





function OnPlayerBreakingBlock(...)
	LogHook("OnPlayerBreakingBlock", unpack(arg));
end





function OnPlayerBrokenBlock(...)
	LogHook("OnPlayerBrokenBlock", unpack(arg));
end





function OnPlayerEating(...)
	LogHook("OnPlayerEating", unpack(arg));
end





function OnPlayerJoined(...)
	LogHook("OnPlayerJoined", unpack(arg));
end





function OnPlayerLeftClick(...)
	LogHook("OnPlayerLeftClick", unpack(arg));
end





function OnPlayerMoving(...)
	LogHook("OnPlayerMoving", unpack(arg));
end





function OnPlayerPlacedBlock(...)
	LogHook("OnPlayerPlacedBlock", unpack(arg));
end





function OnPlayerPlacingBlock(...)
	LogHook("OnPlayerPlacingBlock", unpack(arg));
end





function OnPlayerRightClick(...)
	LogHook("OnPlayerRightClick", unpack(arg));
end





function OnPlayerShooting(...)
	LogHook("OnPlayerShooting", unpack(arg));
end





function OnPlayerSpawned(...)
	LogHook("OnPlayerSpawned", unpack(arg));
end





function OnPlayerTossingItem(...)
	LogHook("OnPlayerTossingItem", unpack(arg));
end





function OnPlayerUsedBlock(...)
	LogHook("OnPlayerUsedBlock", unpack(arg));
end





function OnPlayerUsedItem(...)
	LogHook("OnPlayerUsedItem", unpack(arg));
end





function OnPlayerUsingBlock(...)
	LogHook("OnPlayerUsingBlock", unpack(arg));
end





function OnPlayerUsingItem(...)
	LogHook("OnPlayerUsingItem", unpack(arg));
end





function OnPostCrafting(...)
	LogHook("OnPostCrafting", unpack(arg));
end





function OnPreCrafting(...)
	LogHook("OnPreCrafting", unpack(arg));
end





function OnUpdatedSign(...)
	LogHook("OnUpdatedSign", unpack(arg));
end





function OnUpdatingSign(...)
	LogHook("OnUpdatingSign", unpack(arg));
end





function OnWeatherChanged(...)
	LogHook("OnWeatherChanged", unpack(arg));
end





------------------------------------------------------------------
-- Special handling for OnTakeDamage to print the contents of TDI:

function OnTakeDamage(Receiver, TDI)
	-- Receiver is cPawn
	-- TDI is TakeDamageInfo

	LOG("OnTakeDamage(): " .. Receiver:GetClass() .. " was dealt RawDamage " .. TDI.RawDamage .. ", FinalDamage " .. TDI.FinalDamage .. " (that is, " .. (TDI.RawDamage - TDI.FinalDamage) .. " HPs covered by armor)");
end