Skip to content

ByteSizedMarius/go-minecraft-wrapper

 
 

Repository files navigation

Why is this fork a thing?

  • Starting the server in 1.18 works (Mojang added a random message in 1.18 that basically just say "watch out, servers starting now" which the original repo can't yet handle.)
  • Auto-Stop Server (Allows the wrapper to automatically stop the server, if the server is empty for a given duration)
  • Whitelist Stuff (print current whitelist, add to- and remove from whitelist)
  • Playerlist ( List() ) will now not only return a list of currently connected player, but also their position (updated twice a minute)
  • I added lots of missing death-messages (haven't gotten around to testing on this though)

Thanks to wlwanpan for the heavy lifting, which allowed me to add the stuff I personally needed within a couple of hours. (original readme starts here)

minecraft-wrapper

Minecraft Gopher

What is minecraft-wrapper?

Wrapper is a Go package that wraps a Minecraft Server (JE) and interacts with it by pushing in commands and reading the server logs. This package is meant to provide nicer APIs for your Go program to manage your minecraft server.

Installation

go get github.com/ByteSizedMarius/go-minecraft-wrapper

Usage

  • Starting the server and listening to game events:
wpr := wrapper.NewDefaultWrapper("server.jar", 1024, 1024)
wpr.Start()
defer wpr.Stop()

// Listening to game events...
for {
  select {
  case ev := <-wpr.GameEvents():
    log.Println(ev.String())
  }
}
  • Broadcast a "Hello" message once the server is loaded:
wpr := wrapper.NewDefaultWrapper("server.jar", 1024, 1024)
wpr.Start()
defer wpr.Stop()

<-wpr.Loaded()
wpr.Say("Hello")
  • Retrieving a player position from the /data get command:
out, err := wpr.DataGet("entity", PLAYER_NAME|PLAYER_UUID)
if err != nil {
	...
}
fmt.Println(out.Pos) // [POS_X, POS_Y, POS_Z]
  • Save the game and Tell a game admin "admin-player", when the server is overloading.
wpr := wrapper.NewDefaultWrapper("server.jar", 1024, 1024)
wpr.Start()
defer wpr.Stop()
<-wpr.Loaded()

for {
  select {
  case ev := <-wpr.GameEvents():
    if ev.String() == events.ServerOverloaded {
      if err := wpr.SaveAll(true); err != nil {
        ...
      }
      broadcastMsg := fmt.Sprintf("Server is overloaded and lagging by %sms", ev.Data["lag_time"])
      err := wpr.Tell("admin-player", broadcastMsg)
      ...
    }
  }
}

For more example, go to the examples dir from this repo (more will be added soon).

Note: This package is developed and tested on Minecraft 1.16, though most functionalities (Start, Stop, Seed, ...) works across all versions. Commands like /data get was introduced in version 1.13 and might not work for earlier versions. ⚠️

Overview

Minecraft Wrapper Overview

If you are interested, you can visit this Medium article to learn some of the basic inner working of the wrapper.

Commands 🚧

The following apis/commands are from the official minecraft gamepedia list of commands unless otherwise specified.

Note: this list might be incomplete...

GameEvents 🚧

List of game events and their respective data...

Minecraft resources

Help and contributions

Feel free to drop a PR, file an issue or proposal of changes you want to have.

About

A Go package for your Minecraft Server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%