Skip to content

Commit

Permalink
/gc command + new text api methods
Browse files Browse the repository at this point in the history
  • Loading branch information
oq-x committed Oct 19, 2024
1 parent 94674ca commit 81f6193
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 8 deletions.
2 changes: 1 addition & 1 deletion commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
18 changes: 18 additions & 0 deletions commands/gc.go
Original file line number Diff line number Diff line change
@@ -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))
},
}
2 changes: 1 addition & 1 deletion protocol/net/packet/play/chunkData.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
59 changes: 59 additions & 0 deletions protocol/text/builder.go
Original file line number Diff line number Diff line change
@@ -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}
}
36 changes: 36 additions & 0 deletions protocol/text/color.go
Original file line number Diff line number Diff line change
@@ -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))
}
12 changes: 6 additions & 6 deletions protocol/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 81f6193

Please sign in to comment.