init.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. if not minetest.global_exists("chat_echo") then chat_echo = {} end
  2. chat_echo.modpath = minetest.get_modpath("chat_echo")
  3. chat_echo.players = chat_echo.players or {}
  4. -- Player chat is echoed by default, since most players need it now.
  5. chat_echo.echo_chat = function(pname, chat)
  6. if chat_echo.players[pname] then
  7. minetest.chat_send_player(pname, chat)
  8. end
  9. end
  10. chat_echo.set_echo = function(pname, value)
  11. if value == true then
  12. chat_echo.players[pname] = true
  13. chat_echo.modstorage:set_int(pname .. ":echo", 1)
  14. minetest.chat_send_player(pname, "# Server: The server will now echo your chat back to you.")
  15. elseif value == false then
  16. chat_echo.players[pname] = nil
  17. chat_echo.modstorage:set_int(pname .. ":echo", 2)
  18. minetest.chat_send_player(pname, "# Server: The server will no longer echo your chat to you.")
  19. end
  20. end
  21. chat_echo.get_echo = function(pname)
  22. if chat_echo.players[pname] then
  23. return true
  24. else
  25. return false
  26. end
  27. end
  28. chat_echo.on_joinplayer = function(player)
  29. local pname = player:get_player_name()
  30. chat_echo.players[pname] = true
  31. local value = chat_echo.modstorage:get_int(pname .. ":echo")
  32. if value == 1 then
  33. -- Chat echo should stay enabled.
  34. elseif value == 2 then
  35. -- Chat echo must be disabled.
  36. -- (Player must still have older client that auto-predicts chat.)
  37. chat_echo.players[pname] = nil
  38. end
  39. end
  40. chat_echo.on_leaveplayer = function(player)
  41. local pname = player:get_player_name()
  42. chat_echo.players[pname] = nil
  43. end
  44. if not chat_echo.run_once then
  45. chat_echo.modstorage = minetest.get_mod_storage()
  46. minetest.register_on_joinplayer(function(...)
  47. return chat_echo.on_joinplayer(...)
  48. end)
  49. minetest.register_on_leaveplayer(function(...)
  50. return chat_echo.on_leaveplayer(...)
  51. end)
  52. local c = "chat_echo:core"
  53. local f = chat_echo.modpath .. "/init.lua"
  54. reload.register_file(c, f, false)
  55. chat_echo.run_once = true
  56. end