mirror of
https://github.com/minetest-mods/areas.git
synced 2024-12-25 10:10:41 +01:00
Make find_areas an admin-only command
Some regexes can be very slow. This also fixes a bug with single-item result sets.
This commit is contained in:
parent
9871caf1e2
commit
b3873fcfaf
@ -143,6 +143,7 @@ minetest.register_chatcommand("rename_area", {
|
|||||||
minetest.register_chatcommand("find_areas", {
|
minetest.register_chatcommand("find_areas", {
|
||||||
params = "<regexp>",
|
params = "<regexp>",
|
||||||
description = "Find areas using a Lua regular expression",
|
description = "Find areas using a Lua regular expression",
|
||||||
|
privs = areas.adminPrivs,
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if param == "" then
|
if param == "" then
|
||||||
return false, "A regular expression is required."
|
return false, "A regular expression is required."
|
||||||
@ -158,12 +159,12 @@ minetest.register_chatcommand("find_areas", {
|
|||||||
|
|
||||||
local matches = {}
|
local matches = {}
|
||||||
for id, area in pairs(areas.areas) do
|
for id, area in pairs(areas.areas) do
|
||||||
if areas:isAreaOwner(id, name) and
|
local str = areas:toString(id)
|
||||||
areas:toString(id):find(param) then
|
if str:find(param) then
|
||||||
table.insert(matches, areas:toString(id))
|
table.insert(matches, str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #matches > 1 then
|
if #matches > 0 then
|
||||||
return true, table.concat(matches, "\n")
|
return true, table.concat(matches, "\n")
|
||||||
else
|
else
|
||||||
return true, "No matches found."
|
return true, "No matches found."
|
||||||
|
Loading…
Reference in New Issue
Block a user