chat

package
v1.16.5-pre2-vacpp Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package chat implements Minecraft's chat message encoding system.

The type Message is the Minecraft chat message. Can be encode as JSON or net/packet.Field .

It's very recommended that use SetLanguage before using Message.String or Message.ClearString, or the `github.com/VacPlusPlus/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.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLanguage

func SetLanguage(trans map[string]string)

SetLanguage set the translate map to this map.

func TransCtrlSeq

func TransCtrlSeq(str string, ansi bool) (dst string, change bool)

TransCtrlSeq will transform control sequences into ANSI code or simply filter them. Depends on the second argument. if the str contains control sequences, returned change=true.

Types

type Message

type Message jsonChat

Message is a message sent by other

func Text

func Text(str string) Message

func TranslateMsg

func TranslateMsg(key string, with ...Message) (m Message)
Example
package main

import (
	"fmt"
	"github.com/VacPlusPlus/go-mc/chat"
)

func main() {
	fmt.Println(chat.TranslateMsg("translation.test.none"))
	fmt.Println(chat.TranslateMsg(
		// translation.test.complex == "Prefix, %s%[2]s again %s and %[1]s lastly %s and also %[1]s again!"
		"translation.test.complex",
		chat.Text("1111"),
		chat.Text("2222"),
		chat.Text("3333"),
	).String())
}
Output:

Hello, world!
Prefix, 11112222 again 3333 and 1111 lastly 2222 and also 1111 again!

func (*Message) Append

func (m *Message) Append(extraMsg ...Message)
Example
package main

import (
	"fmt"
	"github.com/VacPlusPlus/go-mc/chat"
)

func main() {
	msg := chat.Message{Text: "1111"}
	msg.Append(
		chat.Message{Text: "22222"},
		chat.Message{Text: "333333"},
		chat.Message{Text: "4444444"},
	)
	fmt.Print(msg)
}
Output:

1111222223333334444444

func (Message) ClearString

func (m Message) ClearString() string

ClearString return the message String without escape sequence for ansi color.

func (*Message) ReadFrom

func (m *Message) ReadFrom(r io.Reader) (int64, error)

Decode for a ChatMsg packet

func (Message) String

func (m Message) String() 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/matte/go-colorable.

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(jsonMsg []byte) (err error)

UnmarshalJSON decode json to Message

func (Message) WriteTo

func (m Message) WriteTo(w io.Writer) (int64, error)

Encode for a ChatMsg packet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL