preemtive optimization - caching a per-node player permission check
before the function actually works
This commit is contained in:
parent
bde3281508
commit
11647fca93
|
@ -102,6 +102,9 @@ worldedit.can_edit_volume = function(--[[name, ]]volume, volfunc--[[, param]])
|
||||||
|
|
||||||
--[[I need to use a special per-command region (think /stack, or even worse, /move), the same one safe_region uses, but corner points instead of count... instead of a for loop interpolating between pos1 and pos2]]--
|
--[[I need to use a special per-command region (think /stack, or even worse, /move), the same one safe_region uses, but corner points instead of count... instead of a for loop interpolating between pos1 and pos2]]--
|
||||||
|
|
||||||
|
--cache the result of this function for later
|
||||||
|
local has_worldedit = minetest.check_player_privs(name, {worldedit=true})
|
||||||
|
|
||||||
--all or nothing here
|
--all or nothing here
|
||||||
for i in volume do
|
for i in volume do
|
||||||
--[[
|
--[[
|
||||||
|
@ -112,6 +115,7 @@ worldedit.can_edit_volume = function(--[[name, ]]volume, volfunc--[[, param]])
|
||||||
|
|
||||||
This needs testing for the other changes first.
|
This needs testing for the other changes first.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
--Is it owned?
|
--Is it owned?
|
||||||
if minetest.is_protected(i) then
|
if minetest.is_protected(i) then
|
||||||
--Is it someone else's?
|
--Is it someone else's?
|
||||||
|
@ -126,7 +130,7 @@ worldedit.can_edit_volume = function(--[[name, ]]volume, volfunc--[[, param]])
|
||||||
|
|
||||||
--no-man's land
|
--no-man's land
|
||||||
--can I edit that?
|
--can I edit that?
|
||||||
elseif not minetest.check_player_privs(name, {worldedit=true}) then --cache this check?
|
elseif not has_worldedit then --use cached check
|
||||||
minetest.chat_send_player(name, "You can only edit area in which you own a plot (missing worldedit privilege)")
|
minetest.chat_send_player(name, "You can only edit area in which you own a plot (missing worldedit privilege)")
|
||||||
--volfunc(name, param) placeholder
|
--volfunc(name, param) placeholder
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue