Documentation ¶
Overview ¶
Package chat implements Minecraft's chat message encoding system.
The type Message is the Minecraft chat message. Can be encoded as JSON or net/packet.Field .
It's very recommended that use SetLanguage before using Message.String or Message.ClearString, or the `github.com/Tnze/go-mc/data/en-us` will be used. Note: The package of data/lang/... will SetLanguage on theirs init() so you don't need to call by your self.
Some of these docs is copied from https://wiki.vg/Chat.
Index ¶
- Constants
- func SetLanguage(trans map[string]string)
- func TransCtrlSeq(str string, ansi bool) (dst string, change bool)
- type ClickEvent
- type Decoration
- type HoverEvent
- type HoverSub
- type JsonMessage
- type Message
- func (m Message) Append(extraMsg ...Message) Message
- func (m Message) ClearString() string
- func (m Message) MarshalJSON() ([]byte, error)
- func (m Message) MarshalNBT(w io.Writer) error
- func (m *Message) ReadFrom(r io.Reader) (int64, error)
- func (m Message) SetColor(color string) Message
- func (m Message) String() string
- func (m Message) TagType() byte
- func (m *Message) UnmarshalJSON(raw []byte) (err error)
- func (m *Message) UnmarshalNBT(tagType byte, r nbt.DecoderReader) error
- func (m Message) WriteTo(w io.Writer) (int64, error)
- type Type
Constants ¶
const ( Chat = iota System GameInfo SayCommand MsgCommand TeamMsgCommand EmoteCommand TellrawCommand )
const ( Black = "black" DarkBlue = "dark_blue" DarkGreen = "dark_green" DarkAqua = "dark_aqua" DarkRed = "dark_red" DarkPurple = "dark_purple" Gold = "gold" Gray = "gray" DarkGray = "dark_gray" Blue = "blue" Green = "green" Aqua = "aqua" Red = "red" LightPurple = "light_purple" Yellow = "yellow" White = "white" )
Colors
Variables ¶
This section is empty.
Functions ¶
func SetLanguage ¶
SetLanguage set the default language used by String() and ClearString().
Types ¶
type ClickEvent ¶
type ClickEvent struct { Action string `json:"action" nbt:"action"` Value string `json:"value" nbt:"value"` }
ClickEvent defines an event that occurs when this component is clicked.
func ChangePage ¶
func ChangePage(page int) *ClickEvent
ChangePage create a ClickEvent usable within written books. Changes the page of the book to the given page, starting at 1. For instance, "value":1 switches the book to the first page. If the page is less than one or beyond the number of pages in the book, the event is ignored.
func CopyToClipboard ¶
func CopyToClipboard(text string) *ClickEvent
CopyToClipboard create a ClickEvent copies the given text to the client's clipboard when clicked.
func OpenURL ¶
func OpenURL(url string) *ClickEvent
OpenURL create a ClickEvent opens the given URL in the default web browser. Ignored if the player has opted to disable links in chat; may open a GUI prompting the user if the setting for that is enabled. The link's protocol must be set and must be http or https, for security reasons.
func RunCommand ¶
func RunCommand(cmd string) *ClickEvent
RunCommand create a ClickEvent runs the given command. Not required to be a command - clicking this only causes the client to send the given content as a chat message, so if not prefixed with /, they will say the given text instead. If used in a book GUI, the GUI is closed after clicking.
func SuggestCommand ¶
func SuggestCommand(cmd string) *ClickEvent
SuggestCommand create a ClickEvent replaces the content of the chat box with the given text - usually a command, but it is not required to be a command (commands should be prefixed with /). This is only usable for messages in chat.
type Decoration ¶
type Decoration struct { TranslationKey string `nbt:"translation_key"` Parameters []string `nbt:"parameters"` Style struct { Bold bool `nbt:"bold,omitempty"` Italic bool `nbt:"italic,omitempty"` UnderLined bool `nbt:"underlined,omitempty"` StrikeThrough bool `nbt:"strikethrough,omitempty"` Obfuscated bool `nbt:"obfuscated,omitempty"` Color string `nbt:"color,omitempty"` Insertion string `nbt:"insertion,omitempty"` Font string `nbt:"font,omitempty"` } `nbt:"style,omitempty"` }
type HoverEvent ¶
type HoverEvent struct { Action string `json:"action" nbt:"action"` Contents any `json:"contents" nbt:"contents"` // Didn't handled yet Value Message `json:"value" nbt:"value"` // Legacy }
HoverEvent defines an event that occurs when this component hovered over.
func ShowEntity ¶
func ShowEntity(entity string) *HoverEvent
ShowEntity show an entity describing by the S-NBT, nbt.StringifiedMessage could help. See: https://wiki.vg/Chat#:~:text=show_entity,given%20entity%20loaded.
func ShowItem ¶
func ShowItem(item string) *HoverEvent
ShowItem show the item to display. Item is encoded as the S-NBT format, nbt.StringifiedMessage could help. See: https://wiki.vg/Chat#:~:text=show_item,in%20red%20instead.
type JsonMessage ¶
type JsonMessage Message
JsonMessage is Message, unless when it is going to be Json instead of NBT
type Message ¶
type Message struct { Text string `json:"text" nbt:"text"` Bold bool `json:"bold,omitempty" nbt:"bold,omitempty"` // 粗体 Italic bool `json:"italic,omitempty" nbt:"italic,omitempty"` // 斜体 UnderLined bool `json:"underlined,omitempty" nbt:"underlined,omitempty"` // 下划线 StrikeThrough bool `json:"strikethrough,omitempty" nbt:"strikethrough,omitempty"` // 删除线 Obfuscated bool `json:"obfuscated,omitempty" nbt:"obfuscated,omitempty"` // 随机 // Font of the message, could be one of minecraft:uniform, minecraft:alt or minecraft:default // This option is only valid on 1.16+, otherwise the property is ignored. Font string `json:"font,omitempty" nbt:"font,omitempty"` // 字体 Color string `json:"color,omitempty" nbt:"color,omitempty"` // 颜色 // Insertion contains text to insert. Only used for messages in chat. // When shift is held, clicking the component inserts the given text // into the chat box at the cursor (potentially replacing selected text). Insertion string `json:"insertion,omitempty" nbt:"insertion,omitempty"` ClickEvent *ClickEvent `json:"clickEvent,omitempty" nbt:"clickEvent,omitempty"` HoverEvent *HoverEvent `json:"hoverEvent,omitempty" nbt:"hoverEvent,omitempty"` Translate string `json:"translate,omitempty" nbt:"translate,omitempty"` With []Message `json:"with,omitempty" nbt:"with,omitempty"` Extra []Message `json:"extra,omitempty" nbt:"extra,omitempty"` }
Message is a message sent by other
func TranslateMsg ¶
func (Message) Append ¶
Append extra message to the end of the message and return the new one. The source message remains unchanged.
func (Message) ClearString ¶
ClearString return the message String without escape sequence for ansi color.
func (Message) MarshalJSON ¶
func (Message) String ¶
String return the message string with escape sequence for ansi color. To convert Translated Message to string, you must set On Windows, you may want print this string using github.com/mattn/go-colorable.
func (*Message) UnmarshalJSON ¶
func (*Message) UnmarshalNBT ¶
func (m *Message) UnmarshalNBT(tagType byte, r nbt.DecoderReader) error