Minor code fixes and cleanup

master
MoNTE48 2020-02-27 22:17:52 +01:00
parent 86e3170ad7
commit ca1ec9fcdf
8 changed files with 30 additions and 22 deletions

View File

@ -16,13 +16,11 @@ function areas:registerOnMove(func)
table.insert(areas.registered_on_moves, func)
end
--- Adds a function as a HUD handler, it will be able to add items to the Areas HUD element.
function areas:registerHudHandler(handler)
table.insert(hudHandlers, handler)
end
function areas:getExternalHudEntries(pos)
local areas = {}
for _, func in pairs(hudHandlers) do
@ -113,7 +111,7 @@ end
-- Note that this fails and returns false when the specified area is fully
-- owned by the player, but with multiple protection zones, none of which
-- cover the entire checked area.
-- @param name (optional) Player name. If not specified checks for any intersecting areas.
-- @param name (optional) Player name. If not specified checks for any intersecting areas.
-- @param allow_open Whether open areas should be counted as if they didn't exist.
-- @return Boolean indicating whether the player can interact in that area.
-- @return Un-owned intersecting area ID, if found.

View File

@ -1,4 +1,3 @@
minetest.register_chatcommand("protect", {
params = "<AreaName>",
description = "Protect your own area",
@ -75,7 +74,7 @@ minetest.register_chatcommand("set_owner", {
minetest.register_chatcommand("add_owner", {
params = "<ParentID> <Player> <AreaName>",
description = "Give a player access to a sub-area beetween two"
description = "Give a player access to a sub-area between two"
.." positions that have already been protected,"
.." Use set_owner if you don't want the parent to be set.",
func = function(name, param)
@ -167,7 +166,12 @@ minetest.register_chatcommand("find_areas", {
if str:find(param) then
table.insert(matches, str)
end
if #matches > 10 then
break
end
end
if #matches > 0 then
return true, table.concat(matches, "\n")
else
@ -193,7 +197,10 @@ minetest.register_chatcommand("list_areas", {
end
if #areaStrings == 0 then
return true, "No visible areas."
end
elseif #areaStrings > 100 then
return true, "Too many areas to list."
end
return true, table.concat(areaStrings, "\n")
end
})

View File

@ -36,4 +36,3 @@ if minetest.settings:get_bool("log_mods") then
local diffTime = os.clock() - areas.startTime
minetest.log("action", "areas loaded in "..diffTime.."s.")
end

View File

@ -46,7 +46,7 @@ end
function areas:checkAreaStoreId(sid)
if not sid then
minetest.log("error", "AreaStore failed to find an ID for an "
.."area! Falling back to iterative area checking.")
.."area! Falling back to iterative area checking.")
self.store = nil
self.store_ids = nil
end
@ -237,7 +237,7 @@ function areas:canPlayerAddArea(pos1, pos2, name)
self.config.self_protection_max_areas
if count >= max_areas then
return false, "You have reached the maximum amount of"
.." areas that you are allowed to protect."
.." areas that you are allowed to protect."
end
-- Check intersecting areas

View File

@ -8,13 +8,13 @@ local function red(str)
return minetest.colorize("#FF5555", str)
end
minetest.register_node(":areasprotector:protector", {
minetest.register_node("areas:protector", {
description = "Protector Block",
groups = {cracky = 1},
tiles = {
"default_stonebrick_carved.png",
"default_stonebrick_carved.png",
"default_stonebrick_carved.png^areasprotector_stone.png"
"default_stonebrick_carved.png^areas_protector_stone.png"
},
paramtype = "light",
drawtype = "nodebox",
@ -40,7 +40,7 @@ minetest.register_node(":areasprotector:protector", {
minetest.chat_send_player(name,
("The area from %s to %s has been protected as #%s")
:format(cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id)))
minetest.set_node(pos, {name = "areasprotector:protector"})
minetest.set_node(pos, {name = "areas:protector"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext", ("Protecting area %d, Owned by %s"):format(id, name))
meta:set_int("area_id", id)
@ -66,29 +66,29 @@ minetest.register_node(":areasprotector:protector", {
local objs = minetest.get_objects_inside_radius(pos, .5) -- a radius of .5 since the entity serialization seems to be not that precise
local displayed = false
for _, o in pairs(objs) do
if not o:is_player() and o:get_luaentity().name == "areasprotector:display" then
if not o:is_player() and o:get_luaentity().name == "areas:display" then
o:remove()
return
end
end
if not displayed then -- nothing was removed: there wasn't the entity
minetest.add_entity(pos, "areasprotector:display")
minetest.add_entity(pos, "areas:display")
end
end
})
-- entities code below (and above) mostly copied-pasted from Zeg9's protector mod
minetest.register_entity(":areasprotector:display", {
minetest.register_entity("areas:display", {
physical = false,
collisionbox = {0},
visual = "wielditem",
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5}, -- wielditem seems to be scaled to 1.5 times original node size
textures = {"areasprotector:display_node"},
textures = {"areas:display_node"},
timer = 0,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 4 or minetest.get_node(self.object:getpos()).name ~= "areasprotector:protector" then
if self.timer > 4 or minetest.get_node(self.object:getpos()).name ~= "areas:protector" then
self.object:remove()
end
end
@ -96,8 +96,8 @@ minetest.register_entity(":areasprotector:display", {
local nb_radius = radius + 0.55
minetest.register_node(":areasprotector:display_node", {
tiles = {"areasprotector_display.png"},
minetest.register_node("areas:display_node", {
tiles = {"areas_protector_display.png"},
walkable = false,
drawtype = "nodebox",
node_box = {
@ -123,7 +123,7 @@ minetest.register_node(":areasprotector:display_node", {
})
minetest.register_craft({
output = "areasprotector:protector",
output = "areas:protector",
type = "shapeless",
recipe = {
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved",
@ -131,3 +131,7 @@ minetest.register_craft({
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved"
}
})
-- Aliases
minetest.register_alias("areasprotector:protector", "areas:protector")
minetest.register_alias("areasprotector:display_node", "areas:display_node")

View File

@ -32,11 +32,11 @@ setting("string", "filename", world_path.."/areas.dat")
-- within the maximum size and number.
setting("boolean", "self_protection", true)
setting("string", "self_protection_privilege", "interact")
setting("position", "self_protection_max_size", {x = 64, y = 128, z = 64})
setting("position", "self_protection_max_size", {x = 64, y = 128, z = 64})
setting("number", "self_protection_max_areas", 4)
-- For players with the areas_high_limit privilege.
setting("position", "self_protection_max_size_high", {x = 512, y = 512, z = 512})
setting("number", "self_protection_max_areas_high", 32)
-- configure the refresh delay for the name displays in the HUD
setting("number", "tick", 1)
setting("number", "tick", 1)

View File

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 88 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB