From a6d940abda11e09342685893ec28b1acce20cf45 Mon Sep 17 00:00:00 2001 From: nixnoxus Date: Sun, 1 May 2022 01:30:15 +0200 Subject: [PATCH] `default.log_player_action` accepts pos as table --- game_api.txt | 2 +- mods/default/functions.lua | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/game_api.txt b/game_api.txt index ad7bbe03..c8b4cec3 100644 --- a/game_api.txt +++ b/game_api.txt @@ -1136,7 +1136,7 @@ the log. * `player` The player who performed the action * `message_parts` Any mumber of message parts describing the action in 3rd person singular present tense. It can also - contain a `vector` which is logged as "(X,Y,Z)" + contain a `pos` which is logged as "(X,Y,Z)" `default.set_inventory_action_loggers(def, name)` diff --git a/mods/default/functions.lua b/mods/default/functions.lua index a263fe71..0afd97ed 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -721,6 +721,11 @@ end local log_non_player_actions = minetest.settings:get_bool("log_non_player_actions", false) +local is_pos = function(v) + return type(v) == "table" and + type(v.x) == "number" and type(v.y) == "number" and type(v.z) == "number" +end + function default.log_player_action(player, ...) local msg = player:get_player_name() if player.is_fake_player or not player:is_player() then @@ -732,7 +737,7 @@ function default.log_player_action(player, ...) end for _, v in ipairs({...}) do -- translate pos - local part = vector.check(v) and minetest.pos_to_string(v) or v + local part = is_pos(v) and minetest.pos_to_string(v) or v -- no leading spaces before punctuation marks msg = msg .. (string.match(part, "^[;,.]") and "" or " ") .. part end