-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAPI.lua
155 lines (112 loc) · 4.09 KB
/
API.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
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
-- API.lua
-- Implements the functions that are considered "External API" callable by other plugins
--- Locks an area specified by the coords
-- Returns true on success, false and error ID and error message on failure
-- a_LockedByName is the name of the player locking the area (for information purposes only)
function LockAreaByCoords(a_WorldName, a_BlockX, a_BlockZ, a_LockedByName)
-- Check params:
a_BlockX = tonumber(a_BlockX)
a_BlockZ = tonumber(a_BlockZ)
if (
(type(a_WorldName) ~= "string") or
(type(a_BlockX) ~= "number") or
(type(a_BlockZ) ~= "number") or
(type(a_LockedByName) ~= "string")
) then
return false, "ParamError", "Invalid parameters. Expected string, number, number and string."
end
-- Find the appropriate area:
local Area = g_DB:LoadAreaByPos(a_WorldName, a_BlockX, a_BlockZ)
if (Area == nil) then
return false, "NoAreaHere", "There is no gallery area here"
end
-- If the area is already locked, bail out:
if (Area.IsLocked) then
return false, "AlreadyLocked", "This area has already been locked by " .. Area.LockedBy .. " on " .. Area.DateLocked
end
-- Lock the area:
g_DB:LockArea(Area, a_LockedByName)
ReplaceAreaForAllPlayers(Area)
return true
end
--- Locks an area specified by its ID
-- Returns true on success, false and error ID and error message on failure
-- a_LockedByName is the name of the player locking the area (for information purposes only)
function LockAreaByID(a_AreaID, a_LockedByName)
-- Check params:
a_AreaID = tonumber(a_AreaID)
if (
(type(a_AreaID) ~= "number") or
(type(a_LockedByName) ~= "string")
) then
return false, "ParamError", "Invalid parameters. Expected number and string."
end
-- Find the appropriate area:
local Area = g_DB:LoadAreaByID(a_AreaID)
if (Area == nil) then
return false, "NoSuchArea", "There is no such area"
end
-- If the area is already locked, bail out:
if (Area.IsLocked) then
return false, "AlreadyLocked", "This area has already been locked by " .. Area.LockedBy .. " on " .. Area.DateLocked
end
-- Lock the area:
g_DB:LockArea(Area, a_LockedByName)
ReplaceAreaForAllPlayers(Area)
return true
end
--- Unlocks an area specified by the coords
-- Returns true on success, false and error ID and error message on failure
-- a_UnlockedByName is the name of the player unlocking the area (for information purposes only)
function UnlockAreaByCoords(a_WorldName, a_BlockX, a_BlockZ, a_UnlockedByName)
-- Check params:
a_BlockX = tonumber(a_BlockX)
a_BlockZ = tonumber(a_BlockZ)
if (
(type(a_WorldName) ~= "string") or
(type(a_BlockX) ~= "number") or
(type(a_BlockZ) ~= "number") or
(type(a_UnlockedByName) ~= "string")
) then
return false, "ParamError", "Invalid parameters. Expected string, number, number and string."
end
-- Find the appropriate area:
local Area = g_DB:LoadAreaByPos(a_WorldName, a_BlockX, a_BlockZ)
if (Area == nil) then
return false, "NoAreaHere", "There is no gallery area here"
end
-- If the area isn't locked, bail out:
if not(Area.IsLocked) then
return false, "NotLocked", "This area hasn't been locked."
end
-- Lock the area:
g_DB:UnlockArea(Area, a_UnlockedByName)
ReplaceAreaForAllPlayers(Area)
return true
end
--- Unlocks an area specified by its ID
-- Returns true on success, false and error ID and error message on failure
-- a_LockedByName is the name of the player locking the area (for information purposes only)
function UnlockAreaByID(a_AreaID, a_UnlockedByName)
-- Check params:
a_AreaID = tonumber(a_AreaID)
if (
(type(a_AreaID) ~= "number") or
(type(a_UnlockedByName) ~= "string")
) then
return false, "ParamError", "Invalid parameters. Expected number and string."
end
-- Find the appropriate area:
local Area = g_DB:LoadAreaByID(a_AreaID)
if (Area == nil) then
return false, "NoSuchArea", "There is no such area"
end
-- If the area is already unlocked, bail out:
if not(Area.IsLocked) then
return false, "NotLocked", "This area has already been unlocked by " .. Area.LockedBy .. " on " .. Area.DateLocked
end
-- Unlock the area:
g_DB:UnlockArea(Area, a_UnlockedByName)
ReplaceAreaForAllPlayers(Area)
return true
end