Skip to content

Commit

Permalink
Skip when passed nil as component
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed May 3, 2022
1 parent 47d30d7 commit a12d7f1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
all: fmt vet mod lint

# Run tests
test: fmt vet
go test ./...

# Run go fmt against code
fmt:
go fmt ./...

# Run go fmt against code
mod:
go mod tidy && go mod verify

# Run go vet against code
vet:
go vet ./...

# Run golangci-lint against code
lint:
golangci-lint run
3 changes: 2 additions & 1 deletion minecraft/color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package color
import (
"errors"
"fmt"
"github.com/lucasb-eyer/go-colorful"
"image/color"
"math"
"strconv"
"strings"

"github.com/lucasb-eyer/go-colorful"
)

// Color is the interface for a Minecraft text color,
Expand Down
8 changes: 5 additions & 3 deletions minecraft/component/codec/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"strings"

"github.com/francoispqt/gojay"
"github.com/google/uuid"

col "go.minekube.com/common/minecraft/color"
. "go.minekube.com/common/minecraft/component"
"go.minekube.com/common/minecraft/key"
"go.minekube.com/common/minecraft/nbt"
"io"
"strings"
)

// Codec can marshal and unmarshal to/from components to/from a different format.
Expand Down Expand Up @@ -540,7 +542,7 @@ func (j *Json) decodeColor(i interface{}) (c col.Color, dec *Decoration, reset b
return
}
} else {
c, _ = col.Names[s]
c = col.Names[s]
}
_, ok = Decorations[Decoration(s)]
if ok {
Expand Down
16 changes: 11 additions & 5 deletions minecraft/component/codec/legacy/legacy.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package legacy

import (
. "go.minekube.com/common/minecraft/color"
. "go.minekube.com/common/minecraft/component"
"go.minekube.com/common/minecraft/component/codec"
"io"
"regexp"
"strings"
"unicode/utf8"

. "go.minekube.com/common/minecraft/color"
. "go.minekube.com/common/minecraft/component"
"go.minekube.com/common/minecraft/component/codec"
)

type Legacy struct {
Expand Down Expand Up @@ -103,6 +104,9 @@ func newStringBuilder(l *Legacy, char rune) *stringBuilder {
}

func (b *stringBuilder) append(c Component, s *style) {
if c == nil {
return
}
s.apply(c)

if t, ok := c.(*Text); ok && len(t.Content) != 0 {
Expand All @@ -115,6 +119,9 @@ func (b *stringBuilder) append(c Component, s *style) {
}
childrenStyle := s.copy()
for _, child := range c.Children() {
if child == nil {
continue
}
b.append(child, childrenStyle)
childrenStyle.set(s)
}
Expand Down Expand Up @@ -235,7 +242,6 @@ func (s *style) applyFormat() {
s.b.style.decorations[d] = struct{}{}
s.b.appendFormat(d)
}
return
}

func (s *style) set(s2 *style) {
Expand Down Expand Up @@ -417,7 +423,7 @@ func decodeFormat(legacy rune) (t FormatCodeType, f Format, ok bool) {
}

func determineFormatType(char rune) (FormatCodeType, bool) {
if strings.IndexRune(Chars, char) != -1 {
if strings.ContainsRune(Chars, char) {
return MojangLegacy, true
}
return 0, false
Expand Down

0 comments on commit a12d7f1

Please sign in to comment.