go_minecraft

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

README

Go Minecraft

Go Reference GitHub tag (latest SemVer) Go Report Card

A Go Client for the Minecraft RCON protocol

Installation

Install with the go get command

go get github.com/brittonhayes/go-minecraft

Documentation

View the full docs on pkg.go.dev

Usage

Using the package is as easy as create client, pick the endpoint, and run the method. This applies across every data type, so it is consistent across the board. Here's a simple example of how to give a player an item in-game.

func main() {
    // Initialize client
    c := minecraft.NewClient("localhost:1234", "password")
    
    // Setup context for request
    ctx := context.Background()
    
    // Give the player items
    res, err := c.Give(ctx, "johndoe", items.Bedrock, 5)
    if err != nil {
        panic(err)
    }
    
    // Print out the response
    fmt.Println(res)
}

Examples

For example uses of the package, check out the example directory

Development

If you'd like to contribute to go-minecraft, make sure you have mage installed: https://magefile.org

# Download dependencies and run tests
mage download
mage test

Documentation

Overview

package go_minecraft is an RCON client for minecraft built in Go

Index

Constants

View Source
const (
	WeatherRain        Weather    = "rain"
	WeatherThunder     Weather    = "thunder"
	WeatherSnow        Weather    = "snow"
	ModeSurvival       Mode       = "survival"
	ModeCreative       Mode       = "creative"
	DifficultyEasy     Difficulty = "easy"
	DifficultyMedium   Difficulty = "normal"
	DifficultyHard     Difficulty = "hard"
	DifficultyPeaceful Difficulty = "peaceful"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*PlayerService
	*WorldService
}

func NewClient

func NewClient(host string, password string) *Client

NewClient creates a new instance of the Minecraft client

type Difficulty

type Difficulty string

type Mode

type Mode string

type Player

type Player interface {
	Give(ctx context.Context, name string, item items.Item, quantity int) (string, error)
	List(ctx context.Context) string
	Meetup(ctx context.Context, player1, player2 string) string
	Teleport(ctx context.Context, player, x, y, z string) string
	Kill(ctx context.Context, player string) string
}

Player is the primary interface for the all player-related commands

type PlayerService

type PlayerService struct {
	// contains filtered or unexported fields
}

func NewPlayerService

func NewPlayerService(addr string, password string) *PlayerService

NewPlayerService creates a new instance of the PlayerService

func (*PlayerService) Give

func (p *PlayerService) Give(ctx context.Context, name string, item items.Item, quantity int) (string, error)

Give adds the specified quantity of items into a player's inventory

func (*PlayerService) Kill

func (p *PlayerService) Kill(ctx context.Context, player string) string

Kill kills the player with the provided name

func (*PlayerService) List added in v0.1.0

func (p *PlayerService) List(ctx context.Context) string

func (*PlayerService) Meetup

func (p *PlayerService) Meetup(ctx context.Context, player1, player2 string) string

Meetup joins player1 onto player2's position in the world

func (*PlayerService) Teleport

func (p *PlayerService) Teleport(ctx context.Context, player, x, y, z string) string

Teleport moves a player to the 3D coordinates provided

type Weather

type Weather string

type World

type World interface {
	Weather(ctx context.Context, w Weather) string
	Time(ctx context.Context, time int) string
	Seed(ctx context.Context) string
	Mode(ctx context.Context, m Mode) string
	Difficulty(ctx context.Context, d Difficulty) string
}

World is the primary interface for the all world-related commands

type WorldService

type WorldService struct {
	// contains filtered or unexported fields
}

func NewWorldService

func NewWorldService(addr string, password string) *WorldService

func (*WorldService) Difficulty

func (ws *WorldService) Difficulty(ctx context.Context, d Difficulty) string

func (*WorldService) Mode

func (ws *WorldService) Mode(ctx context.Context, m Mode) string

func (*WorldService) Seed

func (ws *WorldService) Seed(ctx context.Context) string

Seed returns the world seed

func (*WorldService) Time

func (ws *WorldService) Time(ctx context.Context, time int) string

Time sets the time in the world

func (*WorldService) Weather

func (ws *WorldService) Weather(ctx context.Context, w Weather) string

Weather sets the weather in the world

Directories

Path Synopsis
example
internal
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL