Categorygithub.com/ByteSizedMarius/go-minecraft-wrapper
modulepackage
0.0.0-20220204145510-d0f2f64e1aa0
Repository: https://github.com/bytesizedmarius/go-minecraft-wrapper.git
Documentation: pkg.go.dev

# README

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. :warning:

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 :construction:

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

Note: this list might be incomplete...

GameEvents :construction:

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.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

NewDefaultWrapper returns a new instance of the Wrapper.
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
ClockSyncInterval is the interval where the wrapper clock will sync with the game tick rate.
No description provided by the author
No description provided by the author
GameTickPerSecond is the minecraft game server tick runs at a fixed rate of 20 ticks per second.
No description provided by the author
No description provided by the author
MarketCloseTick is the mc time at which villagers end their workday and begin socializing, trading is not available at this point.
MarketOpenTick is the mc time at which a villagers begin their workday, hence are open for item trading.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrPlayerNotFound is returned when a targetted command failed to process due to the player not being connected to the server.
ErrUnknownItem is returned when an item operation is called with an invalid item type or structure.
ErrWrapperNotOnline is returned when a commad is called but the wrapper is not 'online'.
ErrWrapperResponseTimeout is returned when a command fails to receive its respective event from the server logs within some timeframe.

# Structs

No description provided by the author
DataGetOutput represents the structured data logged from the '/data get entity' command.
No description provided by the author
No description provided by the author
No description provided by the author
Wrapper is the minecraft-wrapper core struct, representing an instance of a minecraft server (JE).

# Interfaces

No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LogParser is an interface func to decode any server log line to its respective event type.