nbt chat message
This commit is contained in:
@ -51,7 +51,7 @@ const (
|
|||||||
|
|
||||||
// Message is a message sent by other
|
// Message is a message sent by other
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Text string `json:"text" nbt:"text,omitempty"`
|
Text string `json:"text" nbt:"text,default"`
|
||||||
|
|
||||||
Bold bool `json:"bold,omitempty" nbt:"bold,omitempty"` // 粗体
|
Bold bool `json:"bold,omitempty" nbt:"bold,omitempty"` // 粗体
|
||||||
Italic bool `json:"italic,omitempty" nbt:"italic,omitempty"` // 斜体
|
Italic bool `json:"italic,omitempty" nbt:"italic,omitempty"` // 斜体
|
||||||
|
@ -387,7 +387,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
// Fall back to linear search.
|
// Fall back to linear search.
|
||||||
for i := range fields.list {
|
for i := range fields.list {
|
||||||
ff := &fields.list[i]
|
ff := &fields.list[i]
|
||||||
if strings.EqualFold(ff.name, tn) {
|
if strings.EqualFold(ff.name, tn) || ff.asDefault && tn == "" {
|
||||||
f = ff
|
f = ff
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ type field struct {
|
|||||||
index []int
|
index []int
|
||||||
typ reflect.Type
|
typ reflect.Type
|
||||||
omitEmpty bool
|
omitEmpty bool
|
||||||
|
asDefault bool
|
||||||
asList bool
|
asList bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ func typeFields(t reflect.Type) (tInfo structFields) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse options
|
// parse options
|
||||||
var omitEmpty, asList bool
|
var omitEmpty, asList, asDefault bool
|
||||||
for opts != "" {
|
for opts != "" {
|
||||||
var name string
|
var name string
|
||||||
name, opts, _ = strings.Cut(opts, ",")
|
name, opts, _ = strings.Cut(opts, ",")
|
||||||
@ -114,6 +115,8 @@ func typeFields(t reflect.Type) (tInfo structFields) {
|
|||||||
omitEmpty = true
|
omitEmpty = true
|
||||||
case "list":
|
case "list":
|
||||||
asList = true
|
asList = true
|
||||||
|
case "default":
|
||||||
|
asDefault = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Deprecated: use `nbt:",list"` instead.
|
// Deprecated: use `nbt:",list"` instead.
|
||||||
@ -133,6 +136,7 @@ func typeFields(t reflect.Type) (tInfo structFields) {
|
|||||||
index: index,
|
index: index,
|
||||||
typ: ft,
|
typ: ft,
|
||||||
omitEmpty: omitEmpty,
|
omitEmpty: omitEmpty,
|
||||||
|
asDefault: asDefault,
|
||||||
asList: asList,
|
asList: asList,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user