-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.lua
104 lines (63 loc) · 2.34 KB
/
hooks.lua
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
function InitHooks()
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_BREAKING_BLOCK, OnPlayerBreakingBlock)
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_PLACING_BLOCK, OnPlayerPlacingBlock)
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, OnPlayerRightClick);
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, OnPlayerLeftClick);
if (g_Config.LogNature) then
cPluginManager:AddHook(cPluginManager.HOOK_BLOCK_SPREAD, OnBlockSpread);
end
end
function OnBlockSpread(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source)
local SourceName = "#" .. (
(a_Source == ssFireSpread) and "fire" or
(a_Source == ssGrassSpread) and "grass" or
(a_Source == ssMushroomSpread) and "mushroom" or
(a_Source == ssMycelSpread) and "mycelium" or
(a_Source == ssVineSpread) and "vine")
g_Storage:InsertChange(
a_World:GetName(),
SourceName,
a_BlockX, a_BlockY, a_BlockZ,
a_World:GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_World:GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ),
"spread"
)
end
function OnPlayerBreakingBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta)
local World = a_Player:GetWorld()
g_Storage:InsertChange(
World:GetName(),
a_Player:GetName(),
a_BlockX, a_BlockY, a_BlockZ,
World:GetBlock(a_BlockX, a_BlockY, a_BlockZ), World:GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ),
"broken"
)
end
function OnPlayerPlacingBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta)
g_Storage:InsertChange(
a_Player:GetWorld():GetName(),
a_Player:GetName(),
a_BlockX, a_BlockY, a_BlockZ,
0, 0,
"placed"
)
end
function OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ)
if (a_BlockFace == BLOCK_FACE_NONE) then
return false
end
a_BlockX, a_BlockY, a_BlockZ = AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace)
local PlayerState = GetPlayerState(a_Player:GetName())
if (not PlayerState:IsInspecting()) then
return false
end
SendChangesAt(a_Player, a_BlockX, a_BlockY, a_BlockZ)
return true
end
function OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Action)
local PlayerState = GetPlayerState(a_Player:GetName())
if (not PlayerState:IsInspecting()) then
return false
end
SendChangesAt(a_Player, a_BlockX, a_BlockY, a_BlockZ)
return true
end