move SystemChat event from bot/basic to bot/msg

This commit is contained in:
Tnze
2023-01-01 22:12:03 +08:00
parent 88356fd576
commit e12b2f368d
6 changed files with 42 additions and 30 deletions

View File

@ -9,7 +9,6 @@ import (
type EventsListener struct {
GameStart func() error
SystemMsg func(c chat.Message, overlay bool) error
Disconnect func(reason chat.Message) error
HealthChange func(health float32) error
Death func() error
@ -21,9 +20,6 @@ func (e EventsListener) attach(p *Player) {
if e.GameStart != nil {
attachJoinGameHandler(p.c, e.GameStart)
}
if e.SystemMsg != nil {
attachSystemMsg(p.c, e.SystemMsg)
}
if e.Disconnect != nil {
attachDisconnect(p.c, e.Disconnect)
}
@ -41,20 +37,6 @@ func attachJoinGameHandler(c *bot.Client, handler func() error) {
})
}
func attachSystemMsg(c *bot.Client, handler func(c chat.Message, overlay bool) error) {
c.Events.AddListener(bot.PacketHandler{
Priority: 64, ID: packetid.ClientboundSystemChat,
F: func(p pk.Packet) error {
var msg chat.Message
var pos pk.Boolean
if err := p.Scan(&msg, &pos); err != nil {
return Error{err}
}
return handler(msg, bool(pos))
},
})
}
func attachDisconnect(c *bot.Client, handler func(reason chat.Message) error) {
c.Events.AddListener(bot.PacketHandler{
Priority: 64, ID: packetid.ClientboundDisconnect,