Documentation ¶
Overview ¶
Package chat is used to construct messages that can be converted to Minecraft's JSON chat format. For more information about this format, visit https:wiki.vg/index.php?title=Chat&oldid=5640. Please note that this package does not implement new functionality from versions newer than 1.8.X, such as web colors.
A simple message can be constructed like this:
msg := Msg{ Text: "Hello", Bold: StyleOn, Color: ColorGreen, }
You can use json.Encoder to convert msg to JSON.
For more complex messages, you might want to use a Builder:
msg := NewBuilder("Hello, ").Bold().Color(ColorRed). Append("world").NotBold().Color(ColorYellow). Build()
If you change a style or color setting in a Builder, that change applies to the current text but also to all text that is appended later. If you want to prevent this, you must explicitly disable the style or change the color back after calling Append.
Index ¶
- type Builder
- func (b *Builder) Append(text string) *Builder
- func (b *Builder) Bold() *Builder
- func (b *Builder) Build() *Msg
- func (b *Builder) Color(c Color) *Builder
- func (b *Builder) Italic() *Builder
- func (b *Builder) NotBold() *Builder
- func (b *Builder) NotItalic() *Builder
- func (b *Builder) NotObfuscated() *Builder
- func (b *Builder) NotStrikethrough() *Builder
- func (b *Builder) NotUnderlined() *Builder
- func (b *Builder) Obfuscated() *Builder
- func (b *Builder) Strikethrough() *Builder
- func (b *Builder) Underlined() *Builder
- type Color
- type Msg
- type Style
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a utility for constructing more complex Msg objects. An instance should be obtained using NewBuilder.
func NewBuilder ¶
NewBuilder constructs a new Builder instance with initial text.
func (*Builder) Build ¶
Build constructs a Msg using all the previously applied options. You should not use and/or keep a reference to the Builder anymore after calling this function.
func (*Builder) NotObfuscated ¶
NotObfuscated disables the obfuscated style for the current text.
func (*Builder) NotStrikethrough ¶
NotStrikethrough disables the strikethrough style for the current text.
func (*Builder) NotUnderlined ¶
NotUnderlined disables the underlined style for the current text.
func (*Builder) Obfuscated ¶
Obfuscated enables the obfuscated style for the current text.
func (*Builder) Strikethrough ¶
Strikethrough enables the strikethrough style for the current text.
func (*Builder) Underlined ¶
Underlined enables the underlined style for the current text.
type Color ¶
type Color uint8
Color represents a color used in a Msg.
const ( // ColorReset resets the color to the default. Which value that is depends on the context of the Msg. ColorReset Color = iota ColorBlack ColorDarkBlue ColorDarkGreen ColorDarkCyan ColorDarkRed ColorPurple ColorGold ColorGray ColorDarkGray ColorBlue ColorGreen ColorCyan ColorRed ColorPink ColorYellow ColorWhite )
func (Color) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
type Msg ¶
type Msg struct { Text string `json:"text"` Bold Style `json:"bold,omitempty"` Italic Style `json:"italic,omitempty"` Underlined Style `json:"underlined,omitempty"` Strikethrough Style `json:"strikethrough,omitempty"` Obfuscated Style `json:"obfuscated,omitempty"` Color Color `json:"color,omitempty"` Extra []Msg `json:"extra,omitempty"` }
Msg represents a chat message. For complex messages, it might be easier to use Builder to construct them.
type Style ¶
type Style uint8
func (Style) MarshalText ¶
MarshalText implements encoding.TextMarshaler.