From ed3aa701e88e05ae8f90c0cf09d0838e8c89a0c6 Mon Sep 17 00:00:00 2001 From: Robin Date: Thu, 8 Sep 2022 17:16:36 +0200 Subject: [PATCH] Fix nil pointer --- minecraft/component/codec/json.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/minecraft/component/codec/json.go b/minecraft/component/codec/json.go index 03ed964..e11b7c0 100644 --- a/minecraft/component/codec/json.go +++ b/minecraft/component/codec/json.go @@ -143,10 +143,16 @@ const ( ) func (j *Json) encodeText(o obj, t *Text) error { + if t == nil { + return nil + } o[text] = t.Content return j.encodeComponent(o, t, extra) } func (j *Json) encodeTranslation(o obj, t *Translation) error { + if t == nil { + return nil + } o[translate] = t.Key return j.encodeComponent(o, t, translateWith) } @@ -317,7 +323,7 @@ func (j *Json) decodeComponent(o obj) (c Component, err error) { c = &Translation{Key: k} } } else { - return nil, errors.New("unknown object, could not find any known key") + c = &Text{} } if o.Has(extra) {