up3
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled

This commit is contained in:
2026-07-09 08:33:57 +08:00
commit 26ed99fda6
845 changed files with 75419 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
package bossbar
import (
"fmt"
"strings"
)
// BossBar represents a boss bar that may be sent to a player. It is shown as a purple bar with text above
// it. The health shown by the bar may be changed.
type BossBar struct {
text string
health float64
c Colour
}
// New creates a new boss bar with the text passed. The text is formatted according to the rules of
// fmt.Sprintln.
// By default, the boss bar will have a full health bar. To change this, use BossBar.WithHealthPercentage().
// The default colour of the BossBar is Purple. This can be changed using BossBar.WithColour.
func New(text ...any) BossBar {
return BossBar{text: format(text), health: 1, c: Purple()}
}
// Text returns the text of the boss bar: The text passed when creating the bar using New().
func (bar BossBar) Text() string {
return bar.text
}
// WithHealthPercentage sets the health percentage of the boss bar. The value passed must be between 0 and 1.
// If a value out of that range is passed, WithHealthPercentage panics.
// The new BossBar with the changed health percentage is returned.
func (bar BossBar) WithHealthPercentage(v float64) BossBar {
if v < 0 || v > 1 {
panic("boss bar: value out of range: health percentage must be between 0.0 and 1.0")
}
bar.health = v
return bar
}
// WithColour returns a copy of the BossBar with the Colour passed.
func (bar BossBar) WithColour(c Colour) BossBar {
bar.c = c
return bar
}
// HealthPercentage returns the health percentage of the boss bar. The number returned is a value between 0
// and 1, with 0 being an empty boss bar and 1 being a full one.
func (bar BossBar) HealthPercentage() float64 {
return bar.health
}
// Colour returns the colour of the BossBar.
func (bar BossBar) Colour() Colour {
return bar.c
}
// format is a utility function to format a list of values to have spaces between them, but no newline at the
// end, which is typically used for sending messages, popups and tips.
func format(a []any) string {
return strings.TrimSuffix(fmt.Sprintln(a...), "\n")
}
+50
View File
@@ -0,0 +1,50 @@
package bossbar
// Colour is the colour of a BossBar.
type Colour struct{ colour }
// Pink is the colour for a pink boss bar.
func Pink() Colour {
return Colour{colour(0)}
}
// Blue is the colour for a blue boss bar.
func Blue() Colour {
return Colour{colour(1)}
}
// Red is the colour for a red boss bar.
func Red() Colour {
return Colour{colour(2)}
}
// Green is the colour for a green boss bar.
func Green() Colour {
return Colour{colour(3)}
}
// Yellow is the colour for a yellow boss bar.
func Yellow() Colour {
return Colour{colour(4)}
}
// Purple is the colour for a purple boss bar.
func Purple() Colour {
return Colour{colour(5)}
}
// RebeccaPurple is the colour for a rebecca purple boss bar.
func RebeccaPurple() Colour {
return Colour{colour(6)}
}
// White is the colour for a white boss bar.
func White() Colour {
return Colour{colour(7)}
}
type colour uint8
func (c colour) Uint8() uint8 {
return uint8(c)
}