Skip to content
7 changes: 4 additions & 3 deletions server/block/jukebox.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/internal/nbtconv"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/player/chat"
"github.com/df-mc/dragonfly/server/world"
"github.com/df-mc/dragonfly/server/world/sound"
"time"
Expand Down Expand Up @@ -66,8 +67,8 @@ func (j Jukebox) BreakInfo() BreakInfo {
// jukeboxUser represents an item.User that can use a jukebox.
type jukeboxUser interface {
item.User
// SendJukeboxPopup sends a jukebox popup to the item.User.
SendJukeboxPopup(a ...any)
// SendJukeboxPopupt sends a translatable jukebox popup to the item.User.
SendJukeboxPopupt(t chat.Translation, a ...any)
}

// Activate ...
Expand All @@ -88,7 +89,7 @@ func (j Jukebox) Activate(pos cube.Pos, _ cube.Face, tx *world.Tx, u item.User,

tx.PlaySound(pos.Vec3Centre(), sound.MusicDiscPlay{DiscType: m.DiscType})
if u, ok := u.(jukeboxUser); ok {
u.SendJukeboxPopup(fmt.Sprintf("Now playing: %v - %v", m.DiscType.Author(), m.DiscType.DisplayName()))
u.SendJukeboxPopupt(chat.MessageNowPlaying, fmt.Sprintf("%v - %v", m.DiscType.Author(), m.DiscType.DisplayName()))
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/player/chat/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var MessageBedIsOccupied = Translate(str("%tile.bed.occupied"), 0, `This bed is
var MessageSleeping = Translate(str("%chat.type.sleeping"), 2, `%v is sleeping in a bed. To skip to dawn, %v more users need to sleep in beds at the same time.`)
var MessageBedNotValid = Translate(str("%tile.bed.notValid"), 0, `Your home bed was missing or obstructed`)

var MessageNowPlaying = Translate(str("%record.nowPlaying"), 1, `Now playing: %v`)

type str string

// Resolve returns the translation identifier as a string.
Expand Down
6 changes: 6 additions & 0 deletions server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ func (p *Player) SendJukeboxPopup(a ...any) {
p.session().SendJukeboxPopup(format(a))
}

// SendJukeboxPopupt sends a translatable jukebox popup to the player and parameterises it using the arguments passed.
// SendJukeboxPopupt panics if an incorrect amount of arguments is passed.
func (p *Player) SendJukeboxPopupt(t chat.Translation, a ...any) {
p.session().SendJukeboxTranslation(t, p.locale, a)
}

// SendToast sends a toast to the player. This toast is shown at the top of the screen, similar to achievements or pack
// loading.
func (p *Player) SendToast(title, message string) {
Expand Down
11 changes: 11 additions & 0 deletions server/session/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ func (s *Session) SendJukeboxPopup(message string) {
})
}

// SendJukeboxTranslation sends a jukebox popup localised for a specific language.Tag.
func (s *Session) SendJukeboxTranslation(t chat.Translation, l language.Tag, a []any) {
tr := t.F(a...)
s.writePacket(&packet.Text{
TextType: packet.TextTypeJukeboxPopup,
NeedsTranslation: true,
Message: tr.Resolve(l),
Parameters: tr.Params(l),
})
}

// SendToast ...
func (s *Session) SendToast(title, message string) {
s.writePacket(&packet.ToastRequest{
Expand Down