Fix Example
This commit is contained in:
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type EventsListener struct {
|
type EventsListener struct {
|
||||||
GameStart func() error
|
GameStart func() error
|
||||||
ChatMsg func(c *PlayerMessage, pos byte, uuid uuid.UUID) error
|
ChatMsg func(c *PlayerMessage) error
|
||||||
SystemMsg func(c chat.Message, pos byte) error
|
SystemMsg func(c chat.Message, pos byte) error
|
||||||
Disconnect func(reason chat.Message) error
|
Disconnect func(reason chat.Message) error
|
||||||
HealthChange func(health float32) error
|
HealthChange func(health float32) error
|
||||||
@ -106,7 +106,7 @@ func (e *EventsListener) onPlayerMsg(p pk.Packet) error {
|
|||||||
if err := message.SenderTeamName.UnmarshalJSON([]byte(senderDisplayName)); err != nil {
|
if err := message.SenderTeamName.UnmarshalJSON([]byte(senderDisplayName)); err != nil {
|
||||||
return Error{err}
|
return Error{err}
|
||||||
}
|
}
|
||||||
return e.ChatMsg(&message, byte(message.Position), message.Sender)
|
return e.ChatMsg(&message)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
//"github.com/mattn/go-colorable"
|
//"github.com/mattn/go-colorable"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/bot"
|
"github.com/Tnze/go-mc/bot"
|
||||||
@ -33,6 +32,7 @@ func main() {
|
|||||||
basic.EventsListener{
|
basic.EventsListener{
|
||||||
GameStart: onGameStart,
|
GameStart: onGameStart,
|
||||||
ChatMsg: onChatMsg,
|
ChatMsg: onChatMsg,
|
||||||
|
SystemMsg: onSystemMsg,
|
||||||
Disconnect: onDisconnect,
|
Disconnect: onDisconnect,
|
||||||
Death: onDeath,
|
Death: onDeath,
|
||||||
}.Attach(c)
|
}.Attach(c)
|
||||||
@ -107,8 +107,12 @@ func onSound(id int, category int, x, y, z float64, volume, pitch float32) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func onChatMsg(c chat.Message, pos byte, uuid uuid.UUID) error {
|
func onChatMsg(c *basic.PlayerMessage) error {
|
||||||
log.Println("Chat:", c)
|
log.Println("Chat:", c.SignedMessage.String())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func onSystemMsg(c chat.Message, pos byte) error {
|
||||||
|
log.Printf("System: %v, Location: %v", c.String(), pos)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
//"github.com/mattn/go-colorable"
|
//"github.com/mattn/go-colorable"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/bot"
|
"github.com/Tnze/go-mc/bot"
|
||||||
@ -36,6 +35,7 @@ func main() {
|
|||||||
basic.EventsListener{
|
basic.EventsListener{
|
||||||
GameStart: onGameStart,
|
GameStart: onGameStart,
|
||||||
ChatMsg: onChatMsg,
|
ChatMsg: onChatMsg,
|
||||||
|
SystemMsg: onSystemMsg,
|
||||||
Disconnect: onDisconnect,
|
Disconnect: onDisconnect,
|
||||||
HealthChange: nil,
|
HealthChange: nil,
|
||||||
Death: onDeath,
|
Death: onDeath,
|
||||||
@ -95,8 +95,12 @@ func onGameStart() error {
|
|||||||
return nil //if err isn't nil, HandleGame() will return it.
|
return nil //if err isn't nil, HandleGame() will return it.
|
||||||
}
|
}
|
||||||
|
|
||||||
func onChatMsg(c chat.Message, _ byte, _ uuid.UUID) error {
|
func onChatMsg(c *basic.PlayerMessage) error {
|
||||||
log.Println("Chat:", c) // output chat message without any format code (like color or bold)
|
log.Println("Chat:", c.SignedMessage.String())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func onSystemMsg(c chat.Message, pos byte) error {
|
||||||
|
log.Printf("System: %v, Location: %v", c.String(), pos)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user