Compare commits
	
		
			22 Commits
		
	
	
		
			nalc-1.0
			...
			57f20bb25f
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 57f20bb25f | |||
| feae9967dc | |||
|  | aca830fd22 | ||
|  | 95c1165e28 | ||
|  | 5527dc8945 | ||
|  | 6218e5884d | ||
|  | cfd4bb2423 | ||
|  | 6e2b9a0a51 | ||
|  | 024424ee8b | ||
|  | f70600db30 | ||
|  | 9508a004d0 | ||
|  | 630bdefd98 | ||
|  | a303abe51b | ||
|  | 7b51f84404 | ||
|  | 1bbb997c7a | ||
|  | 09c030352f | ||
|  | 2637876555 | ||
|  | 289d0e623c | ||
|  | d3d43d9511 | ||
|  | 6080ff065e | ||
|  | 23f81f6278 | ||
|  | 7cb8787beb | 
							
								
								
									
										19
									
								
								.luacheckrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								.luacheckrc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | unused_args = false | ||||||
|  | allow_defined_top = true | ||||||
|  |  | ||||||
|  | read_globals = { | ||||||
|  | 	"DIR_DELIM", | ||||||
|  | 	"core", | ||||||
|  | 	"dump", | ||||||
|  | 	"vector", "nodeupdate", | ||||||
|  | 	"VoxelManip", "VoxelArea", | ||||||
|  | 	"PseudoRandom", "ItemStack", | ||||||
|  | 	"AreaStore", | ||||||
|  | 	"intllib", | ||||||
|  | 	"default", | ||||||
|  | 	table = { fields = { "copy", "getn" } } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | globals = { | ||||||
|  | 	"minetest" | ||||||
|  | } | ||||||
							
								
								
									
										48
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,21 +1,29 @@ | |||||||
| Areas mod for Minetest 0.4.8+ | Areas mod for Minetest | ||||||
| ============================= | ====================== | ||||||
|  |  | ||||||
|  | Dependencies | ||||||
|  | ------------ | ||||||
|  |  | ||||||
|  | Minetest 5.0.0+ is recommended, but 0.4.16+ should work as well. | ||||||
|  |  | ||||||
|  |  | ||||||
| Configuration | Configuration | ||||||
| ------------- | ------------- | ||||||
|  |  | ||||||
| If you wish to specify configuration options, such as whether players are | Open the tab `Settings -> All Settings -> Mods -> areas` to get a list of all | ||||||
| allowed to protect their own areas with the `protect` command (disabled by | possible settings. | ||||||
| default), you should check config.lua and set the appropriate settings in your |  | ||||||
| server's configuration file (probably `minetest.conf`). | For server owners: Check `settingtypes.txt` and modify your `minetest.conf` | ||||||
|  | according to the wanted setting changes. | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| Tutorial | Tutorial | ||||||
| -------- | -------- | ||||||
|  |  | ||||||
| To protect an area you must first set the corner positions of the area. | 1) Specify the corner positions of the area you would like to protect. | ||||||
| In order to set the corner positions you can run: | Use one of the following commands: | ||||||
|  |  | ||||||
|   * `/area_pos set` and punch the two corner nodes to set them. |   * `/area_pos set` and punch the two corner nodes to set them. | ||||||
|   * `/area_pos set1/set2` and punch only the first or second corner node to |   * `/area_pos set1/set2` and punch only the first or second corner node to | ||||||
| 	set them one at a time. | 	set them one at a time. | ||||||
| @@ -23,25 +31,25 @@ In order to set the corner positions you can run: | |||||||
|   * `/area_pos1/2 X Y Z` to set one of the positions to the specified |   * `/area_pos1/2 X Y Z` to set one of the positions to the specified | ||||||
| 	coordinates. | 	coordinates. | ||||||
|  |  | ||||||
| Once you have set the border positions you can protect the area by running one | 2) Protect the selected area by running one of the following commands: | ||||||
| of the following commands: |  | ||||||
|   * `/set_owner <OwnerName> <AreaName>` -- If you have the `areas` privilege. |   * `/set_owner <OwnerName> <AreaName>` -- If you have the `areas` privilege. | ||||||
|   * `/protect <AreaName>` -- If you have the `areas` privilege or the server |   * `/protect <AreaName>` -- If you have the `areas` privilege or the server | ||||||
| 	administrator has enabled area self-protection. | 	administrator has enabled area self-protection. | ||||||
|  |  | ||||||
| The area name is used only for informational purposes (so that you know what | The area name is used only for informational purposes and has no functional | ||||||
| an area is for).  It is not used for any other purpose. | importance. | ||||||
|  |  | ||||||
| For example: `/set_owner SomePlayer Mese city` | For example: `/set_owner SomePlayer Mese city` | ||||||
|  |  | ||||||
| Now that you own an area you may want to add sub-owners to it. You can do this | 3) You now own an area. You may now add sub-owners to it if you want to (see command `/add_owner`). Before using the `/add_owner` command you have to | ||||||
| with the `add_owner` command.  Anyone with an area can use the `add_owner` | select the corners of the sub-area as you did in step 1. | ||||||
| command on their areas.  Before using the `add_owner` command you have to |  | ||||||
| select the corners of the sub-area as you did for `set_owner`. If your markers | If your markers are still around your original area and you want to grant | ||||||
| are still around your original area and you want to grant access to your | access to your entire area you will not have to re-set them. Use `/select_area` to place the markers at the corners of an existing area if you've reset your | ||||||
| entire area you will not have to re-set them. You can also use `select_area` to |  | ||||||
| place the markers at the corners of an existing area if you've reset your |  | ||||||
| markers and want to grant access to a full area. | markers and want to grant access to a full area. | ||||||
| The `add_owner` command expects three arguments: |  | ||||||
|  | The `/add_owner` command expects three arguments: | ||||||
|   1. The ID number of the parent area (the area that you want to add a |   1. The ID number of the parent area (the area that you want to add a | ||||||
| 	sub-area to). | 	sub-area to). | ||||||
|   2. The name of the player that will own the sub-area. |   2. The name of the player that will own the sub-area. | ||||||
|   | |||||||
							
								
								
									
										70
									
								
								api.lua
									
									
									
									
									
								
							
							
						
						
									
										70
									
								
								api.lua
									
									
									
									
									
								
							| @@ -1,7 +1,50 @@ | |||||||
