-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.lua
216 lines (192 loc) · 5.57 KB
/
init.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
--
-- Chat commands
--
local function execute_chatcommand(pname, cmd)
for _,func in pairs(minetest.registered_on_chat_messages) do
func(pname, cmd)
end
end
minetest.register_chatcommand("run_as", {
params = "<playername> /<command>",
description =
"Run a chatcommand as another player,\n" ..
"chat messages are captured and are not sent to the other player.",
privs = {server=true},
func = function(name, param)
local playername, msg = param:match"^([^ ]+) *(/.*)"
if not playername then
return false, "Invalid parameters (see /help run_as)."
end
-- capture chat messages
local actual_chatsend = minetest.chat_send_player
function minetest.chat_send_player(cname, chat_msg)
if cname == playername then
cname = name
end
return actual_chatsend(cname, chat_msg)
end
execute_chatcommand(playername, msg)
minetest.chat_send_player = actual_chatsend
end,
})
minetest.register_chatcommand("grantme", {
params = "<privilege>|all",
description = "Give privilege to yourself",
func = function(name, param)
if param == "" then
return false, "Invalid parameters (see /help grantme)."
end
execute_chatcommand(name, "/grant "..name.." "..param)
end,
})
minetest.register_chatcommand("grantall", {
params = "<privilege>|all",
description = "Give privilege to all players online",
func = function(name, param)
if param == "" then
return false, "Invalid parameters (see /help grantall)"
end
for _,player in pairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
execute_chatcommand(name, "/grant "..playername.." "..param)
end
minetest.log("action", name..' granted everyone ('..param..')')
return true, "You granted everyone: "..param
end,
})
minetest.register_chatcommand("kickall", {
params = "[reason]",
description = "kick all player but the caller",
privs = {kick=true},
func = function(name, reason)
for _,player in pairs(minetest.get_connected_players()) do
local tokick = player:get_player_name()
if tokick ~= name then
execute_chatcommand(name, "/kick "..tokick.." "..reason)
end
end
local log_message = name .. " kicks everyone"
if reason
and reason ~= "" then
log_message = log_message.." with reason \"" .. reason .. "\""
end
minetest.log("action", log_message)
return true, "Kicked everyone but you"
end,
})
minetest.register_chatcommand("revokeall", {
params = "<privilege>|all",
description = "Revoke privilege from all other players online",
func = function(name, param)
if param == "" then
return false, "Invalid parameters (see /help revokeall)"
end
for _,player in pairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
if playername ~= name then
execute_chatcommand(name, "/revoke "..playername.." "..param)
end
end
minetest.log("action", name..' revoked ('..param..') from everyone')
return true, "You revoked:"..param.." from everyone"
end,
})
minetest.register_chatcommand("revokeme", {
params = "<privilege>|all",
description = "Revoke privilege from yourself",
func = function(name, param)
if param == "" then
return false, "Invalid parameters (see /help revokeall)"
end
execute_chatcommand(name, "/revoke "..name.." "..param)
end,
})
minetest.register_chatcommand("giveall", {
params = "<privilege>|all",
description = "Give item to all players online",
func = function(name, param)
if param == "" then
return false, "Invalid parameters (see /help giveall)"
end
for _,player in pairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
execute_chatcommand(name, "/give "..playername.." "..param)
end
minetest.log("action", name..' given everyone ('..param..')')
return true, "You given everyone: "..param
end,
})
minetest.register_chatcommand("listitems", {
params = "<regexp>",
description = "Find names of registered items",
privs = {},
func = function(_, param)
local names = {}
for itemname in pairs(minetest.registered_items) do
if string.find(itemname, param) then
names[#names+1] = itemname
end
end
table.sort(names)
-- make every second itemname red to increase readability
for i = 2, #names, 2 do
names[i] = minetest.colorize("#ffaaaa", names[i])
end
return true, table.concat(names, ", ")
end,
})
if minetest.global_exists("worldedit") then
local liquids
local function get_liquids()
if liquids then
return liquids
end
local lliquids,n = {},1
for name,def in pairs(minetest.registered_nodes) do
if def.drawtype == "liquid"
or def.drawtype == "flowingliquid" then
lliquids[n] = name
n = n+1
end
end
liquids = lliquids
return lliquids
end
minetest.register_chatcommand("/drain", {
params = "",
description = "Remove any fluid node within the WorldEdit region",
privs = {worldedit=true},
func = function(name)
for _,nodename in pairs(get_liquids()) do
execute_chatcommand(name, "//replace "..nodename.." air")
execute_chatcommand(name, "//y")
end
end,
})
local fires
local function get_fires()
if fires then
return fires
end
local lfires,n = {},1
for name,def in pairs(minetest.registered_nodes) do
if def.drawtype == "firelike" then
lfires[n] = name
n = n+1
end
end
fires = lfires
return lfires
end
minetest.register_chatcommand("/extinguish", {
params = "",
description = "Remove any fire node within the WorldEdit region",
privs = {worldedit=true},
func = function(name)
for _,nodename in pairs(get_fires()) do
execute_chatcommand(name, "//replace "..nodename.." air")
execute_chatcommand(name, "//y")
end
end,
})
end