Home / Misc

Chat colors

The color table provides Minecraft chat color codes. Use the constants directly, or call color.translate(text) to convert ampersand codes such as &a and &6.

API

color.black ... color.white color.translate(text)

color.translate(text) returns a string, converting &0โ€“&9 and &aโ€“&f to Minecraft formatting codes. Matching is case-insensitive; other ampersand sequences are unchanged.

Color names

black, dark_blue, dark_green, dark_aqua, dark_red, purple, gold, gray, dark_gray, blue, green, aqua, red, pink, yellow, and white.

Examples

command('error', function(sender)
  sender:send(color.red .. 'An error occurred.')
  server.broadcast(color.translate('&6[Server] &fPlease contact an admin.'))
  return true
end)

Color a player's chat message

The chat event can rewrite a player's message body. The server's standard <name> prefix is not changed by this example.

on('chat', function(e)
  e.message = color.green .. e.message
end)

To style the name and whole line, translate only the plugin-generated prefix, cancel the original message, and broadcast a replacement:

on('chat', function(e)
  local prefix = color.translate('&7<&b' .. e.player.name .. '&7> &f')
  e:cancel()
  server.broadcast(prefix .. e.message)
end)

Notes

Players cannot type the raw Minecraft ยง character in chat; server input validation rejects it. Plugins can add formatting codes. Translating player-supplied text also converts any &0โ€“&f sequences in it. If multiple plugins replace and rebroadcast chat, each may produce a separate line because cancellation does not stop later event listeners.