Decode ChatMsg as chat.Message but not pk.String

This commit is contained in:
JunDao
2019-05-02 12:18:00 +08:00
parent 1f0bdf19a3
commit c74cffcc22
4 changed files with 43 additions and 36 deletions

View File

@ -3,9 +3,11 @@ package chat
import (
"encoding/json"
"fmt"
"io"
"strings"
"github.com/Tnze/go-mc/data"
pk "github.com/Tnze/go-mc/net/packet"
)
//Message is a message sent by other
@ -36,6 +38,16 @@ func (m *Message) UnmarshalJSON(jsonMsg []byte) (err error) {
return
}
//Decode a ChatMsg packet
func (m *Message) Decode(r pk.ComByteReader) error {
var Len pk.VarInt
if err := Len.Decode(r); err != nil {
return err
}
return json.NewDecoder(io.LimitReader(r, int64(Len))).Decode(m)
}
var colors = map[string]int{
"black": 30,
"dark_blue": 34,