This repository was archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Join a server
Tnze edited this page Jan 18, 2019
·
4 revisions
package main
import (
// mb "github.com/Tnze/gomcbot"
auth "github.com/Tnze/gomcbot/authenticate"
)
func main() {
//Login
resp, err := auth.Authenticate("email", "password")
if err != nil {
panic(err)
}
Auth := resp.ToAuth()
//Join server
game, err := Auth.JoinServer("localhost", 25565)
if err != nil {
panic(err)
}
//Handle game
events := game.GetEvents()
go game.HandleGame()
for e := range events {//Reciving events
switch e {
case mb.PlayerSpawnEvent:
fmt.Println("Player is spawn!")
}
}
}Previous code can join both online and offline mode server, but to joining a offline server, you don't need an account by following :
package main
import (
mb "github.com/Tnze/gomcbot"
)
func main() {
p := mb.Auth{
Name: "YourGameName",
UUID: "YourUUID",
}
game, err := p.JoinServer("localhost", 25565)
if err != nil {
panic(err)
}
events := game.GetEvents()
go game.HandleGame()
for e := range events {
switch e {
case mb.PlayerSpawnEvent:
fmt.Println("Player is spawn!")
}
}
}