mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-11-15 06:40:32 +01:00
Rewrite protection testing
Now it checks for pushing into protected area as well
This commit is contained in:
parent
3eba0bfba9
commit
2693a0550d
|
@ -145,30 +145,37 @@ function mesecon.mvps_mark_owner(pos, placer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function prot_deny() return true end
|
local function add_pos(positions, pos)
|
||||||
local function prot_allow() return false end
|
local hash = minetest.hash_node_position(pos)
|
||||||
|
positions[hash] = pos
|
||||||
|
end
|
||||||
|
|
||||||
local function make_is_protected(player_name)
|
local function are_protected(positions, player_name)
|
||||||
local mode = mesecon.setting("mvps_protection_mode", "normal")
|
local mode = mesecon.setting("mvps_protection_mode", "normal")
|
||||||
if mode == "ignore" then
|
if mode == "ignore" then
|
||||||
return prot_allow
|
return false
|
||||||
end
|
end
|
||||||
|
local name = player_name
|
||||||
if player_name == "" or not player_name then -- legacy MVPS
|
if player_name == "" or not player_name then -- legacy MVPS
|
||||||
if mode == "normal" then
|
if mode == "normal" then
|
||||||
player_name = "$unknown" -- sentinel, for checking for *any* protection
|
name = "$unknown" -- sentinel, for checking for *any* protection
|
||||||
elseif mode == "compat" then
|
elseif mode == "compat" then
|
||||||
return prot_allow
|
return false
|
||||||
elseif mode == "restrict" then
|
elseif mode == "restrict" then
|
||||||
return prot_deny
|
return true
|
||||||
else
|
else
|
||||||
error("Invalid protection mode")
|
error("Invalid protection mode")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local is_protected = minetest.is_protected
|
local is_protected = minetest.is_protected
|
||||||
return function(pos)
|
for _, pos in pairs(positions) do
|
||||||
return is_protected(pos, player_name)
|
if is_protected(pos, name) then
|
||||||
|
minetest.record_protection_violation(pos, player_name)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function mesecon.mvps_push(pos, dir, maximum, player_name)
|
function mesecon.mvps_push(pos, dir, maximum, player_name)
|
||||||
return mesecon.mvps_push_or_pull(pos, dir, dir, maximum, false, player_name)
|
return mesecon.mvps_push_or_pull(pos, dir, dir, maximum, false, player_name)
|
||||||
|
@ -194,16 +201,21 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
|
||||||
local nodes = mesecon.mvps_get_stack(pos, movedir, maximum, all_pull_sticky)
|
local nodes = mesecon.mvps_get_stack(pos, movedir, maximum, all_pull_sticky)
|
||||||
|
|
||||||
if not nodes then return end
|
if not nodes then return end
|
||||||
|
|
||||||
|
local protection_check_set = {}
|
||||||
|
if vector.equals(stackdir, movedir) then -- pushing
|
||||||
|
add_pos(protection_check_set, pos)
|
||||||
|
end
|
||||||
-- determine if one of the nodes blocks the push / pull
|
-- determine if one of the nodes blocks the push / pull
|
||||||
local is_protected = make_is_protected(player_name)
|
|
||||||
for id, n in ipairs(nodes) do
|
for id, n in ipairs(nodes) do
|
||||||
if mesecon.is_mvps_stopper(n.node, movedir, nodes, id) then
|
if mesecon.is_mvps_stopper(n.node, movedir, nodes, id) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if is_protected(n.pos) then
|
add_pos(protection_check_set, n.pos)
|
||||||
minetest.record_protection_violation(n.pos, player_name)
|
add_pos(protection_check_set, vector.add(n.pos, movedir))
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
if are_protected(protection_check_set, player_name) then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- remove all nodes
|
-- remove all nodes
|
||||||
|
|
Loading…
Reference in New Issue
Block a user