From 876a2f7cef72bc807e84f8cac1fa94c9410c5134 Mon Sep 17 00:00:00 2001 From: nixnoxus Date: Wed, 30 Mar 2022 23:57:08 +0200 Subject: [PATCH] add `default.log_action` function --- mods/default/chests.lua | 11 +++-------- mods/default/functions.lua | 12 ++++++++++-- mods/default/nodes.lua | 9 +++------ mods/vessels/init.lua | 9 +++------ 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/mods/default/chests.lua b/mods/default/chests.lua index f4462ae7..b303ed22 100644 --- a/mods/default/chests.lua +++ b/mods/default/chests.lua @@ -224,18 +224,13 @@ function default.chest.register_chest(prefixed_name, d) def.on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name() .. - " moves stuff in chest at " .. minetest.pos_to_string(pos)) + default.log_action(player, pos, "moves stuff in chest") end def.on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " moves " .. stack:get_name() .. - " to chest at " .. minetest.pos_to_string(pos)) + default.log_action(player, pos, "moves " .. stack:get_name() .. " to chest") end def.on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " takes " .. stack:get_name() .. - " from chest at " .. minetest.pos_to_string(pos)) + default.log_action(player, pos, "takes " .. stack:get_name() .. " from chest") end local def_opened = table.copy(def) diff --git a/mods/default/functions.lua b/mods/default/functions.lua index 4d89a384..c8e8f13e 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -717,8 +717,8 @@ end -- --- NOTICE: This method is not an official part of the API yet. --- This method may change in future. +-- NOTICE: This methods are not an official part of the API yet. +-- This methods may change in future. -- function default.can_interact_with_node(player, pos) @@ -757,3 +757,11 @@ function default.can_interact_with_node(player, pos) return false end + +function default.log_action(player, pos, message) + -- only log actions of real players + if player and not player.is_fake_player and player:is_player() then + minetest.log("action", player:get_player_name() .. + " " .. message .. " at " .. minetest.pos_to_string(pos)) + end +end diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index a2974517..6d74171e 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -2551,18 +2551,15 @@ minetest.register_node("default:bookshelf", { return 0 end, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name() .. - " moves stuff in bookshelf at " .. minetest.pos_to_string(pos)) + default.log_action(player, pos, "moves stuff in bookshelf") update_bookshelf(pos) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " puts stuff to bookshelf at " .. minetest.pos_to_string(pos)) + default.log_action(player, pos, "puts stuff to bookshelf") update_bookshelf(pos) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " takes stuff from bookshelf at " .. minetest.pos_to_string(pos)) + default.log_action(player, pos, "takes stuff from bookshelf") update_bookshelf(pos) end, on_blast = function(pos) diff --git a/mods/vessels/init.lua b/mods/vessels/init.lua index 71a06893..eb66dddd 100644 --- a/mods/vessels/init.lua +++ b/mods/vessels/init.lua @@ -75,18 +75,15 @@ minetest.register_node("vessels:shelf", { return 0 end, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name() .. - " moves stuff in vessels shelf at ".. minetest.pos_to_string(pos)) + default.log_action(player, pos, "moves stuff in vessels shelf") update_vessels_shelf(pos) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " moves stuff to vessels shelf at ".. minetest.pos_to_string(pos)) + default.log_action(player, pos, "moves stuff to vessels shelf") update_vessels_shelf(pos) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " takes stuff from vessels shelf at ".. minetest.pos_to_string(pos)) + default.log_action(player, pos, "takes stuff from vessels shelf") update_vessels_shelf(pos) end, on_blast = function(pos)