|  | local hudHandlers = {} | ||||||
|  |  | ||||||
|  | ---plants to place in openfarming | ||||||
|  | local plants = { | ||||||
|  | 	["farming:blueberries"]="air", ["farming:carrot"]="air", ["farming:coffee_beans"]="air", | ||||||
|  | 	["farming:corn"]="air", ["farming:cucumber"]="air", ["farming:melon_slice"]="air", | ||||||
|  | 	["farming:potato"]="air", ["farming:pumpkin_slice"]="air", ["farming:raspberries"]="air", | ||||||
|  | 	["farming:rhubarb"]="air",	["farming:tomato"]="air", ["farming:seed_cotton"]="air", | ||||||
|  | 	["farming:seed_wheat"]="air",["default:papyrus"]="air", ["farming:trellis"]="air", | ||||||
|  | 	["farming:grapes"]="farming:trellis", ["farming:beanpole"]="air", ["farming:beans"]="farming:beanpole", | ||||||
|  | } | ||||||
|  |  | ||||||
|  | areas.registered_on_adds = {} | ||||||
|  | areas.registered_on_removes = {} | ||||||
|  | areas.registered_on_moves = {} | ||||||
|  |  | ||||||
|  | function areas:registerOnAdd(func) | ||||||
|  | 	table.insert(areas.registered_on_adds, func) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function areas:registerOnRemove(func) | ||||||
|  | 	table.insert(areas.registered_on_removes, func) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | 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 | ||||||
|  | 		func(pos, areas) | ||||||
|  | 	end | ||||||
|  | 	return areas | ||||||
|  | end | ||||||
|  |  | ||||||
| --- Returns a list of areas that include the provided position. | --- Returns a list of areas that include the provided position. | ||||||
| function areas:getAreasAtPos(pos) | function areas:getAreasAtPos(pos) | ||||||
| 	local res = {} | 	local res = {} | ||||||
|  |  | ||||||
| 	if self.store then | 	if self.store then | ||||||
| 		local a = self.store:get_areas_for_pos(pos, false, true) | 		local a = self.store:get_areas_for_pos(pos, false, true) | ||||||
| 		for store_id, store_area in pairs(a) do | 		for store_id, store_area in pairs(a) do | ||||||
| @@ -60,9 +103,31 @@ function areas:canInteract(pos, name) | |||||||
| 	for _, area in pairs(self:getAreasAtPos(pos)) do | 	for _, area in pairs(self:getAreasAtPos(pos)) do | ||||||
| 		if area.owner == name or area.open then | 		if area.owner == name or area.open then | ||||||
| 			return true | 			return true | ||||||
| 		else | 		elseif area.openfarming then | ||||||
| 			owned = true | 			-- if area is openfarming | ||||||
|  | 			local node = minetest.get_node(pos).name | ||||||
|  | 			if not minetest.registered_nodes[node] then return false end | ||||||
|  | 			local player = minetest.get_player_by_name(name) | ||||||
|  | 			if not player then return false end | ||||||
|  | 			local wstack = player:get_wielded_item():get_name() | ||||||
|  | 			if wstack == "" then wstack = "hand" end | ||||||
|  |  | ||||||
|  | 			--on_dig | ||||||
|  | 			if minetest.get_item_group(node, "plant") == 1 and (wstack == "hand" or minetest.registered_tools[wstack]) then | ||||||
|  | 				return true | ||||||
|  | 			end | ||||||
|  |  | ||||||
|  | 			--on_place | ||||||
|  | 			if plants[wstack] ~= nil and plants[wstack] == node then | ||||||
|  | 				return true | ||||||
|  | 			end | ||||||
|  | 		elseif areas.factions_available and area.faction_open then | ||||||
|  | 			local faction_name = factions.get_player_faction(area.owner) | ||||||
|  | 			if faction_name ~= nil and faction_name == factions.get_player_faction(name) then | ||||||
|  | 				return true | ||||||
|  | 			end | ||||||
| 		end | 		end | ||||||
|  | 		owned = true | ||||||
| 	end | 	end | ||||||
| 	return not owned | 	return not owned | ||||||
| end | end | ||||||
| @@ -125,4 +190,3 @@ function areas:canInteractInArea(pos1, pos2, name, allow_open) | |||||||
| 	-- intersecting areas and they are all owned by the player. | 	-- intersecting areas and they are all owned by the player. | ||||||
| 	return true | 	return true | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										48
									
								
								api.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								api.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | Areas mod API | ||||||
|  | === | ||||||
|  |  | ||||||
|  | API list | ||||||
|  | --- | ||||||
|  |  | ||||||
|  |  * `areas:registerHudHandler(handler)` - Registers a handler to add items to the Areas HUD.  See [HUD](#hud). | ||||||
|  |  * `areas:registerOnAdd(func(id, area))` | ||||||
|  |  * `areas:registerOnRemove(func(id))` | ||||||
|  |  * `areas:registerOnMove(func(id, area, pos1, pos2))` | ||||||
|  |  | ||||||
|  |  | ||||||
|  | HUD | ||||||
|  | --- | ||||||
|  |  | ||||||
|  | If you are making a protection mod or a similar mod that adds invisible regions | ||||||
|  | to the world, and you would like then to show up in the areas HUD element, you | ||||||
|  | can register a callback to show your areas. | ||||||
|  |  | ||||||
|  | HUD handler specification: | ||||||
|  |  | ||||||
|  |  * `handler(pos, list)` | ||||||
|  |    * `pos` - The position to check. | ||||||
|  |    * `list` - The list of area HUD elements, this should be modified in-place. | ||||||
|  |  | ||||||
|  | The area list item is a table containing a list of tables with the following fields: | ||||||
|  |  | ||||||
|  |  * `id` - An identifier for the area. This should be a unique string in the format `mod:id`. | ||||||
|  |  * `name` - The name of the area. | ||||||
|  |  * `owner` - The player name of the region owner, if any. | ||||||
|  |  | ||||||
|  | All of the fields are optional but at least one of them must be set. | ||||||
|  |  | ||||||
|  | ### Example | ||||||
|  |  | ||||||
|  | 	local function areas_hud_handler(pos, areas) | ||||||
|  | 		local val = find_my_protection(pos) | ||||||
|  |  | ||||||
|  | 		if val then | ||||||
|  | 			table.insert(areas, { | ||||||
|  | 				id = "mod:"..val.id, | ||||||
|  | 				name = val.name, | ||||||
|  | 				owner = val.owner, | ||||||
|  | 			}) | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|  |  | ||||||
|  | 	areas:registerHudHandler(areas_hud_handler) | ||||||
| @@ -60,7 +60,7 @@ minetest.register_chatcommand("set_owner", { | |||||||
|  |  | ||||||
| 		local id = areas:add(ownerName, areaName, pos1, pos2, nil) | 		local id = areas:add(ownerName, areaName, pos1, pos2, nil) | ||||||
| 		areas:save() | 		areas:save() | ||||||
| 	 |  | ||||||
| 		minetest.chat_send_player(ownerName, | 		minetest.chat_send_player(ownerName, | ||||||
| 				"You have been granted control over area #".. | 				"You have been granted control over area #".. | ||||||
| 				id..". Type /list_areas to show your areas.") | 				id..". Type /list_areas to show your areas.") | ||||||
| @@ -286,6 +286,52 @@ minetest.register_chatcommand("area_open", { | |||||||
| }) | }) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | minetest.register_chatcommand( | ||||||
|  | 	"area_openfarming", { | ||||||
|  | 		params = "<ID>", | ||||||
|  | 		description = "Toggle an area as open farming (anyone can harvest and plant) or closed", | ||||||
|  | 		func = function(name, param) | ||||||
|  | 			local id = tonumber(param) | ||||||
|  | 			if not id then | ||||||
|  | 				return false, "Invalid usage, see /help area_openfarming." | ||||||
|  | 			end | ||||||
|  | 			 | ||||||
|  | 			if not areas:isAreaOwner(id, name) then | ||||||
|  | 				return false, "Area "..id.." does not exist" | ||||||
|  | 					.." or is not owned by you." | ||||||
|  | 			end | ||||||
|  | 			local open = not areas.areas[id].openfarming | ||||||
|  | 			-- Save false as nil to avoid inflating the DB. | ||||||
|  | 			areas.areas[id].openfarming = open or nil | ||||||
|  | 			areas:save() | ||||||
|  | 			return true, ("Area %s to farming."):format(open and "opened" or "closed") | ||||||
|  | 		end | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | if areas.factions_available then | ||||||
|  | 	minetest.register_chatcommand("area_faction_open", { | ||||||
|  | 		params = "<ID>", | ||||||
|  | 		description = "Toggle an area open/closed for members in your faction.", | ||||||
|  | 		func = function(name, param) | ||||||
|  | 			local id = tonumber(param) | ||||||
|  | 			if not id then | ||||||
|  | 				return false, "Invalid usage, see /help area_faction_open." | ||||||
|  | 			end | ||||||
|  | 			 | ||||||
|  | 			if not areas:isAreaOwner(id, name) then | ||||||
|  | 				return false, "Area "..id.." does not exist" | ||||||
|  | 						.." or is not owned by you." | ||||||
|  | 			end | ||||||
|  | 			local open = not areas.areas[id].faction_open | ||||||
|  | 			-- Save false as nil to avoid inflating the DB. | ||||||
|  | 			areas.areas[id].faction_open = open or nil | ||||||
|  | 			areas:save() | ||||||
|  | 			return true, ("Area %s for faction members."):format(open and "opened" or "closed") | ||||||
|  | 		end | ||||||
|  | 	}) | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
| minetest.register_chatcommand("move_area", { | minetest.register_chatcommand("move_area", { | ||||||
| 	params = "<ID>", | 	params = "<ID>", | ||||||
| 	description = "Move (or resize) an area to the current positions.", | 	description = "Move (or resize) an area to the current positions.", | ||||||
| @@ -357,7 +403,9 @@ minetest.register_chatcommand("area_info", { | |||||||
| 		elseif has_high_limit then | 		elseif has_high_limit then | ||||||
| 			table.insert(lines, | 			table.insert(lines, | ||||||
| 				"You have extended area protection".. | 				"You have extended area protection".. | ||||||
| 				" limits (\"areas_high_limit\" privilege).") | 					" limits (\"areas_high_limit\" privilege).") | ||||||
|  | 		elseif privs.megabuilder then | ||||||
|  | 			table.insert(lines, "You are a megabuilder (\"megabuilder\" privilege).") | ||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		-- Area count | 		-- Area count | ||||||
| @@ -369,7 +417,7 @@ minetest.register_chatcommand("area_info", { | |||||||
| 		end | 		end | ||||||
| 		local count_line = ("You have %d area%s"):format( | 		local count_line = ("You have %d area%s"):format( | ||||||
| 			area_num, area_num == 1 and "" or "s") | 			area_num, area_num == 1 and "" or "s") | ||||||
| 		if privs.areas then | 		if privs.areas or privs.megabuilder then | ||||||
| 			count_line = count_line.. | 			count_line = count_line.. | ||||||
| 				" and have no area protection limits." | 				" and have no area protection limits." | ||||||
| 		elseif can_prot then | 		elseif can_prot then | ||||||
| @@ -383,10 +431,10 @@ minetest.register_chatcommand("area_info", { | |||||||
| 			table.insert(lines, ("%s spanning up to %dx%dx%d.") | 			table.insert(lines, ("%s spanning up to %dx%dx%d.") | ||||||
| 				:format(str, size.x, size.y, size.z)) | 				:format(str, size.x, size.y, size.z)) | ||||||
| 		end | 		end | ||||||
| 		local function priv_limit_info(priv, max_count, max_size) | 		local function priv_limit_info(lpriv, lmax_count, lmax_size) | ||||||
| 			size_info(("Players with the %q privilege".. | 			size_info(("Players with the %q privilege".. | ||||||
| 				" can protect up to %d areas"):format( | 				" can protect up to %d areas"):format( | ||||||
| 					priv, max_count), max_size) | 					lpriv, lmax_count), lmax_size) | ||||||
| 		end | 		end | ||||||
| 		if self_prot then | 		if self_prot then | ||||||
| 			if privs.areas then | 			if privs.areas then | ||||||
| @@ -394,6 +442,8 @@ minetest.register_chatcommand("area_info", { | |||||||
| 					limit, size_limit) | 					limit, size_limit) | ||||||
| 				priv_limit_info("areas_high_limit", | 				priv_limit_info("areas_high_limit", | ||||||
| 					limit_high, size_limit_high) | 					limit_high, size_limit_high) | ||||||
|  | 			elseif privs.megabuilder then | ||||||
|  | 				table.insert(lines, "You can protect areas unlimited in size and number.") | ||||||
| 			elseif has_prot_priv then | 			elseif has_prot_priv then | ||||||
| 				size_info("You can protect areas", max_size) | 				size_info("You can protect areas", max_size) | ||||||
| 			end | 			end | ||||||
| @@ -402,4 +452,3 @@ minetest.register_chatcommand("area_info", { | |||||||
| 		return true, table.concat(lines, "\n") | 		return true, table.concat(lines, "\n") | ||||||
| 	end, | 	end, | ||||||
| }) | }) | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										34
									
								
								hud.lua
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								hud.lua
									
									
									
									
									
								
							| @@ -1,17 +1,43 @@ | |||||||
| -- This is inspired by the landrush mod by Bremaweb | -- This is inspired by the landrush mod by Bremaweb | ||||||
|  |  | ||||||
| areas.hud = {} | areas.hud = {} | ||||||
|  | areas.hud.refresh = 0 | ||||||
|  |  | ||||||
| minetest.register_globalstep(function(dtime) | minetest.register_globalstep(function(dtime) | ||||||
|  |  | ||||||
|  | 	areas.hud.refresh = areas.hud.refresh + dtime | ||||||
|  | 	if areas.hud.refresh > areas.config["tick"] then | ||||||
|  | 		areas.hud.refresh = 0 | ||||||
|  | 	else | ||||||
|  | 		return | ||||||
|  | 	end | ||||||
|  |  | ||||||
| 	for _, player in pairs(minetest.get_connected_players()) do | 	for _, player in pairs(minetest.get_connected_players()) do | ||||||
| 		local name = player:get_player_name() | 		local name = player:get_player_name() | ||||||
| 		local pos = vector.round(player:getpos()) | 		local pos = vector.round(player:get_pos()) | ||||||
|  | 		pos = vector.apply(pos, function(p) | ||||||
|  | 			return math.max(math.min(p, 2147483), -2147483) | ||||||
|  | 		end) | ||||||
| 		local areaStrings = {} | 		local areaStrings = {} | ||||||
|  |  | ||||||
| 		for id, area in pairs(areas:getAreasAtPos(pos)) do | 		for id, area in pairs(areas:getAreasAtPos(pos)) do | ||||||
| 			table.insert(areaStrings, ("%s [%u] (%s%s)") | 			local faction_info = area.faction_open and areas.factions_available and | ||||||
|  | 					factions.get_player_faction(area.owner) | ||||||
|  | 			area.faction_open = faction_info | ||||||
|  | 			table.insert(areaStrings, ("%s [%u] (%s%s%s)") | ||||||
| 					:format(area.name, id, area.owner, | 					:format(area.name, id, area.owner, | ||||||
| 					area.open and ":open" or "")) | 					area.open and ":open" or area.openfarming and ":openfarming" or "", | ||||||
|  | 					faction_info and ":"..faction_info or "")) | ||||||
| 		end | 		end | ||||||
|  |  | ||||||
|  | 		for i, area in pairs(areas:getExternalHudEntries(pos)) do | ||||||
|  | 			local str = "" | ||||||
|  | 			if area.name then str = area.name .. " " end | ||||||
|  | 			if area.id then str = str.."["..area.id.."] " end | ||||||
|  | 			if area.owner then str = str.."("..area.owner..")" end | ||||||
|  | 			table.insert(areaStrings, str) | ||||||
|  | 		end | ||||||
|  |  | ||||||
| 		local areaString = "Areas:" | 		local areaString = "Areas:" | ||||||
| 		if #areaStrings > 0 then | 		if #areaStrings > 0 then | ||||||
| 			areaString = areaString.."\n".. | 			areaString = areaString.."\n".. | ||||||
| @@ -26,7 +52,7 @@ minetest.register_globalstep(function(dtime) | |||||||
| 				name = "Areas", | 				name = "Areas", | ||||||
| 				number = 0xFFFFFF, | 				number = 0xFFFFFF, | ||||||
| 				position = {x=0, y=1}, | 				position = {x=0, y=1}, | ||||||
| 				offset = {x=8, y=-8}, | 				offset = {x=8, y=-24}, | ||||||
| 				text = areaString, | 				text = areaString, | ||||||
| 				scale = {x=200, y=60}, | 				scale = {x=200, y=60}, | ||||||
| 				alignment = {x=1, y=-1}, | 				alignment = {x=1, y=-1}, | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								init.lua
									
									
									
									
									
								
							| @@ -4,6 +4,8 @@ | |||||||
|  |  | ||||||
| areas = {} | areas = {} | ||||||
|  |  | ||||||
|  | areas.factions_available = minetest.global_exists("factions") | ||||||
|  |  | ||||||
| areas.adminPrivs = {areas=true} | areas.adminPrivs = {areas=true} | ||||||
| areas.startTime = os.clock() | areas.startTime = os.clock() | ||||||
|  |  | ||||||
| @@ -23,7 +25,11 @@ 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 do more bigger areas." | ||||||
|  | }) | ||||||
|  | -- Mega_builder privilege -- MFF | ||||||
|  | minetest.register_privilege("megabuilder", { | ||||||
|  | 	description = "Can protect an infinite amount of areas." | ||||||
| }) | }) | ||||||
|  |  | ||||||
| if not minetest.registered_privileges[areas.config.self_protection_privilege] then | if not minetest.registered_privileges[areas.config.self_protection_privilege] then | ||||||
| @@ -32,7 +38,7 @@ if not minetest.registered_privileges[areas.config.self_protection_privilege] th | |||||||
| 	}) | 	}) | ||||||
| end | end | ||||||
|  |  | ||||||
| if minetest.setting_getbool("log_mod") then | 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 | ||||||
|   | |||||||
							
								
								
									
										83
									
								
								internal.lua
									
									
									
									
									
								
							
							
						
						
									
										83
									
								
								internal.lua
									
									
									
									
									
								
							| @@ -1,6 +1,17 @@ | |||||||
|  |  | ||||||
| function areas:player_exists(name) | function areas:player_exists(name) | ||||||
| 	return minetest.auth_table[name] ~= nil | 	return minetest.get_auth_handler().get_auth(name) ~= nil | ||||||
|  | end | ||||||
|  |  | ||||||
|  | local safe_file_write = minetest.safe_file_write | ||||||
|  | if safe_file_write == nil then | ||||||
|  | 	function safe_file_write(path, content) | ||||||
|  | 		local file, err = io.open(path, "w") | ||||||
|  | 		if err then | ||||||
|  | 			return err | ||||||
|  | 		end | ||||||
|  | 		file:write(content) | ||||||
|  | 		file:close() | ||||||
|  | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| -- Save the areas table to a file | -- Save the areas table to a file | ||||||
| @@ -10,12 +21,7 @@ function areas:save() | |||||||
| 		minetest.log("error", "[areas] Failed to serialize area data!") | 		minetest.log("error", "[areas] Failed to serialize area data!") | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| 	local file, err = io.open(self.config.filename, "w") | 	return safe_file_write(self.config.filename, datastr) | ||||||
| 	if err then |  | ||||||
| 		return err |  | ||||||
| 	end |  | ||||||
| 	file:write(datastr) |  | ||||||
| 	file:close() |  | ||||||
| end | end | ||||||
|  |  | ||||||
| -- Load the areas table from the save file | -- Load the areas table from the save file | ||||||
| @@ -86,6 +92,11 @@ function areas:add(owner, name, pos1, pos2, parent) | |||||||
| 		owner = owner, | 		owner = owner, | ||||||
| 		parent = parent | 		parent = parent | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	for i=1, #areas.registered_on_adds do | ||||||
|  | 		areas.registered_on_adds[i](id, self.areas[id]) | ||||||
|  | 	end | ||||||
|  |  | ||||||
| 	-- Add to AreaStore | 	-- Add to AreaStore | ||||||
| 	if self.store then | 	if self.store then | ||||||
| 		local sid = self.store:insert_area(pos1, pos2, tostring(id)) | 		local sid = self.store:insert_area(pos1, pos2, tostring(id)) | ||||||
| @@ -118,6 +129,10 @@ function areas:remove(id, recurse) | |||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
|  | 	for i=1, #areas.registered_on_removes do | ||||||
|  | 		areas.registered_on_removes[i](id) | ||||||
|  | 	end | ||||||
|  |  | ||||||
| 	-- Remove main entry | 	-- Remove main entry | ||||||
| 	self.areas[id] = nil | 	self.areas[id] = nil | ||||||
|  |  | ||||||
| @@ -133,6 +148,11 @@ 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 | ||||||
|  | 		areas.registered_on_moves[i](id, area, pos1, pos2) | ||||||
|  | 	end | ||||||
|  |  | ||||||
| 	if self.store then | 	if self.store then | ||||||
| 		self.store:remove_area(areas.store_ids[id]) | 		self.store:remove_area(areas.store_ids[id]) | ||||||
| 		local sid = self.store:insert_area(pos1, pos2, tostring(id)) | 		local sid = self.store:insert_area(pos1, pos2, tostring(id)) | ||||||
| @@ -195,39 +215,41 @@ function areas:canPlayerAddArea(pos1, pos2, name) | |||||||
| 				.." the necessary privilege." | 				.." the necessary privilege." | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	local max_size = privs.areas_high_limit and | 	-- MFF: megabuilders skip checks on size and number of areas | ||||||
|  | 	if not privs.megabuilder then | ||||||
|  | 		local max_size = privs.areas_high_limit and | ||||||
| 			self.config.self_protection_max_size_high or | 			self.config.self_protection_max_size_high or | ||||||
| 			self.config.self_protection_max_size | 			self.config.self_protection_max_size | ||||||
| 	if | 		if | ||||||
| 			(pos2.x - pos1.x) > max_size.x or | 			(pos2.x - pos1.x) > max_size.x or | ||||||
| 			(pos2.y - pos1.y) > max_size.y or | 			(pos2.y - pos1.y) > max_size.y or | ||||||
| 			(pos2.z - pos1.z) > max_size.z then | 		(pos2.z - pos1.z) > max_size.z then | ||||||
| 		return false, "Area is too big." | 			return false, "Area is too big." | ||||||
| 	end |  | ||||||
|  |  | ||||||
| 	-- Check number of areas the user has and make sure it not above the max |  | ||||||
| 	local count = 0 |  | ||||||
| 	for _, area in pairs(self.areas) do |  | ||||||
| 		if area.owner == name then |  | ||||||
| 			count = count + 1 |  | ||||||
| 		end | 		end | ||||||
| 	end |  | ||||||
| 	local max_areas = privs.areas_high_limit and | 		-- Check number of areas the user has and make sure it not above the max | ||||||
|  | 		local count = 0 | ||||||
|  | 		for _, area in pairs(self.areas) do | ||||||
|  | 			if area.owner == name then | ||||||
|  | 				count = count + 1 | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 		local max_areas = privs.areas_high_limit and | ||||||
| 			self.config.self_protection_max_areas_high or | 			self.config.self_protection_max_areas_high or | ||||||
| 			self.config.self_protection_max_areas | 			self.config.self_protection_max_areas | ||||||
| 	if count >= max_areas then | 		if count >= max_areas then | ||||||
| 		return false, "You have reached the maximum amount of" | 			return false, "You have reached the maximum amount of" | ||||||
| 				.." areas that you are allowed to  protect." | 				.." areas that you are allowed to  protect." | ||||||
| 	end | 		end | ||||||
|  |  | ||||||
| 	-- Check intersecting areas | 		-- Check intersecting areas | ||||||
| 	local can, id = self:canInteractInArea(pos1, pos2, name) | 		local can, id = self:canInteractInArea(pos1, pos2, name) | ||||||
| 	if not can then | 		if not can then | ||||||
| 		local area = self.areas[id] | 			local area = self.areas[id] | ||||||
| 		return false, ("The area intersects with %s [%u] (%s).") | 			return false, ("The area intersects with %s [%u] (%s).") | ||||||
| 				:format(area.name, id, area.owner) | 				:format(area.name, id, area.owner) | ||||||
|  | 		end | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	return true | 	return true | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -282,4 +304,3 @@ function areas:isAreaOwner(id, name) | |||||||
| 	end | 	end | ||||||
| 	return false | 	return false | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ minetest.register_chatcommand("legacy_load_areas", { | |||||||
| 		minetest.chat_send_player(name, "Converting areas...") | 		minetest.chat_send_player(name, "Converting areas...") | ||||||
| 		local version = tonumber(param) | 		local version = tonumber(param) | ||||||
| 		if version == 0 then | 		if version == 0 then | ||||||
| 			err = areas:node_ownership_load() | 			local err = areas:node_ownership_load() | ||||||
| 			if err then | 			if err then | ||||||
| 				minetest.chat_send_player(name, "Error loading legacy file: "..err) | 				minetest.chat_send_player(name, "Error loading legacy file: "..err) | ||||||
| 				return | 				return | ||||||
| @@ -48,6 +48,7 @@ minetest.register_chatcommand("legacy_load_areas", { | |||||||
|  |  | ||||||
| function areas:node_ownership_load() | function areas:node_ownership_load() | ||||||
| 	local filename = minetest.get_worldpath().."/owners.tbl" | 	local filename = minetest.get_worldpath().."/owners.tbl" | ||||||
|  | 	local tables, err | ||||||
| 	tables, err = loadfile(filename) | 	tables, err = loadfile(filename) | ||||||
| 	if err then | 	if err then | ||||||
| 		return err | 		return err | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								pos.lua
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								pos.lua
									
									
									
									
									
								
							| @@ -11,6 +11,16 @@ areas.set_pos = {} | |||||||
| areas.pos1 = {} | areas.pos1 = {} | ||||||
| areas.pos2 = {} | areas.pos2 = {} | ||||||
|  |  | ||||||
|  | local LIMIT = 30992 -- this is due to MAPBLOCK_SIZE=16! | ||||||
|  |  | ||||||
|  | local function posLimit(pos) | ||||||
|  | 	return { | ||||||
|  | 		x = math.max(math.min(pos.x, LIMIT), -LIMIT), | ||||||
|  | 		y = math.max(math.min(pos.y, LIMIT), -LIMIT), | ||||||
|  | 		z = math.max(math.min(pos.z, LIMIT), -LIMIT) | ||||||
|  | 	} | ||||||
|  | end | ||||||
|  |  | ||||||
| minetest.register_chatcommand("select_area", { | minetest.register_chatcommand("select_area", { | ||||||
| 	params = "<ID>", | 	params = "<ID>", | ||||||
| 	description = "Select a area by id.", | 	description = "Select a area by id.", | ||||||
| @@ -35,7 +45,7 @@ minetest.register_chatcommand("area_pos1", { | |||||||
| 		.." location or the one specified", | 		.." location or the one specified", | ||||||
| 	privs = {}, | 	privs = {}, | ||||||
| 	func = function(name, param) | 	func = function(name, param) | ||||||
| 		local pos = nil | 		local pos | ||||||
| 		local found, _, x, y, z = param:find( | 		local found, _, x, y, z = param:find( | ||||||
| 				"^(-?%d+)[, ](-?%d+)[, ](-?%d+)$") | 				"^(-?%d+)[, ](-?%d+)[, ](-?%d+)$") | ||||||
| 		if found then | 		if found then | ||||||
| @@ -43,14 +53,14 @@ minetest.register_chatcommand("area_pos1", { | |||||||
| 		elseif param == "" then | 		elseif param == "" then | ||||||
| 			local player = minetest.get_player_by_name(name) | 			local player = minetest.get_player_by_name(name) | ||||||
| 			if player then | 			if player then | ||||||
| 				pos = player:getpos() | 				pos = player:get_pos() | ||||||
| 			else | 			else | ||||||
| 				return false, "Unable to get position." | 				return false, "Unable to get position." | ||||||
| 			end | 			end | ||||||
| 		else | 		else | ||||||
| 			return false, "Invalid usage, see /help area_pos1." | 			return false, "Invalid usage, see /help area_pos1." | ||||||
| 		end | 		end | ||||||
| 		pos = vector.round(pos) | 		pos = posLimit(vector.round(pos)) | ||||||
| 		areas:setPos1(name, pos) | 		areas:setPos1(name, pos) | ||||||
| 		return true, "Area position 1 set to " | 		return true, "Area position 1 set to " | ||||||
| 				..minetest.pos_to_string(pos) | 				..minetest.pos_to_string(pos) | ||||||
| @@ -62,7 +72,7 @@ minetest.register_chatcommand("area_pos2", { | |||||||
| 	description = "Set area protection region position 2 to your" | 	description = "Set area protection region position 2 to your" | ||||||
| 		.." location or the one specified", | 		.." location or the one specified", | ||||||
| 	func = function(name, param) | 	func = function(name, param) | ||||||
| 		local pos = nil | 		local pos | ||||||
| 		local found, _, x, y, z = param:find( | 		local found, _, x, y, z = param:find( | ||||||
| 				"^(-?%d+)[, ](-?%d+)[, ](-?%d+)$") | 				"^(-?%d+)[, ](-?%d+)[, ](-?%d+)$") | ||||||
| 		if found then | 		if found then | ||||||
| @@ -70,14 +80,14 @@ minetest.register_chatcommand("area_pos2", { | |||||||
| 		elseif param == "" then | 		elseif param == "" then | ||||||
| 			local player = minetest.get_player_by_name(name) | 			local player = minetest.get_player_by_name(name) | ||||||
| 			if player then | 			if player then | ||||||
| 				pos = player:getpos() | 				pos = player:get_pos() | ||||||
| 			else | 			else | ||||||
| 				return false, "Unable to get position." | 				return false, "Unable to get position." | ||||||
| 			end | 			end | ||||||
| 		else | 		else | ||||||
| 			return false, "Invalid usage, see /help area_pos2." | 			return false, "Invalid usage, see /help area_pos2." | ||||||
| 		end | 		end | ||||||
| 		pos = vector.round(pos) | 		pos = posLimit(vector.round(pos)) | ||||||
| 		areas:setPos2(name, pos) | 		areas:setPos2(name, pos) | ||||||
| 		return true, "Area position 2 set to " | 		return true, "Area position 2 set to " | ||||||
| 				..minetest.pos_to_string(pos) | 				..minetest.pos_to_string(pos) | ||||||
| @@ -130,12 +140,12 @@ function areas:getPos(playerName) | |||||||
| end | end | ||||||
|  |  | ||||||
| function areas:setPos1(playerName, pos) | function areas:setPos1(playerName, pos) | ||||||
| 	areas.pos1[playerName] = pos | 	areas.pos1[playerName] = posLimit(pos) | ||||||
| 	areas.markPos1(playerName) | 	areas.markPos1(playerName) | ||||||
| end | end | ||||||
|  |  | ||||||
| function areas:setPos2(playerName, pos) | function areas:setPos2(playerName, pos) | ||||||
| 	areas.pos2[playerName] = pos | 	areas.pos2[playerName] = posLimit(pos) | ||||||
| 	areas.markPos2(playerName) | 	areas.markPos2(playerName) | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										49
									
								
								settings.lua
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								settings.lua
									
									
									
									
									
								
							| @@ -2,42 +2,45 @@ local world_path = minetest.get_worldpath() | |||||||
|  |  | ||||||
| areas.config = {} | areas.config = {} | ||||||
|  |  | ||||||
| local function setting(tp, name, default) | local function setting(name, tp, default) | ||||||
| 	local full_name = "areas."..name | 	local full_name = "areas." .. name | ||||||
| 	local value | 	local value | ||||||
| 	if tp == "boolean" then | 	if tp == "bool" then | ||||||
| 		value = minetest.setting_getbool(full_name) | 		value = minetest.settings:get_bool(full_name) | ||||||
|  | 		default = value == nil and minetest.is_yes(default) | ||||||
| 	elseif tp == "string" then | 	elseif tp == "string" then | ||||||
| 		value = minetest.setting_get(full_name) | 		value = minetest.settings:get(full_name) | ||||||
| 	elseif tp == "position" then | 	elseif tp == "v3f" then | ||||||
| 		value = minetest.setting_get_pos(full_name) | 		value = minetest.setting_get_pos(full_name) | ||||||
| 	elseif tp == "number" then | 		default = value == nil and minetest.string_to_pos(default) | ||||||
| 		value = tonumber(minetest.setting_get(full_name)) | 	elseif tp == "float" or tp == "int" then | ||||||
|  | 		value = tonumber(minetest.settings:get(full_name)) | ||||||
|  | 		local v, other = default:match("^(%S+) (.+)") | ||||||
|  | 		default = value == nil and tonumber(other and v or default) | ||||||
| 	else | 	else | ||||||
| 		error("Invalid setting type!") | 		error("Cannot parse setting type " .. tp) | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	if value == nil then | 	if value == nil then | ||||||
| 		value = default | 		value = default | ||||||
|  | 		assert(default ~= nil, "Cannot parse default for " .. full_name) | ||||||
| 	end | 	end | ||||||
|  | 	--print("add", name, default, value) | ||||||
| 	areas.config[name] = value | 	areas.config[name] = value | ||||||
| end | end | ||||||
|  |  | ||||||
|  | local file = io.open(areas.modpath .. "/settingtypes.txt", "r") | ||||||
|  | for line in file:lines() do | ||||||
|  | 	local name, tp, value = line:match("^areas%.(%S+) %(.*%) (%S+) (.*)") | ||||||
|  | 	if value then | ||||||
|  | 		setting(name, tp, value) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  | file:close() | ||||||
|  |  | ||||||
| -------------- | -------------- | ||||||
| -- Settings -- | -- Settings -- | ||||||
| -------------- | -------------- | ||||||
|  |  | ||||||
| setting("string", "filename", world_path.."/areas.dat") | setting("filename", "string", world_path.."/areas.dat") | ||||||
|  |  | ||||||
| -- Allow players with a privilege create their own areas |  | ||||||
| -- within the maximum size and number. |  | ||||||
| setting("boolean",  "self_protection", false) |  | ||||||
| setting("string",   "self_protection_privilege", "interact") |  | ||||||
| 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) |  | ||||||
|  |  | ||||||
| -- legacy_table (owner_defs) compatibility.  Untested and has known issues. |  | ||||||
| setting("boolean", "legacy_table", false) |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										38
									
								
								settingtypes.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								settingtypes.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | # This file is parsed in "settings.lua". Check regex first. | ||||||
|  |  | ||||||
|  | # Static paths do not work well with settings | ||||||
|  | #areas.filename (Configuration file path) string (world_path)/areas.dat | ||||||
|  |  | ||||||
|  | # Allow players with a privilege create their own areas using /protect | ||||||
|  | # within the specified size and amount limits. | ||||||
|  | areas.self_protection (Self protection) bool false | ||||||
|  |  | ||||||
|  | # Self protection: Privilege required to protect an area | ||||||
|  | areas.self_protection_privilege (Self protection: Required privs) string interact | ||||||
|  |  | ||||||
|  | # Refresh delay for the name displays in the HUD in seconds | ||||||
|  | areas.tick (HUD update delay) float 0.5 0 100 | ||||||
|  |  | ||||||
|  | # Enable the legacy owner_defs metatable mode. Untested and possibly unstable | ||||||
|  | areas.legacy_table (Legacy owner_defs metatable) bool false | ||||||
|  |  | ||||||
|  | [Self protection (normal)] | ||||||
|  |  | ||||||
|  | # Self protection (normal): Maximal size of the protectable area | ||||||
|  | # Only enter positive whole numbers for the coordinate values or you'll mess up stuff. | ||||||
|  | areas.self_protection_max_size (Maximal area size) v3f (64, 128, 64) | ||||||
|  |  | ||||||
|  | # Self protection (normal): Maximal amount of protected areas per player | ||||||
|  | areas.self_protection_max_areas (Maximal area count) int 4 | ||||||
|  |  | ||||||
|  | [Self protection (high)] | ||||||
|  |  | ||||||
|  | # Self protection (normal): Maximal size of the protectable area | ||||||
|  | # This setting applies for plyaers with the privilege 'areas_high_limit' | ||||||
|  | areas.self_protection_max_size_high (Maximal area size) v3f (512, 512, 512) | ||||||
|  |  | ||||||
|  | # Self protection (normal): Maximal amount of protected areas per player | ||||||
|  | # 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' | ||||||
|  | areas.self_protection_max_areas_high (Maximal area count) float 32 | ||||||
|  |  | ||||||
		Reference in New Issue
	
	Block a user