Documentation ¶
Index ¶
- Constants
- Variables
- type Abilities
- type Attribute
- type BanListType
- type Brain
- type Console
- type DataGetOutput
- type ExperienceType
- type GameDifficulty
- type GameMode
- type Inventory
- type JavaExec
- type LogParser
- type Player
- type Pos
- type RecipeBook
- type Wrapper
- func (w *Wrapper) AutoStop(after time.Duration)
- func (w *Wrapper) BanIP(ip, reason string) error
- func (w *Wrapper) BanList(t BanListType) ([]string, error)
- func (w *Wrapper) DataGet(t, id string) (*DataGetOutput, error)
- func (w *Wrapper) DeOp(player string) error
- func (w *Wrapper) DefaultGameMode(mode GameMode) error
- func (w *Wrapper) Difficulty(d GameDifficulty) error
- func (w *Wrapper) ExperienceAdd(target string, xp int32, xpType ExperienceType) error
- func (w *Wrapper) ExperienceQuery(target string, xpType ExperienceType) (int, error)
- func (w *Wrapper) ForceLoadRemoveAll() error
- func (w *Wrapper) GameEvents() <-chan events.GameEvent
- func (w *Wrapper) Give(target, item string, count int) error
- func (w *Wrapper) Kick(target, reason string) error
- func (w *Wrapper) Kill() error
- func (w *Wrapper) List() []Player
- func (w *Wrapper) Loaded() <-chan bool
- func (w *Wrapper) Reload() error
- func (w *Wrapper) SaveAll(flush bool) error
- func (w *Wrapper) SaveOff() error
- func (w *Wrapper) SaveOn() error
- func (w *Wrapper) Say(msg string) error
- func (w *Wrapper) Seed() (int, error)
- func (w *Wrapper) SetIdleTimeout(minutes uint32) error
- func (w *Wrapper) Start() error
- func (w *Wrapper) State() string
- func (w *Wrapper) Stop() error
- func (w *Wrapper) Tell(target, msg string) error
- func (w *Wrapper) Tick() int
- func (w *Wrapper) WhitelistAdd(player string) (events.GameEvent, error)
- func (w *Wrapper) WhitelistList() (events.GameEvent, error)
- func (w *Wrapper) WhitelistRemove(player string) (events.GameEvent, error)
Constants ¶
const ( // MarketOpenTick is the mc time at which a villagers begin their workday, // hence are open for item trading. MarketOpenTick int64 = 2000 // MarketCloseTick is the mc time at which villagers end their workday // and begin socializing, trading is not available at this point. MarketCloseTick int64 = 9000 // GameTickPerSecond is the minecraft game server tick runs at a fixed // rate of 20 ticks per second. GameTickPerSecond int = 20 // ClockSyncInterval is the interval where the wrapper clock will sync with the // game tick rate. The wrapper and game tick can be skewed when the game lags. ClockSyncInterval time.Duration = 30 * time.Second )
const ( WrapperOffline = "offline" WrapperOnline = "online" WrapperStarting = "starting" WrapperStopping = "stopping" WrapperSaving = "saving" )
Variables ¶
var ( // ErrWrapperResponseTimeout is returned when a command fails to receive // its respective event from the server logs within some timeframe. Hence // no output could be decoded for the command. ErrWrapperResponseTimeout = errors.New("response timeout") // ErrWrapperNotOnline is returned when a commad is called but the wrapper // is not 'online'. The minecraft server is not loaded and ready to process // any commands. ErrWrapperNotOnline = errors.New("not online") // ErrPlayerNotFound is returned when a targetted command failed to process // due to the player not being connected to the server. ErrPlayerNotFound = errors.New("player not found") // ErrUnknownItem is returned when an item operation is called with an // invalid item type or structure. ErrUnknownItem = errors.New("unknown item") )
Functions ¶
This section is empty.
Types ¶
type BanListType ¶
type BanListType string
const ( BanIPs BanListType = "ips" BanPlayers BanListType = "players" )
type DataGetOutput ¶
type DataGetOutput struct { Brain Brain HurtByTimestamp int SleepTimer int SpawnForced int Attributes []Attribute Invulnerable int FallFlying int PortalCooldown int AbsorptionAmount float64 Abilities Abilities FallDistance float64 RecipeBook RecipeBook DeathTime int XpSeed int XpTotal int UUID []interface{} // Technically []int, cc issue in decoder.go#Lexer.buildStr() PlayerGameType int SeenCredits int Motion []float64 Health float64 FoodSaturationLevel float64 Air int OnGround int Dimension string Rotation []float64 XpLevel int Score int Pos []float64 PreviousPlayerGameType int Fire int XpP float64 EnderItems []interface{} DataVersion int FoodLevel int FoodExhaustionLevel float64 HurtTime int // TODO: support native time.Time? SelectedItemSlot int Inventory Inventory FoodTickTimer int }
DataGetOutput represents the structured data logged from the '/data get entity' command. Some fields might not be of the right or precise type since the decoder will coerse any value to either a string, int or float64 for simplicity.
type ExperienceType ¶
type ExperienceType string
const ( Levels ExperienceType = "levels" Points ExperienceType = "points" )
type GameDifficulty ¶
type GameDifficulty string
const ( Easy GameDifficulty = "easy" Hard GameDifficulty = "hard" Normal GameDifficulty = "normal" Peaceful GameDifficulty = "peaceful" )
type JavaExec ¶
type JavaExec interface { Stdout() io.ReadCloser Stdin() io.WriteCloser Start() error Kill() error }
type LogParser ¶
LogParser is an interface func to decode any server log line to its respective event type. The returned events must be either: - Cmd: event holds data to be returned to a user command. - State: event affects the state of the wrapper. - Game: event related to in-game events, like a player died... - Nil: event that hold no value and usually ignored/
type RecipeBook ¶
type Wrapper ¶
type Wrapper struct { // Version is the minecraft server version being wrapped. // The Version is detected and set from the log line: // "Starting minecraft server version [X.X.X]"" Version string // contains filtered or unexported fields }
Wrapper is the minecraft-wrapper core struct, representing an instance of a minecraft server (JE). It is used to manage and interact with the java process by proxying its stdin and stdout via the Console interface.
func NewDefaultWrapper ¶
NewDefaultWrapper returns a new instance of the Wrapper. This is the main method to use for your wrapper but if you wish to read and parse your own log lines to events, see 'NewWrapper'. This
func NewWrapper ¶
func (*Wrapper) DataGet ¶
func (w *Wrapper) DataGet(t, id string) (*DataGetOutput, error)
DataGet returns the Go struct representation of an 'entity' or 'block' or 'storage'. The data is originally stored in a NBT format.
func (*Wrapper) DefaultGameMode ¶
DefaultGameMode sets the default game mode for new players joining.
func (*Wrapper) Difficulty ¶
func (w *Wrapper) Difficulty(d GameDifficulty) error
Difficulty changes the game difficulty level of the world.
func (*Wrapper) ExperienceAdd ¶
func (w *Wrapper) ExperienceAdd(target string, xp int32, xpType ExperienceType) error
ExperienceAdd adds a given amount of experience either: - levels or - points to the provided player.
func (*Wrapper) ExperienceQuery ¶
func (w *Wrapper) ExperienceQuery(target string, xpType ExperienceType) (int, error)
ExperienceQuery returns the amount of experience of the provided player. The 'target' arg should be a single target, multi-targets query might fail.
func (*Wrapper) ForceLoadRemoveAll ¶
ForceLoadRemoveAll removes the constant force loads on all chunks in the dimension.
func (*Wrapper) GameEvents ¶
GameEvents returns a receive-only channel of game related event. For example: - Player joined, left, died, was banned. - Game updates like game mode changes. - Player sends messages...
func (*Wrapper) Kick ¶
Kick kicks the provided player from the server. If a reason is provided, the message will display on the players screen when disconnected.
func (*Wrapper) Kill ¶
Kill the java process, use with caution since it will not trigger a save game. Kill manually perform some cleanup task and hard reset the state to 'offline'.
func (*Wrapper) SaveAll ¶
SaveAll marks all chunks and player data to be saved to the data storage device. When flush is true, the marked data are saved immediately.
func (*Wrapper) SaveOff ¶
SaveOff disables automatic saving by preventing the server from writing to the world files.
func (*Wrapper) SaveOn ¶
SaveOn enables automatic saving. The server is allowed to write to the world files.
func (*Wrapper) SetIdleTimeout ¶
SetIdleTimeout sets the default timeout in minutes after which idle players are kicked out of the server.
func (*Wrapper) Start ¶
Start will initialize the minecraft java process and start orchestrating the wrapper machine.
func (*Wrapper) State ¶
State returns the current state of the server, it can be one of: 'offline', 'online', 'starting' or 'stopping'.
func (*Wrapper) Tick ¶
Tick returns the current minecraft game tick, which runs at a fixed rate of 20 ticks per second, src: https://minecraft.gamepedia.com/Tick.