diff --git a/protector.lua b/protector.lua index 92be47b..a9db3fd 100644 --- a/protector.lua +++ b/protector.lua @@ -37,23 +37,26 @@ minetest.register_node(":areasprotector:protector", { local pos1 = vector.add(pos, vector.new(radius, radius, radius)) local pos2 = vector.add(pos, vector.new(-1 * radius, -1 * radius, -1 * radius)) local name = player:get_player_name() - local perm, err = areas:canPlayerAddArea(pos1, pos2, name) - if not perm then - minetest.chat_send_player(name, red("You are not allowed to protect that area: ") .. err) + + if not minetest.is_protected_action(pos, name) then + local perm, err = areas:canPlayerAddArea(pos1, pos2, name) + if not perm then + minetest.chat_send_player(name, red("You are not allowed to protect that area: ") .. err) + return itemstack + end + local id = areas:add(name, "Protected by Protector Block", pos1, pos2) + areas:save() + local msg = string.format("The area from %s to %s has been protected as #%s", cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id)) + minetest.chat_send_player(name, msg) + minetest.set_node(pos, {name = "areasprotector:protector"}) + local meta = minetest.get_meta(pos) + local infotext = string.format("Protecting area %d owned by %s", id, name) + meta:set_string("infotext", infotext) + meta:set_int("area_id", id) + meta:set_string("owner", name) + itemstack:take_item() return itemstack end - local id = areas:add(name, "Protected by Protector Block", pos1, pos2) - areas:save() - local msg = string.format("The area from %s to %s has been protected as #%s", cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id)) - minetest.chat_send_player(name, msg) - minetest.set_node(pos, {name = "areasprotector:protector"}) - local meta = minetest.get_meta(pos) - local infotext = string.format("Protecting area %d owned by %s", id, name) - meta:set_string("infotext", infotext) - meta:set_int("area_id", id) - meta:set_string("owner", name) - itemstack:take_item() - return itemstack end, after_dig_node = function(pos, oldnode, oldmetadata, digger)