diff --git a/chatcommands.lua b/chatcommands.lua index 5a0b007..07620d9 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -17,9 +17,9 @@ minetest.register_chatcommand("creative_region", { local data = region_name local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data)) if astore_id then - creative_regions:set_region_privs("r"..tostring(astore_id), nil) + creative_regions.set_region_privs("r"..tostring(astore_id), nil) minetest.chat_send_player(name, "[creative_regions] New region set. ID: " .. "r"..astore_id) - creative_regions:save_regions() + creative_regions.save_regions() return true, "Done" else return false, "Failed" @@ -41,9 +41,9 @@ minetest.register_chatcommand("creative_region_privs", { return false, "Syntax error" end - creative_regions:set_region_privs(tostring(region_id), privstring) + creative_regions.set_region_privs(tostring(region_id), privstring) minetest.chat_send_player(name, "[creative_regions] Privstring set for region " .. region_id .. ": " .. privstring) - creative_regions:save_regions() + creative_regions.save_regions() return true, "Done" end, }) @@ -65,12 +65,12 @@ minetest.register_chatcommand("creative_region_rm", { local success = creative_regions.astore:remove_area(astore_id) if success then minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "removed") - creative_regions:set_region_privs(tostring(region_id), nil) + creative_regions.set_region_privs(tostring(region_id), nil) else minetest.chat_send_player(name, "Failed to remove region " .. region_id) return false, "Region not found" end - creative_regions:save_regions() + creative_regions.save_regions() return true, "Done." end, }) diff --git a/init.lua b/init.lua index b349efe..0aa0024 100644 --- a/init.lua +++ b/init.lua @@ -37,7 +37,7 @@ function creative_regions:update_player(player) end -- find active regions - local current_regions = self.astore:get_areas_for_pos(pos, true, true) + local current_regions = creative_regions.astore:get_areas_for_pos(pos, true, true) for astore_id, astore_area in pairs( current_regions ) do local id = "r"..tostring(astore_id) local size = creative_regions:get_region_size(astore_area) @@ -100,7 +100,7 @@ function creative_regions:update_player(player) end -creative_regions:load_regions() +creative_regions.load_regions() local timer = 0 minetest.register_globalstep(function(dtime) diff --git a/items.lua b/items.lua index e69de29..842174a 100644 --- a/items.lua +++ b/items.lua @@ -0,0 +1,96 @@ +if minetest.get_modpath("areas") then + + function creative_regions.protector_set_noflyzone(pos, placer, itemstack, pointed_thing) + if not pos or not placer then + return + end + local meta = minetest.get_meta(pos) + local name = placer:get_player_name(); + local player_owns_id = nil + + local current_areas = areas:getAreasAtPos(pos) + for areas_id, areas_area in pairs( current_areas ) do + if areas_area.owner == name then + player_owns_id = "a"..tostring(areas_id) + break + end + end + + if player_owns_id then + meta:set_string("infotext", string.format("No-Fly-Zone Protector for area %s owned by %s", player_owns_id, name) + meta:set_string("area_id", player_owns_id) + meta:set_string("owner", name) + + creative_regions.set_region_privs(tostring(player_owns_id), "-fast, -fly") + minetest.chat_send_player(name, "[creative_regions] No-Fly-Zone set for region " .. player_owns_id) + creative_regions.save_regions() + else + minetest.after(0.2, function(pos) + minetest.remove_node(pos) + end, pos) + end + + end + + function creative_regions.protector_can_dig(pos, player) + if not pos or not player then + return true + end + local name = player:get_player_name() + local meta = minetest.get_meta(pos) + local id = meta:get_string("area_id") + local owner = meta:get_string("owner") + + local player_owns_id = nil + + local current_areas = areas:getAreasAtPos(pos) + for areas_id, areas_area in pairs( current_areas ) do + if areas_area.owner == name then + player_owns_id = "a"..tostring(areas_id) + break + end + end + + if player_owns_id then + return true + else + minetest.chat_send_player(name, "[creative_regions] Cannot remove No-Fly-Zone "..id.." owned by "..owner) + return false + end + + end + + function creative_regions.protector_remove_noflyzone(pos, oldnode, oldmetadata, digger) + if not oldmetadata or not oldmetadata.fields then + return + end + local owner = oldmetadata.fields.owner + local stored_id = oldmetadata.fields.area_id + local name = digger:get_player_name() + + local current_areas = areas:getAreasAtPos(pos) + for areas_id, areas_area in pairs( current_areas ) do + local id = "a"..tostring(areas_id) + if stored_id == id then + creative_regions.set_region_privs(tostring(id), nil) + minetest.chat_send_player(name, "[creative_regions] No-Fly-Zone for area " .. id .. " removed") + creative_regions.save_regions() + end + end + + end + + minetest.register_node("creative_regions:protector_nofly", { + description = "No-Fly-Zone Protector", + tiles = {"creative_regions_protector_nofly.png"}, + is_ground_content = true, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=1}, + light_source = 1, + after_place_node = creative_regions.protector_set_noflyzone, + can_dig = creative_regions.protector_can_dig, + after_dig_node = creative_regions.protector_remove_noflyzone, + }) + + --minetest.register_alias("noflyzone", "creative_regions:noflyprotector") + +end diff --git a/region.lua b/region.lua index b84ce76..59b1444 100644 --- a/region.lua +++ b/region.lua @@ -3,19 +3,19 @@ creative_regions.mod_storage = minetest.get_mod_storage() creative_regions.region_privs = {} -function creative_regions:load_regions() - self.astore:from_file(minetest.get_worldpath().."/creative_regions_regions") +function creative_regions.load_regions() + creative_regions.astore:from_file(minetest.get_worldpath().."/creative_regions_regions") creative_regions.region_privs = minetest.deserialize(creative_regions.mod_storage:get_string("astore_privs")) or {} -- local edge1 = { x=-10, y=-10, z=-10 } -- local edge2 = { x=10, y=10, z=10 } -- local data = "Testregion" --- local astore_id = self.astore:insert_area(edge1, edge2, tostring(data)) +-- local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data)) -- --- creative_regions:set_region_privs("r"..astore_id, "+creative, +fast, +fly") +-- creative_regions.set_region_privs("r"..astore_id, "+creative, +fast, +fly") end -function creative_regions:save_regions() - self.astore:to_file(minetest.get_worldpath().."/creative_regions_regions") +function creative_regions.save_regions() + creative_regions.astore:to_file(minetest.get_worldpath().."/creative_regions_regions") local datastr = minetest.serialize(creative_regions.region_privs) if not datastr then minetest.log("error", "[creative_regions] Failed to serialize region_privs data!") @@ -32,7 +32,7 @@ function creative_regions:get_region_size(astore_area) return x*z end -function creative_regions:set_region_privs(id, privs_string) +function creative_regions.set_region_privs(id, privs_string) creative_regions.region_privs[tostring(id)] = privs_string end diff --git a/settingtypes.txt b/settingtypes.txt index 55f1dd0..25f261c 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -2,7 +2,7 @@ creative_regions.owner_privs (Owner privs) string "+creative, +fast, +fly" # Privs of an areas mod guest -creative_regions.guest_privs (Guest privs) string "-fly, -fast" +creative_regions.guest_privs (Guest privs) string "-fast, -fly" # Default privs when not in an area creative_regions.noregion_privs (Noregion default privs) string "-creative, -fast, -fly" diff --git a/textures/creative_regions_protector_nofly.png b/textures/creative_regions_protector_nofly.png new file mode 100644 index 0000000..ccc3e5c Binary files /dev/null and b/textures/creative_regions_protector_nofly.png differ