47
47
48
48
core .chatcommands = core .registered_chatcommands -- BACKWARDS COMPATIBILITY
49
49
50
+ local msg_time_threshold =
51
+ tonumber (core .settings :get (" chatcommand_msg_time_threshold" )) or 0.1
50
52
core .register_on_chat_message (function (name , message )
51
53
if message :sub (1 ,1 ) ~= " /" then
52
54
return
@@ -73,7 +75,9 @@ core.register_on_chat_message(function(name, message)
73
75
local has_privs , missing_privs = core .check_player_privs (name , cmd_def .privs )
74
76
if has_privs then
75
77
core .set_last_run_mod (cmd_def .mod_origin )
78
+ local t_before = minetest .get_us_time ()
76
79
local success , result = cmd_def .func (name , param )
80
+ local delay = (minetest .get_us_time () - t_before ) / 1000000
77
81
if success == false and result == nil then
78
82
core .chat_send_player (name , " -!- " .. S (" Invalid command usage." ))
79
83
local help_def = core .registered_chatcommands [" help" ]
@@ -83,8 +87,20 @@ core.register_on_chat_message(function(name, message)
83
87
core .chat_send_player (name , helpmsg )
84
88
end
85
89
end
86
- elseif result then
87
- core .chat_send_player (name , result )
90
+ else
91
+ if delay > msg_time_threshold then
92
+ -- Show how much time it took to execute the command
93
+ if result then
94
+ result = result ..
95
+ minetest .colorize (" #f3d2ff" , " (%.5g s)" ):format (delay )
96
+ else
97
+ result = minetest .colorize (" #f3d2ff" ,
98
+ " Command execution took %.5f s" ):format (delay )
99
+ end
100
+ end
101
+ if result then
102
+ core .chat_send_player (name , result )
103
+ end
88
104
end
89
105
else
90
106
core .chat_send_player (name ,
0 commit comments