mirror of
https://github.com/minetest-mods/more_chests.git
synced 2026-07-06 18:46:53 -06:00
Localize global variables and strengthen luacheck config (#34)
This commit is contained in:
+22
-23
@@ -1,17 +1,18 @@
|
||||
local function get_inventory_auth_string(player, meta, pos, label)
|
||||
return player:get_player_name() .. " tried to access a locked " .. label .. " belonging to " .. meta:get_string("owner") .. " at " .. minetest.pos_to_string(pos)
|
||||
local name = player:get_player_name()
|
||||
local owner = meta:get_string("owner")
|
||||
local pos_str = minetest.pos_to_string(pos)
|
||||
return ("%s tried to access a locked %s belonging to %s at %s"):format(name, label, owner, pos_str)
|
||||
end
|
||||
|
||||
|
||||
function has_locked_chest_privilege(meta, player)
|
||||
local function has_locked_chest_privilege(meta, player)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function get_allow_metadata_inventory_move(t)
|
||||
local function get_allow_metadata_inventory_move(t)
|
||||
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||
local label, check_privs = t[1], t.check_privs
|
||||
return function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
@@ -24,7 +25,7 @@ function get_allow_metadata_inventory_move(t)
|
||||
end
|
||||
end
|
||||
|
||||
function get_allow_metadata_inventory_put(t)
|
||||
local function get_allow_metadata_inventory_put(t)
|
||||
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||
local label, check_privs = t[1], t.check_privs
|
||||
return function(pos, listname, index, stack, player)
|
||||
@@ -37,7 +38,7 @@ function get_allow_metadata_inventory_put(t)
|
||||
end
|
||||
end
|
||||
|
||||
function get_allow_metadata_inventory_take(t)
|
||||
local function get_allow_metadata_inventory_take(t)
|
||||
setmetatable(t, {__index={check_privs=has_locked_chest_privilege}})
|
||||
local label, check_privs = t[1], t.check_privs
|
||||
return function(pos, listname, index, stack, player)
|
||||
@@ -50,41 +51,39 @@ function get_allow_metadata_inventory_take(t)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function get_inventory_action_string(player, pos, action, label)
|
||||
return player:get_player_name() .. " moves stuff " .. action .. " locked " .. label .. " at " .. minetest.pos_to_string(pos)
|
||||
local name = player:get_player_name()
|
||||
local pos_str = minetest.pos_to_string(pos)
|
||||
return ("%s moves stuff %s locked %s at %s"):format(name, action, label, pos_str)
|
||||
end
|
||||
|
||||
|
||||
function get_on_metadata_inventory_move(label)
|
||||
local function get_on_metadata_inventory_move(label)
|
||||
return function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", get_inventory_action_string(player, pos, "in", label)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function get_on_metadata_inventory_put(label)
|
||||
local function get_on_metadata_inventory_put(label)
|
||||
return function(pos, listname, index, stack, player)
|
||||
minetest.log("action", get_inventory_action_string(player, pos, "to", label))
|
||||
end
|
||||
end
|
||||
|
||||
function get_on_metadata_inventory_take(label)
|
||||
local function get_on_metadata_inventory_take(label)
|
||||
return function(pos, listname, index, stack, player)
|
||||
minetest.log("action", get_inventory_action_string(player, pos, "from", label))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
actions = {
|
||||
has_locked_chest_privilege = has_locked_chest_privilege,
|
||||
get_allow_metadata_inventory_move = get_allow_metadata_inventory_move,
|
||||
get_allow_metadata_inventory_put = get_allow_metadata_inventory_put,
|
||||
get_allow_metadata_inventory_take = get_allow_metadata_inventory_take,
|
||||
get_on_metadata_inventory_move = get_on_metadata_inventory_move,
|
||||
get_on_metadata_inventory_put = get_on_metadata_inventory_put,
|
||||
get_on_metadata_inventory_take = get_on_metadata_inventory_take,
|
||||
local actions = {
|
||||
has_locked_chest_privilege = has_locked_chest_privilege,
|
||||
get_allow_metadata_inventory_move = get_allow_metadata_inventory_move,
|
||||
get_allow_metadata_inventory_put = get_allow_metadata_inventory_put,
|
||||
get_allow_metadata_inventory_take = get_allow_metadata_inventory_take,
|
||||
get_on_metadata_inventory_move = get_on_metadata_inventory_move,
|
||||
get_on_metadata_inventory_put = get_on_metadata_inventory_put,
|
||||
get_on_metadata_inventory_take = get_on_metadata_inventory_take,
|
||||
}
|
||||
return actions
|
||||
|
||||
Reference in New Issue
Block a user