forked from minetest-mods/areas
Compare commits
1 Commits
a8cacee8cc
...
require_pr
Author | SHA1 | Date | |
---|---|---|---|
f52454edec |
48
api.lua
48
api.lua
@ -1,24 +1,5 @@
|
|||||||
local hudHandlers = {}
|
local hudHandlers = {}
|
||||||
|
|
||||||
---plants to place in openfarming
|
|
||||||
local plants = {
|
|
||||||
["farming:beetroot"]="air", ["farming:blueberries"]="air", ["farming:cabbage"]="air",
|
|
||||||
["farming:carrot"]="air", ["farming:chili_pepper"]="air", ["farming:coffee_beans"]="air",
|
|
||||||
["farming:corn"]="air", ["farming:cucumber"]="air", ["farming:garlic_clove"]="air",
|
|
||||||
["farming:melon_slice"]="air", ["farming:onion"]="air", ["default:papyrus"]="air",
|
|
||||||
["farming:pea_pod"]="air", ["farming:peppercorn"]="air", ["farming:pineapple_top"]="air",
|
|
||||||
["farming:potato"]="air", ["farming:pumpkin_slice"]="air", ["farming:raspberries"]="air",
|
|
||||||
["farming:rhubarb"]="air",
|
|
||||||
["farming:seed_barley"]="air", ["farming:seed_cotton"]="air", ["farming:seed_hemp"]="air",
|
|
||||||
["farming:seed_mint"]="air", ["farming:seed_oat"]="air", ["farming:seed_rice"]="air",
|
|
||||||
["farming:seed_rye"]="air", ["farming:seed_wheat"]="air",
|
|
||||||
["farming:tomato"]="air",
|
|
||||||
["farming:trellis"]="air", ["farming:grapes"]="farming:trellis",
|
|
||||||
["farming:beanpole"]="air", ["farming:beans"]="farming:beanpole",
|
|
||||||
["morefarming:seed_wildcarrot"]="air", ["morefarming:seed_teosinte"]="air",
|
|
||||||
["morefarming:seed_carrot"]="air", ["morefarming:seed_corn"]="air",
|
|
||||||
}
|
|
||||||
|
|
||||||
areas.registered_on_adds = {}
|
areas.registered_on_adds = {}
|
||||||
areas.registered_on_removes = {}
|
areas.registered_on_removes = {}
|
||||||
areas.registered_on_moves = {}
|
areas.registered_on_moves = {}
|
||||||
@ -103,34 +84,19 @@ end
|
|||||||
|
|
||||||
-- Checks if the area is unprotected or owned by you
|
-- Checks if the area is unprotected or owned by you
|
||||||
function areas:canInteract(pos, name)
|
function areas:canInteract(pos, name)
|
||||||
|
if name == "" then
|
||||||
|
return true -- Mods, namely minetest.item_place_node
|
||||||
|
end
|
||||||
if minetest.check_player_privs(name, self.adminPrivs) then
|
if minetest.check_player_privs(name, self.adminPrivs) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local owned = false
|
|
||||||
|
-- Disallow interaction by default when the restrictive setting is enabled
|
||||||
|
local owned = areas.config.require_protection
|
||||||
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
|
||||||
end
|
elseif areas.factions_available and area.faction_open then
|
||||||
if area.openfarming then
|
|
||||||
-- if area is openfarming
|
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
local node = minetest.get_node(pos).name
|
|
||||||
if player and minetest.registered_nodes[node] then
|
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if areas.factions_available and area.faction_open then
|
|
||||||
if (factions.version or 0) < 2 then
|
if (factions.version or 0) < 2 then
|
||||||
local faction_name = factions.get_player_faction(name)
|
local faction_name = factions.get_player_faction(name)
|
||||||
if faction_name then
|
if faction_name then
|
||||||
|
@ -284,28 +284,6 @@ 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
|
if areas.factions_available then
|
||||||
minetest.register_chatcommand("area_faction_open", {
|
minetest.register_chatcommand("area_faction_open", {
|
||||||
params = S("<ID> [faction_name]"),
|
params = S("<ID> [faction_name]"),
|
||||||
@ -415,9 +393,7 @@ minetest.register_chatcommand("area_info", {
|
|||||||
elseif has_high_limit then
|
elseif has_high_limit then
|
||||||
table.insert(lines,
|
table.insert(lines,
|
||||||
S("You have extended area protection"..
|
S("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
|
||||||
@ -430,7 +406,7 @@ minetest.register_chatcommand("area_info", {
|
|||||||
table.insert(lines, S("You have @1 areas.", area_num))
|
table.insert(lines, S("You have @1 areas.", area_num))
|
||||||
|
|
||||||
-- Area limit
|
-- Area limit
|
||||||
local area_limit_line = (privs.areas or privs.megabuilder) and
|
local area_limit_line = privs.areas and
|
||||||
S("Limit: no area count limit") or
|
S("Limit: no area count limit") or
|
||||||
S("Limit: @1 areas", max_count)
|
S("Limit: @1 areas", max_count)
|
||||||
table.insert(lines, area_limit_line)
|
table.insert(lines, area_limit_line)
|
||||||
@ -451,9 +427,6 @@ 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)
|
||||||
table.insert(lines, "Players with the \"megabuilder\" privilege can protect unlimited areas in size and number.")
|
|
||||||
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(S("You can protect areas"), max_size)
|
size_info(S("You can protect areas"), max_size)
|
||||||
end
|
end
|
||||||
|
4
hud.lua
4
hud.lua
@ -44,8 +44,8 @@ minetest.register_globalstep(function(dtime)
|
|||||||
|
|
||||||
table.insert(areaStrings, ("%s [%u] (%s%s%s)")
|
table.insert(areaStrings, ("%s [%u] (%s%s%s)")
|
||||||
:format(area.name, id, area.owner,
|
:format(area.name, id, area.owner,
|
||||||
area.open and S(":open") or area.openfarming and ":openfarming" or "",
|
area.open and S(":open") or "",
|
||||||
faction_info and ":"..faction_info or ""))
|
faction_info and ": "..faction_info or ""))
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, area in pairs(areas:getExternalHudEntries(pos)) do
|
for i, area in pairs(areas:getExternalHudEntries(pos)) do
|
||||||
|
8
init.lua
8
init.lua
@ -16,7 +16,9 @@ dofile(areas.modpath.."/internal.lua")
|
|||||||
dofile(areas.modpath.."/chatcommands.lua")
|
dofile(areas.modpath.."/chatcommands.lua")
|
||||||
dofile(areas.modpath.."/pos.lua")
|
dofile(areas.modpath.."/pos.lua")
|
||||||
dofile(areas.modpath.."/interact.lua")
|
dofile(areas.modpath.."/interact.lua")
|
||||||
dofile(areas.modpath.."/legacy.lua")
|
if areas.config.node_ownership_legacy then
|
||||||
|
dofile(areas.modpath.."/legacy.lua")
|
||||||
|
end
|
||||||
dofile(areas.modpath.."/hud.lua")
|
dofile(areas.modpath.."/hud.lua")
|
||||||
|
|
||||||
areas:load()
|
areas:load()
|
||||||
@ -31,10 +33,6 @@ minetest.register_privilege("areas_high_limit", {
|
|||||||
description = S("Can protect more, bigger areas."),
|
description = S("Can protect more, bigger areas."),
|
||||||
give_to_singleplayer = false
|
give_to_singleplayer = false
|
||||||
})
|
})
|
||||||
-- 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
|
||||||
minetest.register_privilege(areas.config.self_protection_privilege, {
|
minetest.register_privilege(areas.config.self_protection_privilege, {
|
||||||
|
21
interact.lua
21
interact.lua
@ -9,11 +9,20 @@ function minetest.is_protected(pos, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_protection_violation(function(pos, name)
|
minetest.register_on_protection_violation(function(pos, name)
|
||||||
if not areas:canInteract(pos, name) then
|
if areas:canInteract(pos, name) then
|
||||||
local owners = areas:getNodeOwners(pos)
|
return
|
||||||
minetest.chat_send_player(name,
|
|
||||||
S("@1 is protected by @2.",
|
|
||||||
minetest.pos_to_string(pos),
|
|
||||||
table.concat(owners, ", ")))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local owners = areas:getNodeOwners(pos)
|
||||||
|
if #owners == 0 then
|
||||||
|
-- When require_protection=true
|
||||||
|
minetest.chat_send_player(name,
|
||||||
|
S("@1 may not be accessed.",
|
||||||
|
minetest.pos_to_string(pos)))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(name,
|
||||||
|
S("@1 is protected by @2.",
|
||||||
|
minetest.pos_to_string(pos),
|
||||||
|
table.concat(owners, ", ")))
|
||||||
end)
|
end)
|
||||||
|
24
internal.lua
24
internal.lua
@ -225,27 +225,24 @@ function areas:canPlayerAddArea(pos1, pos2, name)
|
|||||||
.." the necessary privilege.")
|
.." the necessary privilege.")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MFF: megabuilders skip checks on size and number of areas
|
local max_size = privs.areas_high_limit and
|
||||||
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, S("Area is too big.")
|
return false, S("Area is too big.")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check number of areas the user has and make sure it not above the max
|
-- Check number of areas the user has and make sure it not above the max
|
||||||
local count = 0
|
local count = 0
|
||||||
for _, area in pairs(self.areas) do
|
for _, area in pairs(self.areas) do
|
||||||
if area.owner == name then
|
if area.owner == name then
|
||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
|
||||||
end
|
end
|
||||||
local max_areas = privs.areas_high_limit and
|
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
|
||||||
@ -260,6 +257,7 @@ function areas:canPlayerAddArea(pos1, pos2, name)
|
|||||||
return false, S("The area intersects with @1 [@2] (@3).",
|
return false, S("The area intersects with @1 [@2] (@3).",
|
||||||
area.name, id, area.owner)
|
area.name, id, area.owner)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,30 +8,34 @@
|
|||||||
areas.self_protection (Self protection) bool false
|
areas.self_protection (Self protection) bool false
|
||||||
|
|
||||||
# Self protection: Privilege required to protect an area
|
# Self protection: Privilege required to protect an area
|
||||||
areas.self_protection_privilege (Self protection: Required privs) string interact
|
areas.self_protection_privilege (Self protection: Required priv) string interact
|
||||||
|
|
||||||
# Refresh delay for the name displays in the HUD in seconds
|
# Limits interactions of players to the areas they have access to.
|
||||||
|
# This setting is very restrictive and is not recommended for open-world games.
|
||||||
|
areas.require_protection (Require protection) bool false
|
||||||
|
|
||||||
|
# Area name HUD refresh delay in seconds
|
||||||
areas.tick (HUD update delay) float 0.5 0 100
|
areas.tick (HUD update delay) float 0.5 0 100
|
||||||
|
|
||||||
# Enable the legacy owner_defs metatable mode. Untested and possibly unstable
|
# Enable the legacy owner_defs metatable mode. Untested and possibly unstable
|
||||||
areas.legacy_table (Legacy owner_defs metatable) bool false
|
areas.node_ownership_legacy (node_ownership compatibility) bool false
|
||||||
|
|
||||||
[Self protection (normal)]
|
[Self protection (normal)]
|
||||||
|
|
||||||
# Self protection (normal): Maximal size of the protectable area
|
# Maximal size of the protectable area
|
||||||
# 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.
|
||||||
areas.self_protection_max_size (Maximal area size) v3f (64, 128, 64)
|
areas.self_protection_max_size (Maximal area size) v3f (64, 128, 64)
|
||||||
|
|
||||||
# Self protection (normal): Maximal amount of protected areas per player
|
# Maximal amount of protected areas per player
|
||||||
areas.self_protection_max_areas (Maximal area count) int 4
|
areas.self_protection_max_areas (Maximal area count) int 4
|
||||||
|
|
||||||
[Self protection (high)]
|
[Self protection (high)]
|
||||||
|
|
||||||
# Self protection (normal): Maximal size of the protectable area
|
# For players with the 'areas_high_limit' privilege.
|
||||||
# This setting applies for plyaers with the privilege 'areas_high_limit'
|
# Maximal size of the protectable area
|
||||||
|
# This setting applies for players with the privilege 'areas_high_limit'
|
||||||
areas.self_protection_max_size_high (Maximal area size) v3f (512, 512, 512)
|
areas.self_protection_max_size_high (Maximal area size) v3f (512, 512, 512)
|
||||||
|
|
||||||
# Self protection (normal): Maximal amount of protected areas per player
|
# For players with the 'areas_high_limit' privilege.
|
||||||
# Only enter positive whole numbers for the coordinate values or you'll mess up stuff.
|
# Maximal amount of protected areas per player
|
||||||
# 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
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 123 B After Width: | Height: | Size: 142 B |
Binary file not shown.
Before Width: | Height: | Size: 134 B After Width: | Height: | Size: 157 B |
Reference in New Issue
Block a user