From 4878c6cc7be25dee57c55bcbb5ca884ffdb9a6ab Mon Sep 17 00:00:00 2001 From: adman Date: Tue, 28 Apr 2026 22:25:36 +0200 Subject: [PATCH] fix logger not being and other thing maybe --- proto/connection.go | 1 + text/text.go | 7 ++----- text/text_test.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/proto/connection.go b/proto/connection.go index e1c3ef9..3a6fc70 100644 --- a/proto/connection.go +++ b/proto/connection.go @@ -279,5 +279,6 @@ func NewConn() (ret *Conn) { panic(err) } ret.Loop = event.NewLoop() + ret.Log = slog.Default() return } diff --git a/text/text.go b/text/text.go index 17bf036..33d82ec 100644 --- a/text/text.go +++ b/text/text.go @@ -157,10 +157,6 @@ func (c *Component) UnmarshalJSON(data []byte) error { // ToNBT converts the component to a format suitable for the nbt package. func (c *Component) ToNBT() any { - if c.isSimpleText() { - return c.Text - } - m := make(map[string]any) if c.Bold != nil { m["bold"] = boolToByte(*c.Bold) @@ -494,7 +490,8 @@ func Pretty(s string) *Component { // PrettyF returns a Component from a formatted string. func PrettyF(format string, args ...any) *Component { - return Pretty(fmt.Sprintf(format, args...)) + s := fmt.Sprintf(format, args...) + return Pretty(s) } var colorToCode = map[string]byte{ diff --git a/text/text_test.go b/text/text_test.go index bd64a84..35ad340 100644 --- a/text/text_test.go +++ b/text/text_test.go @@ -4,6 +4,9 @@ import ( "encoding/json" "reflect" "testing" + + "github.com/admin-else/strom/nbt" + "github.com/google/go-cmp/cmp" ) func TestComponent_JSON(t *testing.T) { @@ -216,3 +219,31 @@ func TestComponent_String(t *testing.T) { }) } } + +func TestPrettyToNbt(t *testing.T) { + tests := []struct { + name string + f string + want nbt.Anon + }{ + { + name: "real data", + f: `§dno gooning`, + want: nbt.Anon{Value: map[string]interface{}{"extra": []interface{}{map[string]interface{}{"color": "light_purple", "text": "no gooning"}}}}, + }, + { + name: "reset thing", + f: "§3Any§bProtect§3 » §rffff", + want: nbt.Anon{Value: map[string]interface{}{"extra": []interface{}{map[string]interface{}{"color": "dark_aqua", "text": "Any"}, map[string]interface{}{"color": "aqua", "text": "Protect"}, map[string]interface{}{"color": "dark_aqua", "text": " » "}, map[string]interface{}{"text": "ffff"}}, "text": ""}}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + a := Pretty(tt.f).AsNBT() + b := tt.want + if !cmp.Equal(a, b) { + t.Errorf("PrettyToNbt() = %v, want %v", a, b) + } + }) + } +}