Merge branch 'master' into luacheck-ci

This commit is contained in:
Buckaroo Banzai
2020-06-05 07:02:02 +02:00
committed by GitHub
13 changed files with 35 additions and 20 deletions

View File

@ -102,6 +102,9 @@ Commands
* `/area_pos2 [X,Y,Z|X Y Z]` -- Sets area position two to your position or * `/area_pos2 [X,Y,Z|X Y Z]` -- Sets area position two to your position or
the one supplied. the one supplied.
* `/areas_cleanup` -- Removes all ownerless areas.
Useful for cleaning after user deletion, for example using /remove_player.
License License
------- -------
@ -109,4 +112,3 @@ Copyright (C) 2013 ShadowNinja
Licensed under the GNU LGPL version 2.1 or later. Licensed under the GNU LGPL version 2.1 or later.
See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt

View File

@ -1,6 +1,5 @@
local hudHandlers = {} local hudHandlers = {}
areas.registered_on_adds = {} areas.registered_on_adds = {}
areas.registered_on_removes = {} areas.registered_on_removes = {}
areas.registered_on_moves = {} areas.registered_on_moves = {}
@ -17,13 +16,11 @@ function areas:registerOnMove(func)
table.insert(areas.registered_on_moves, func) table.insert(areas.registered_on_moves, func)
end end
--- Adds a function as a HUD handler, it will be able to add items to the Areas HUD element. --- Adds a function as a HUD handler, it will be able to add items to the Areas HUD element.
function areas:registerHudHandler(handler) function areas:registerHudHandler(handler)
table.insert(hudHandlers, handler) table.insert(hudHandlers, handler)
end end
function areas:getExternalHudEntries(pos) function areas:getExternalHudEntries(pos)
local areas = {} local areas = {}
for _, func in pairs(hudHandlers) do for _, func in pairs(hudHandlers) do

View File

@ -75,8 +75,7 @@ minetest.register_chatcommand("add_owner", {
.." positions that have already been protected," .." positions that have already been protected,"
.." Use set_owner if you don't want the parent to be set."), .." Use set_owner if you don't want the parent to be set."),
func = function(name, param) func = function(name, param)
local pid, ownerName, areaName local pid, ownerName, areaName = param:match('^(%d+) ([^ ]+) (.+)$')
= param:match('^(%d+) ([^ ]+) (.+)$')
if not pid then if not pid then
minetest.chat_send_player(name, S("Invalid usage, see /help @1.", "add_owner")) minetest.chat_send_player(name, S("Invalid usage, see /help @1.", "add_owner"))
@ -419,3 +418,27 @@ minetest.register_chatcommand("area_info", {
end, end,
}) })
minetest.register_chatcommand("areas_cleanup", {
description = S("Removes all ownerless areas"),
privs = areas.adminPrivs,
func = function()
local total, count = 0, 0
local aareas = areas.areas
for id, _ in pairs(aareas) do
local owner = aareas[id].owner
if not areas:player_exists(owner) then
areas:remove(id)
count = count + 1
end
total = total + 1
end
areas:save()
return true, "Total areas: " .. total .. ", Removed " ..
count .. " areas. New count: " .. (total - count)
end
})

View File

@ -4,7 +4,6 @@ areas.hud = {}
areas.hud.refresh = 0 areas.hud.refresh = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
areas.hud.refresh = areas.hud.refresh + dtime areas.hud.refresh = areas.hud.refresh + dtime
if areas.hud.refresh > areas.config["tick"] then if areas.hud.refresh > areas.config["tick"] then
areas.hud.refresh = 0 areas.hud.refresh = 0
@ -69,4 +68,3 @@ end)
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
areas.hud[player:get_player_name()] = nil areas.hud[player:get_player_name()] = nil
end) end)

View File

@ -25,7 +25,7 @@ minetest.register_privilege("areas", {
description = "Can administer areas." description = "Can administer areas."
}) })
minetest.register_privilege("areas_high_limit", { minetest.register_privilege("areas_high_limit", {
description = "Can can more, bigger areas." description = "Can protect more, bigger areas."
}) })
if not minetest.registered_privileges[areas.config.self_protection_privilege] then if not minetest.registered_privileges[areas.config.self_protection_privilege] then
@ -38,4 +38,3 @@ if minetest.settings:get_bool("log_mods") then
local diffTime = os.clock() - areas.startTime local diffTime = os.clock() - areas.startTime
minetest.log("action", "areas loaded in "..diffTime.."s.") minetest.log("action", "areas loaded in "..diffTime.."s.")
end end

View File

@ -17,4 +17,3 @@ minetest.register_on_protection_violation(function(pos, name)
table.concat(owners, ", "))) table.concat(owners, ", ")))
end end
end) end)

View File

@ -150,7 +150,6 @@ function areas:move(id, area, pos1, pos2)
area.pos1 = pos1 area.pos1 = pos1
area.pos2 = pos2 area.pos2 = pos2
for i=1, #areas.registered_on_moves do for i=1, #areas.registered_on_moves do
areas.registered_on_moves[i](id, area, pos1, pos2) areas.registered_on_moves[i](id, area, pos1, pos2)
end end

View File

@ -106,5 +106,3 @@ function areas.hasOwner(pos)
end end
return false return false
end end

View File

@ -65,6 +65,8 @@ You have extended area protection limits ("areas_high_limit" privilege).=
You have the necessary privilege ("@1").= You have the necessary privilege ("@1").=
You need to select an area first.= You need to select an area first.=
Removes all ownerless areas.=
### chatcommands.lua ### ### chatcommands.lua ###
### pos.lua ### ### pos.lua ###

View File

@ -1,4 +1,5 @@
local S = minetest.get_translator("areas") local S = minetest.get_translator("areas")
-- I could depend on WorldEdit for this, but you need to have the 'worldedit' -- I could depend on WorldEdit for this, but you need to have the 'worldedit'
-- permission to use those commands and you don't have -- permission to use those commands and you don't have
-- /area_pos{1,2} [X Y Z|X,Y,Z]. -- /area_pos{1,2} [X Y Z|X,Y,Z].
@ -262,4 +263,3 @@ minetest.register_entity("areas:pos2", {
areas.marker2[name] = nil areas.marker2[name] = nil
end, end,
}) })

View File

@ -43,4 +43,3 @@ file:close()
-------------- --------------
setting("filename", "string", world_path.."/areas.dat") setting("filename", "string", world_path.."/areas.dat")

View File

@ -35,4 +35,3 @@ areas.self_protection_max_size_high (Maximal area size) v3f (512, 512, 512)
# Only enter positive whole numbers for the coordinate values or you'll mess up stuff. # Only enter positive whole numbers for the coordinate values or you'll mess up stuff.
# This setting applies for plyaers with the privilege 'areas_high_limit' # This setting applies for plyaers with the privilege 'areas_high_limit'
areas.self_protection_max_areas_high (Maximal area count) float 32 areas.self_protection_max_areas_high (Maximal area count) float 32