-
Notifications
You must be signed in to change notification settings - Fork 5
/
admin.lua
240 lines (176 loc) · 5.31 KB
/
admin.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
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
local S = protector.intllib
local removal_names = ""
local replace_names = ""
minetest.register_chatcommand("protector_remove", {
params = S("<names list>"),
description = S("Remove Protectors around players (separate names with spaces)"),
privs = {server = true},
func = function(name, param)
if not param or param == "" then
minetest.chat_send_player(name,
S("Protector Names to remove: @1",
removal_names))
return
end
if param == "-" then
minetest.chat_send_player(name,
S("Name List Reset"))
removal_names = ""
return
end
removal_names = param
end
})
minetest.register_chatcommand("protector_replace", {
params = S("<owner name> <name to replace with>"),
description = S("Replace Protector Owner with name provided"),
privs = {server = true},
func = function(name, param)
-- reset list to empty
if param == "-" then
minetest.chat_send_player(name, S("Name List Reset"))
replace_names = ""
return
end
-- show name info
if param == ""
and replace_names ~= "" then
local names = replace_names:split(" ")
minetest.chat_send_player(name,
S("Replacing Protector name @1 with @2",
names[1] or "", names[2] or ""))
return
end
replace_names = param
end
})
minetest.register_abm({
nodenames = {"protector:protect", "protector:protect2", "protector:protect_hidden"},
interval = 6,
chance = 1,
catch_up = false,
action = function(pos, node)
if removal_names == ""
and replace_names == "" then
return
end
local meta = minetest.get_meta(pos)
if not meta then return end
local owner = meta:get_string("owner")
if removal_names ~= "" then
local names = removal_names:split(" ")
for _, n in pairs(names) do
if n == owner then
minetest.set_node(pos, {name = "air"})
end
end
end
if replace_names ~= "" then
local names = replace_names:split(" ")
if names[1] and names[2] and owner == names[1] then
meta:set_string("owner", names[2])
meta:set_string("infotext", S("Protection (owned by @1)", names[2]))
end
end
end
})
-- get protection radius
local r = tonumber(minetest.settings:get("protector_radius")) or 5
-- show protection areas of nearby protectors owned by you (thanks agaran)
minetest.register_chatcommand("protector_show_area", {
params = "",
description = S("Show protected areas of your nearby protectors"),
privs = {},
func = function(name, param)
local player = minetest.get_player_by_name(name)
local ppos = player:get_pos()
-- find the protector nodes
local pos = minetest.find_nodes_in_area(
{x = ppos.x - r, y = ppos.y - r, z = ppos.z - r},
{x = ppos.x + r, y = ppos.y + r, z = ppos.z + r},
{"protector:protect", "protector:protect2", "protector:protect_hidden"})
local meta, owner
-- show a maximum of 5 protected areas only
for n = 1, math.min(#pos, 5) do
meta = minetest.get_meta(pos[n])
owner = meta:get_string("owner") or ""
if owner == name
or minetest.check_player_privs(name, {protection_bypass = true}) then
minetest.add_entity(pos[n], "protector:display")
end
end
end
})
-- ability to hide protection blocks (borrowed from doors mod :)
minetest.register_node("protector:protect_hidden", {
description = "Hidden Protector",
drawtype = "airlike",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
-- has to be walkable for falling nodes to stop falling
walkable = true,
pointable = false,
diggable = false,
buildable_to = false,
floodable = false,
drop = "",
groups = {not_in_creative_inventory = 1, unbreakable = 1},
is_ground_content = false,
on_blast = function() end,
-- 1px block inside door hinge near node top
collision_box = {
type = "fixed",
fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32}
}
})
minetest.register_chatcommand("protector_show", {
params = "",
description = S("Show your nearby protection blocks"),
privs = {interact = true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
local pos = player:get_pos()
local a = minetest.find_nodes_in_area(
{x = pos.x - r, y = pos.y - r, z = pos.z - r},
{x = pos.x + r, y = pos.y + r, z = pos.z + r},
{"protector:protect_hidden"})
local meta, owner
for _, row in pairs(a) do
meta = minetest.get_meta(row)
owner = meta:get_string("owner") or ""
if owner == name
or minetest.check_player_privs(name, {protection_bypass = true}) then
minetest.swap_node(row, {name = "protector:protect"})
end
end
end
})
minetest.register_chatcommand("protector_hide", {
params = "",
description = S("Hide your nearby protection blocks"),
privs = {interact = true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
local pos = player:get_pos()
local a = minetest.find_nodes_in_area(
{x = pos.x - r, y = pos.y - r, z = pos.z - r},
{x = pos.x + r, y = pos.y + r, z = pos.z + r},
{"protector:protect", "protector:protect2"})
local meta, owner
for _, row in pairs(a) do
meta = minetest.get_meta(row)
owner = meta:get_string("owner") or ""
if owner == name
or minetest.check_player_privs(name, {protection_bypass = true}) then
minetest.swap_node(row, {name = "protector:protect_hidden"})
end
end
end
})