quectocraft2/plugins/mcchat.lua

109 lines
2.1 KiB
Lua
Raw Normal View History

2023-08-01 04:56:38 +00:00
return {
-- id is required, server_version is recommended, all other fields are optional
id = "mcchat",
name = "MCChat",
version = "0.1.0",
2023-08-08 02:24:28 +00:00
priority = 80,
2023-08-01 04:56:38 +00:00
server_version = "0.2",
authors = {"trimill"},
description = "Adds basic chat and join/leave messages",
license = "MIT",
2023-08-08 02:24:28 +00:00
init = function(self)
srv:add_command("tell")
srv:add_command("msg")
srv:add_command("me")
end,
2023-08-01 04:56:38 +00:00
on_join = function(self, _, name)
srv:info(name .. " joined the game")
2023-08-08 02:24:28 +00:00
srv:send_msg({
2023-08-01 04:56:38 +00:00
translate = "multiplayer.player.joined",
with = { { text = name } },
color = "yellow",
})
end,
on_leave = function(self, _, name)
srv:info(name .. " left the game")
2023-08-08 02:24:28 +00:00
srv:send_msg({
2023-08-01 04:56:38 +00:00
translate = "multiplayer.player.left",
with = { { text = name } },
color = "yellow",
})
end,
on_message = function(self, msg, _, name)
srv:info("<" .. name .. "> " .. msg)
2023-08-08 02:24:28 +00:00
srv:send_chat({
2023-08-01 04:56:38 +00:00
translate = "chat.type.text",
with = {
{ text = name },
{ text = msg },
},
})
2023-08-08 02:24:28 +00:00
return true
2023-08-01 04:56:38 +00:00
end,
2023-08-08 02:24:28 +00:00
on_command = function(self, cmd, args, _, uuid, name)
if cmd == "me" then
local msg = table.concat(args, " ")
srv:info("* " .. name .. " " .. msg)
srv:send_chat({
translate = "chat.type.emote",
with = {
{ text = name },
{ text = msg }
},
})
elseif cmd == "tell" or cmd == "msg" then
local target = args[1]
if target == nil then
srv:send_msg({
text = cmd .. ": no target specified",
color = "red",
}, uuid)
return
end
local target_uuid = srv:get_uuid(target)
if target_uuid == nil then
srv:send_msg({
text = cmd .. ": player not found: " .. target,
color = "red",
}, uuid)
return
end
local msg = table.concat(args, " ", 2)
srv:info(name .. " whispers to " .. target .. ": " .. msg)
srv:send_chat({
translate = "commands.message.display.outgoing",
with = {
{ text = target },
{ text = msg }
},
color = "gray",
italic = true,
}, uuid)
srv:send_chat({
translate = "commands.message.display.incoming",
with = {
{ text = name },
{ text = msg }
},
color = "gray",
italic = true,
}, target_uuid);
end
end
2023-08-01 04:56:38 +00:00
}