Skip to content

Commit

Permalink
chat: text is default field
Browse files Browse the repository at this point in the history
  • Loading branch information
patyhank committed Aug 25, 2024
1 parent bd1350a commit e614a23
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chat/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (

// Message is a message sent by other
type Message struct {
Text string `json:"text" nbt:"text"`
Text string `json:"text" nbt:"text,default"`

Bold bool `json:"bold,omitempty" nbt:"bold,omitempty"` // 粗体
Italic bool `json:"italic,omitempty" nbt:"italic,omitempty"` // 斜体
Expand Down
21 changes: 21 additions & 0 deletions chat/nbtmessage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package chat

import (
"github.com/Tnze/go-mc/nbt"
"os"
"testing"
)

func TestNbtExtraText(t *testing.T) {
//SNBT: {extra: [{extra: [{color: "dark_gray",text: "> "},{: "test"}],text: ""}],text: ""}
f, _ := os.Open("testdata/chat.nbt")
d := nbt.NewDecoder(f)
var m Message
if _, err := d.Decode(&m); err != nil {
t.Fatal(err)
}

if m.ClearString() != "> test" {
t.Fatalf("gets %q, wants %q", m.ClearString(), "> test")
}
}
Binary file added chat/testdata/chat.nbt
Binary file not shown.

0 comments on commit e614a23

Please sign in to comment.