Documentation
¶
Overview ¶
Package micromessage is a MiniMessage (https://docs.advntr.dev/minimessage) parser and renderer for Gate/Minekube's component model (go.minekube.com/common/minecraft/component).
Example ¶
This mirrors how you'd use the library inside a Gate plugin:
msg, err := micromessage.Deserialize("<gradient:aqua:blue>Welcome</gradient> <red>%s</red>!")
if err != nil {
return err
}
return player.SendMessage(msg) // player is a go.minekube.com/gate proxy.Player
player.SendMessage takes a component.Component (msg component.Component, opts ...command.MessageOption), and *component.Text (what Deserialize returns) implements that interface directly, so no adapting is needed.
package main
import (
"fmt"
"github.com/Hoppou-Hangout/micromessage"
)
func main() {
msg, err := micromessage.Deserialize(`<gradient:aqua:blue>Welcome</gradient> <red><bold>friend</bold></red>!`)
if err != nil {
panic(err)
}
fmt.Println(len(msg.Children()) > 0)
}
Output: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deserialize ¶
Deserialize parses a MiniMessage string into a *component.Text tree compatible with go.minekube.com/common and, by extension, Gate.
func MustDeserialize ¶ added in v0.3.1
MustDeserialize is similar to Deserialize but panics on error.
Types ¶
type Node ¶ added in v0.3.1
type Node struct {
Kind Kind
Text string // set when Kind == KindText
Name string // tag name, set when Kind == KindElement
Args []string
SelfClosed bool // true for <tag/>
Closed bool // true if an explicit </tag> was found; false = auto-closed
Children []*Node
}
Node is either a run of text or a tag, mirroring how MiniMessage really works: styling tags don't have "children" in a strict sense, they wrap whatever text/tags follow until an explicit close or the end of input.