1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2025-07-01 15:40:39 +02:00

basic area protection support

This commit is contained in:
Isidor Zeuner
2017-06-21 12:55:25 +02:00
parent acc9188828
commit 5e4298d00d
3 changed files with 95 additions and 5 deletions

View File

@ -1 +1,2 @@
worldedit worldedit
areas?

View File

@ -13,7 +13,7 @@ end
dofile(minetest.get_modpath("worldedit_commands") .. "/cuboid.lua") dofile(minetest.get_modpath("worldedit_commands") .. "/cuboid.lua")
dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua") dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
dofile(minetest.get_modpath("worldedit_commands") .. "/wand.lua") dofile(minetest.get_modpath("worldedit_commands") .. "/wand.lua")
local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua") local safe_region, check_region, reset_pending, area_protection = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
local function get_position(name) --position 1 retrieval function for when not using `safe_region` local function get_position(name) --position 1 retrieval function for when not using `safe_region`
local pos1 = worldedit.pos1[name] local pos1 = worldedit.pos1[name]
@ -409,6 +409,13 @@ minetest.register_chatcommand("/mix", {
}) })
local check_replace = function(name, param) local check_replace = function(name, param)
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"check_replace not yet supported with area protection"
)
return nil
end
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
if found == nil then if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param) worldedit.player_notify(name, "invalid usage: " .. param)
@ -456,8 +463,11 @@ minetest.register_chatcommand("/replaceinverse", {
}) })
local check_sphere = function(name, param) local check_sphere = function(name, param)
if worldedit.pos1[name] == nil then if nil ~= area_protection.areas then
worldedit.player_notify(name, "no position 1 selected") worldedit.player_notify(
name,
"check_sphere not yet supported with area protection"
)
return nil return nil
end end
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
@ -495,6 +505,13 @@ minetest.register_chatcommand("/sphere", {
}) })
local check_dome = function(name, param) local check_dome = function(name, param)
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"check_dome not yet supported with area protection"
)
return nil
end
if worldedit.pos1[name] == nil then if worldedit.pos1[name] == nil then
worldedit.player_notify(name, "no position 1 selected") worldedit.player_notify(name, "no position 1 selected")
return nil return nil
@ -534,6 +551,13 @@ minetest.register_chatcommand("/dome", {
}) })
local check_cylinder = function(name, param) local check_cylinder = function(name, param)
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"check_cylinder not yet supported with area protection"
)
return nil
end
if worldedit.pos1[name] == nil then if worldedit.pos1[name] == nil then
worldedit.player_notify(name, "no position 1 selected") worldedit.player_notify(name, "no position 1 selected")
return nil return nil
@ -583,6 +607,13 @@ minetest.register_chatcommand("/cylinder", {
}) })
local check_pyramid = function(name, param) local check_pyramid = function(name, param)
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"check_pyramid not yet supported with area protection"
)
return nil
end
if worldedit.pos1[name] == nil then if worldedit.pos1[name] == nil then
worldedit.player_notify(name, "no position 1 selected") worldedit.player_notify(name, "no position 1 selected")
return nil return nil
@ -643,6 +674,13 @@ minetest.register_chatcommand("/spiral", {
worldedit.player_notify(name, count .. " nodes added") worldedit.player_notify(name, count .. " nodes added")
end, end,
function(name, param) function(name, param)
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"/spiral not yet supported with area protection"
)
return nil
end
if worldedit.pos1[name] == nil then if worldedit.pos1[name] == nil then
worldedit.player_notify(name, "no position 1 selected") worldedit.player_notify(name, "no position 1 selected")
return nil return nil
@ -766,6 +804,13 @@ minetest.register_chatcommand("/stack2", {
worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions, worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,
function() worldedit.player_notify(name, count .. " nodes stacked") end) function() worldedit.player_notify(name, count .. " nodes stacked") end)
end, function() end, function()
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"/stack2 not yet supported with area protection"
)
return nil
end
return count return count
end)(name,param) -- more hax --wip: clean this up a little bit end)(name,param) -- more hax --wip: clean this up a little bit
end end
@ -791,6 +836,13 @@ minetest.register_chatcommand("/stretch", {
worldedit.player_notify(name, count .. " nodes stretched") worldedit.player_notify(name, count .. " nodes stretched")
end, end,
function(name, param) function(name, param)
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"/stretch not yet supported with area protection"
)
return nil
end
local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$") local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$")
if found == nil then if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param) worldedit.player_notify(name, "invalid usage: " .. param)
@ -1071,6 +1123,13 @@ minetest.register_chatcommand("/load", {
description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin", description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",
privs = {worldedit=true}, privs = {worldedit=true},
func = function(name, param) func = function(name, param)
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"/load not yet supported with area protection"
)
return
end
local pos = get_position(name) local pos = get_position(name)
if pos == nil then return end if pos == nil then return end
@ -1187,6 +1246,13 @@ minetest.register_chatcommand("/mtschemplace", {
description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin", description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",
privs = {worldedit=true}, privs = {worldedit=true},
func = function(name, param) func = function(name, param)
if nil ~= area_protection.areas then
worldedit.player_notify(
name,
"/mtschemplace not yet supported with area protection"
)
return
end
if param == "" then if param == "" then
worldedit.player_notify(name, "no filename specified") worldedit.player_notify(name, "no filename specified")
return return

View File

@ -1,3 +1,11 @@
local area_protection = {}
if minetest.get_modpath(
"areas"
) then
area_protection.areas = areas
end
local safe_region_callback = {} local safe_region_callback = {}
local safe_region_param = {} local safe_region_param = {}
@ -7,6 +15,21 @@ local function check_region(name, param)
worldedit.player_notify(name, "no region selected") worldedit.player_notify(name, "no region selected")
return nil return nil
end end
if nil ~= area_protection.areas then
local allowed, conflicting = area_protection.areas:canInteractInArea(
pos1,
pos2,
name,
false
)
if false == allowed then
worldedit.player_notify(
name,
"region conflicts with non-owned region " .. conflicting
)
return nil
end
end
return worldedit.volume(pos1, pos2) return worldedit.volume(pos1, pos2)
end end
@ -62,4 +85,4 @@ minetest.register_chatcommand("/n", {
}) })
return safe_region, check_region, reset_pending return safe_region, check_region, reset_pending, area_protection