如何在新版mc发送命令?
#238
-
如图所示 以下是我的代码,我试图登录服务器,但这不起作用 package main
import (
"github.com/Tnze/go-mc/bot"
"github.com/Tnze/go-mc/bot/basic"
"github.com/Tnze/go-mc/bot/msg"
"github.com/Tnze/go-mc/bot/playerlist"
"github.com/Tnze/go-mc/chat"
"log"
)
var client *bot.Client
var player *basic.Player
var chatHandler *msg.Manager
var playerList *playerlist.PlayerList
func main() {
name := "Bot002"
client = bot.NewClient()
client.Auth.Name = name
player = basic.NewPlayer(client, basic.DefaultSettings, basic.EventsListener{Death: onDeath, GameStart: onGamestart})
playerList = playerlist.New(client)
chatHandler = msg.New(client, player, playerList, msg.EventsHandler{
SystemChat: onSystemMsg,
PlayerChatMessage: onPlayerMsg,
DisguisedChat: onDisguisedMsg,
})
//chatHandler = msg.New(client, player, playerList, msg.EventsHandler{})
err := client.JoinServer("localhost:25565")
if err != nil {
log.Fatal(err)
}
log.Println("Login success")
for {
if err = client.HandleGame(); err != nil {
log.Fatal(err)
}
}
}
func onSystemMsg(msg chat.Message, overlay bool) error {
log.Printf("System: %v", msg)
return nil
}
func onPlayerMsg(msg chat.Message, validated bool) error {
log.Printf("Player: %s", msg)
return nil
}
func onDisguisedMsg(msg chat.Message) error {
log.Printf("Disguised: %v", msg)
return nil
}
func onGamestart() error {
if err := chatHandler.SendMessage("/register Password01 Password01"); err != nil {
return err
}
if err := chatHandler.SendMessage("/login Password01"); err != nil {
return err
}
return nil
}
func onDeath() error {
err := player.Respawn()
return err
} |
Beta Was this translation helpful? Give feedback.
Answered by
cxzlw
Apr 15, 2023
Replies: 3 comments 9 replies
-
应该是要发送这个包,看看要不要添加到bot/msg里去。 |
Beta Was this translation helpful? Give feedback.
8 replies
-
新版指令跟訊息的包分開來了 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
空数组工作了,最后工作的代码是这样的