mirror of
https://github.com/minetest-mods/areas.git
synced 2024-12-21 20:42:21 +01:00
Short summary print in /list_areas for admins (#72)
This commit is contained in:
parent
2c900ef2cd
commit
c044d49d21
@ -173,13 +173,46 @@ minetest.register_chatcommand("find_areas", {
|
|||||||
|
|
||||||
|
|
||||||
minetest.register_chatcommand("list_areas", {
|
minetest.register_chatcommand("list_areas", {
|
||||||
description = S("List your areas, or all areas if you are an admin."),
|
params = S("[<name>]"),
|
||||||
|
description = S("List your areas. Admins can list all areas or those of a specific player."),
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local admin = minetest.check_player_privs(name, areas.adminPrivs)
|
local admin = minetest.check_player_privs(name, areas.adminPrivs)
|
||||||
|
local admin_show_summary = admin
|
||||||
|
local owner_name = name
|
||||||
|
|
||||||
|
if admin and #param > 0 then
|
||||||
|
owner_name = param
|
||||||
|
admin_show_summary = false
|
||||||
|
end
|
||||||
|
|
||||||
local areaStrings = {}
|
local areaStrings = {}
|
||||||
for id, area in pairs(areas.areas) do
|
if admin_show_summary then
|
||||||
if admin or areas:isAreaOwner(id, name) then
|
-- Summary per-player
|
||||||
table.insert(areaStrings, areas:toString(id))
|
local indices = {}
|
||||||
|
local counts = {} -- { [1] = name, [2] = count }, ...
|
||||||
|
for _, area in pairs(areas.areas) do
|
||||||
|
local i = indices[area.owner]
|
||||||
|
if i then
|
||||||
|
counts[i][2] = counts[i][2] + 1
|
||||||
|
else
|
||||||
|
table.insert(counts, { area.owner, 1 })
|
||||||
|
indices[area.owner] = #counts
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Alphabatical name sorting
|
||||||
|
table.sort(counts, function (kv_a, kv_b)
|
||||||
|
return kv_a[1] < kv_b[1]
|
||||||
|
end)
|
||||||
|
-- Output
|
||||||
|
for _, kv in ipairs(counts) do
|
||||||
|
table.insert(areaStrings, S("@1 : @2 area(s)", kv[1], kv[2]))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Detailed list
|
||||||
|
for id, area in pairs(areas.areas) do
|
||||||
|
if areas:isAreaOwner(id, owner_name) then
|
||||||
|
table.insert(areaStrings, areas:toString(id))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #areaStrings == 0 then
|
if #areaStrings == 0 then
|
||||||
|
Loading…
Reference in New Issue
Block a user