]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/client/chatcommands.lua
Improve testSerializeJsonString unit tests
[dragonfireclient.git] / builtin / client / chatcommands.lua
index 2b8cc4acd7c8526363e2db775e4f898ad56a01b7..a563a66276f745f6868bcb1a23464e9dbdb67fe3 100644 (file)
@@ -1,14 +1,13 @@
 -- Minetest: builtin/client/chatcommands.lua
 
-
-core.register_on_sending_chat_messages(function(message)
+core.register_on_sending_chat_message(function(message)
        if message:sub(1,2) == ".." then
                return false
        end
 
        local first_char = message:sub(1,1)
        if first_char == "/" or first_char == "." then
-               core.display_chat_message(core.gettext("issued command: ") .. message)
+               core.display_chat_message(core.gettext("Issued command: ") .. message)
        end
 
        if first_char ~= "." then
@@ -16,22 +15,27 @@ core.register_on_sending_chat_messages(function(message)
        end
 
        local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
-       param = param or ""
+       param = param or ""
 
        if not cmd then
-               core.display_chat_message(core.gettext("-!- Empty command"))
+               core.display_chat_message("-!- " .. core.gettext("Empty command."))
+               return true
+       end
+
+       -- Run core.registered_on_chatcommand callbacks.
+       if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
                return true
        end
 
        local cmd_def = core.registered_chatcommands[cmd]
        if cmd_def then
                core.set_last_run_mod(cmd_def.mod_origin)
-               local _, message = cmd_def.func(param)
-               if message then
-                       core.display_chat_message(message)
+               local _, result = cmd_def.func(param)
+               if result then
+                       core.display_chat_message(result)
                end
        else
-               core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
+               core.display_chat_message("-!- " .. core.gettext("Invalid command: ") .. cmd)
        end
 
        return true
@@ -40,8 +44,13 @@ end)
 core.register_chatcommand("list_players", {
        description = core.gettext("List online players"),
        func = function(param)
-               local players = table.concat(core.get_player_names(), ", ")
-               core.display_chat_message(core.gettext("Online players: ") .. players)
+               local player_names = core.get_player_names()
+               if not player_names then
+                       return false, core.gettext("This command is disabled by server.")
+               end
+
+               local players = table.concat(player_names, ", ")
+               return true, core.gettext("Online players: ") .. players
        end
 })
 
@@ -56,7 +65,7 @@ core.register_chatcommand("clear_chat_queue", {
        description = core.gettext("Clear the out chat queue"),
        func = function(param)
                core.clear_out_chat_queue()
-               return true, core.gettext("The out chat queue is now empty")
+               return true, core.gettext("The out chat queue is now empty.")
        end,
 })