From 81f61933dc339efa864c1386fc4bf6c3f1df5ef0 Mon Sep 17 00:00:00 2001 From: oq Date: Sat, 19 Oct 2024 23:28:44 +0300 Subject: [PATCH] /gc command + new text api methods --- commands/commands.go | 2 +- commands/gc.go | 18 ++++++++ protocol/net/packet/play/chunkData.go | 2 +- protocol/text/builder.go | 59 +++++++++++++++++++++++++++ protocol/text/color.go | 36 ++++++++++++++++ protocol/text/text.go | 12 +++--- 6 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 commands/gc.go create mode 100644 protocol/text/builder.go create mode 100644 protocol/text/color.go diff --git a/commands/commands.go b/commands/commands.go index 07fcd6a..40a62c0 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -3,5 +3,5 @@ package commands import "github.com/zeppelinmc/zeppelin/server/command" var Commands = []command.Command{ - mem, debug, tick, timecmd, + mem, debug, tick, timecmd, gc, } diff --git a/commands/gc.go b/commands/gc.go new file mode 100644 index 0000000..280e40c --- /dev/null +++ b/commands/gc.go @@ -0,0 +1,18 @@ +package commands + +import ( + "runtime" + + "github.com/zeppelinmc/zeppelin/protocol/text" + "github.com/zeppelinmc/zeppelin/server/command" +) + +var gc = command.Command{ + Node: command.NewLiteral("gc"), + Namespace: "zeppelin", + Callback: func(ccc command.CommandCallContext) { + runtime.GC() + + ccc.Executor.SystemMessage(text.Text("Done.").WithColor(text.BrightGreen)) + }, +} diff --git a/protocol/net/packet/play/chunkData.go b/protocol/net/packet/play/chunkData.go index 5892348..d1034d8 100644 --- a/protocol/net/packet/play/chunkData.go +++ b/protocol/net/packet/play/chunkData.go @@ -16,7 +16,7 @@ type BlockEntity struct { const PacketIdChunkDataUpdateLight = 0x27 type Heightmaps struct { - MOTION_BLOCKING, WORLD_SURFACE [37]int64 + MOTION_BLOCKING, WORLD_SURFACE []int64 } type ChunkDataUpdateLight struct { diff --git a/protocol/text/builder.go b/protocol/text/builder.go new file mode 100644 index 0000000..79d813d --- /dev/null +++ b/protocol/text/builder.go @@ -0,0 +1,59 @@ +package text + +func New() TextComponent { + return TextComponent{} +} + +func (t TextComponent) WithColor(c string) TextComponent { + t.Color = c + return t +} + +func (t TextComponent) WithText(c string) TextComponent { + t.Text = c + return t +} + +func (t TextComponent) WithItalic() TextComponent { + t.Italic = !t.Italic + return t +} + +func (t TextComponent) WithUnderline() TextComponent { + t.Underlined = !t.Underlined + return t +} + +func (t TextComponent) WithStrikethrough() TextComponent { + t.Strikethrough = !t.Strikethrough + return t +} + +func (t TextComponent) WithObfuscation() TextComponent { + t.Obfuscated = !t.Obfuscated + return t +} + +func Color(c string) TextComponent { + return TextComponent{Color: c} +} + +func Text(c string) TextComponent { + return TextComponent{Text: c} +} + +func Italic() TextComponent { + return TextComponent{Italic: true} +} + +func Underline() TextComponent { + return TextComponent{Underlined: true} +} + +func Strikethrough() TextComponent { + return TextComponent{Strikethrough: true} +} + +func Obfuscation() TextComponent { + return TextComponent{Obfuscated: true} +} diff --git a/protocol/text/color.go b/protocol/text/color.go new file mode 100644 index 0000000..abd0e0a --- /dev/null +++ b/protocol/text/color.go @@ -0,0 +1,36 @@ +package text + +import ( + "fmt" + "image/color" +) + +// colors +const ( + Black = "black" + DarkBlue = "dark_blue" + DarkGreen = "dark_green" + DarkCyan = "dark_aqua" + DarkRed = "dark_red" + Purple = "dark_purple" + Gold = "gold" + Gray = "gray" + DarkGray = "dark_gray" + Blue = "blue" + BrightGreen = "green" + Cyan = "aqua" + Red = "red" + Pink = "light_purple" + Yellow = "yellow" + White = "white" +) + +func RGB(r, g, b uint8) string { + return fmt.Sprintf("#%02X%02X%02X", r, g, b) +} + +func CustomColor(c color.Color) string { + r, g, b, _ := c.RGBA() + + return RGB(uint8(r>>8), uint8(g>>8), uint8(b>>8)) +} diff --git a/protocol/text/text.go b/protocol/text/text.go index 755d299..e57a52a 100644 --- a/protocol/text/text.go +++ b/protocol/text/text.go @@ -4,12 +4,12 @@ package text import "fmt" const ( - Text = "text" - Translatable = "translatable" - Keybind = "keybind" - Score = "score" - Selector = "selector" - NBT = "nbt" + TypeText = "text" + TypeTranslatable = "translatable" + TypeKeybind = "keybind" + TypeScore = "score" + TypeSelector = "selector" + TypeNBT = "nbt" ) const (