init.lua 763 B

123456789101112131415161718192021222324252627
  1. -- The idea here is to completely wrap all chat commands, both existing ones and
  2. -- those to be registered in the future, with a function that intercepts their
  3. -- return values and deals with them.
  4. local function wrap_commands()
  5. local data = minetest.registered_chatcommands
  6. for k, v in pairs(data) do
  7. local old = v.func
  8. v.func = function(...)
  9. local result, message = old(...)
  10. if message and message ~= "" then
  11. -- But if the message already has a '#' symbol, pass it through.
  12. if message:sub(1, 1) ~= "#" then
  13. message = "# Server: " .. message
  14. end
  15. end
  16. -- The *builtin* will send the message via core.chat_send_player.
  17. return result, message
  18. end
  19. end
  20. end
  21. -- Execute action after startup.
  22. minetest.after(0, wrap_commands)