plot

package
v0.0.0-...-1279de1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RoadHeight is a rough Y position of the height of the road where a player can be safely teleported.
	RoadHeight = 24
)

Variables

This section is empty.

Functions

func Within

func Within(pos, min, max cube.Pos) bool

Within checks if a cube.Pos is within the minimum and maximum cube.Pos passed.

Types

type DB

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

DB handles access to the plots leveldb database. It provides abstraction over the database layer so that plots may be directly read from it.

func OpenDB

func OpenDB(dir string, settings Settings) (*DB, error)

OpenDB opens the directory passed as a leveldb database for plots. If the directory does not yet exist, it is created. If successful, a new DB is returned which may be used to read and write plots.

func (*DB) Close

func (db *DB) Close() error

Close closes the underlying leveldb database.

func (*DB) PlayerPlots

func (db *DB) PlayerPlots(p *player.Player) ([]Position, error)

PlayerPlots attempts to read a list of Positions from the DB for the player.Player passed.

func (*DB) Plot

func (db *DB) Plot(pos Position) (*Plot, error)

Plot attempts to read a Plot from the DB at the Position passed.

func (*DB) RemovePlot

func (db *DB) RemovePlot(pos Position) error

RemovePlot attempts to remove a Plot at a specific Position in the DB.

func (*DB) StorePlayerPlots

func (db *DB) StorePlayerPlots(p *player.Player, positions []Position) error

StorePlayerPlots attempts to store the Positions of the plots it owns into the DB.

func (*DB) StorePlot

func (db *DB) StorePlot(pos Position, p *Plot) error

StorePlot attempts to store a Plot at a specific Position in the DB.

type Generator

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

Generator implements a generator for a plot world. The settings of the generator are configurable, allowing for different results depending on the fields set.

func NewGenerator

func NewGenerator(s Settings) *Generator

NewGenerator returns a new plot Generator with the Settings passed.

func (*Generator) GenerateChunk

func (g *Generator) GenerateChunk(pos world.ChunkPos, chunk *chunk.Chunk)

GenerateChunk generates a chunk for a plot world.

type PlayerHandler

type PlayerHandler struct {
	player.NopHandler
	// contains filtered or unexported fields
}

PlayerHandler handles events of a player.Player. It handles things such as preventing players from placing in plots that they do not own.

func LookupHandler

func LookupHandler(p *player.Player) (*PlayerHandler, bool)

LookupHandler looks up the PlayerHandler of a player.Player passed.

func NewPlayerHandler

func NewPlayerHandler(p *player.Player, settings Settings, db *DB) *PlayerHandler

NewPlayerHandler creates a new PlayerHandler for the player.Player passed. The Settings and DB are used to track which plots the player.Player can build in.

func (*PlayerHandler) DB

func (h *PlayerHandler) DB() *DB

DB returns the plot DB of the PlayerHandler.

func (*PlayerHandler) HandleBlockBreak

func (h *PlayerHandler) HandleBlockBreak(ctx *event.Context, pos cube.Pos, _ *[]item.Stack)

HandleBlockBreak prevents block breaking outside of the player's plots.

func (*PlayerHandler) HandleBlockPlace

func (h *PlayerHandler) HandleBlockPlace(ctx *event.Context, pos cube.Pos, _ world.Block)

HandleBlockPlace prevents block placing outside of the player's plots.

func (*PlayerHandler) HandleItemUseOnBlock

func (h *PlayerHandler) HandleItemUseOnBlock(ctx *event.Context, pos cube.Pos, face cube.Face, _ mgl64.Vec3)

HandleItemUseOnBlock prevents using items on blocks outside of the player's plots.

func (*PlayerHandler) HandleMove

func (h *PlayerHandler) HandleMove(_ *event.Context, pos mgl64.Vec3, _, _ float64)

HandleMove shows information on the plot that the player enters.

func (*PlayerHandler) HandleQuit

func (h *PlayerHandler) HandleQuit()

HandleQuit removes the PlayerHandler from the Handlers map.

func (*PlayerHandler) PlotPositions

func (h *PlayerHandler) PlotPositions() []Position

PlotPositions returns positions of all plots that the PlayerHandler holds.

func (*PlayerHandler) Plots

func (h *PlayerHandler) Plots() []*Plot

Plots returns a list of all Plots that the PlayerHandler owns.

func (*PlayerHandler) SetPlotPositions

func (h *PlayerHandler) SetPlotPositions(positions []Position) error

SetPlotPositions sets the positions of all plots that the PlayerHandler holds.

func (*PlayerHandler) Settings

func (h *PlayerHandler) Settings() Settings

Settings returns the Settings of the PlayerHandler.

type Plot

type Plot struct {
	// Owner is the UUID of the owner of the plot. The owner has administrative permissions over the plot such
	// as being able to add helpers to the plot.
	Owner uuid.UUID
	// OwnerName is the name last recorded for the owner.
	OwnerName string
	// Helpers is a list of helpers added to the plot. These helpers may edit the plot, but are unable to, for
	// example, add other helpers.
	Helpers []uuid.UUID
	// Colour is the colour of the plot. The border of the plot will have this colour and the colour will be
	// used to refer to different chunks owned by the player.
	Colour string

	MergedDirections []cube.Direction
}

Plot represents a plot in the world. Each plot has an owner

func (*Plot) ColourToFormat

func (p *Plot) ColourToFormat() string

ColourToFormat converts the colour of the plot to a text.FormatFunc and returns it.

func (*Plot) ColourToString

func (p *Plot) ColourToString() string

ColourToString converts the colour of the plot to a readable representation.

func (*Plot) Info

func (p *Plot) Info() string

Info returns a string of info about the Plot.

func (*Plot) Owned

func (p *Plot) Owned() bool

Owned checks if the Plot is currently owned.

type Position

type Position [2]int

Position represents the position of a plot. These positions are similar to chunk positions, in that they do not represent absolute coordinates, but, instead, a coordinate based on the size of plots.

func PosFromBlockPos

func PosFromBlockPos(pos cube.Pos, settings Settings) Position

PosFromBlockPos returns a Position that reflects the position of the plot present at that position.

func (Position) Absolute

func (pos Position) Absolute(settings Settings) cube.Pos

Absolute returns an absolute cube.Pos that holds the corner of the plot.

func (Position) Add

func (pos Position) Add(p Position) Position

Add adds a Position to the current Position and returns a new resulting Position.

func (Position) Bounds

func (pos Position) Bounds(settings Settings) (min, max cube.Pos)

Bounds returns the bounds of the Plot present at this position. Blocks may only be edited within these block positions.

func (Position) Hash

func (pos Position) Hash() []byte

Hash creates a hash of the position and returns it. This hash is unique per Position and may be used to do lookups in databases.

func (Position) Reset

func (pos Position) Reset(w *world.World, settings Settings)

Reset resets the Plot at the Position in the world.World passed. The Settings are used to determine the bounds of the plot.

func (Position) TeleportPosition

func (pos Position) TeleportPosition(settings Settings) mgl64.Vec3

TeleportPosition returns an absolute mgl64.Vec3 that can be used for teleporting the player.

type Settings

type Settings struct {
	// FloorBlock is the block on the floor of each plot. The floor may be changed later, but plots will have
	// this floor by default.
	FloorBlock world.Block
	// BoundaryBlock is the block used to surround plots with. These blocks cannot be changed by an individual
	// player.
	BoundaryBlock world.Block
	// RoadBlock is the outer block of the pattern on the road. These blocks cannot be changed by any player.
	RoadBlock world.Block
	// PlotWidth is the width in blocks that each plot generated will be.
	PlotWidth int
	// MaximumPlots is the maximum amount of plots that a player is allowed to claim. Trying to claim more
	// than this will result in an error.
	MaximumPlots int
}

Settings holds the settings for a plot Generator. These settings may be changed in order to change the appearance of the plots generated.

type WorldHandler

type WorldHandler struct {
	world.NopHandler
	// contains filtered or unexported fields
}

WorldHandler handles events of the world.World, making sure liquids don't spread out of plots.

func NewWorldHandler

func NewWorldHandler(w *world.World, settings Settings) *WorldHandler

NewWorldHandler returns a new WorldHandler instance using the world.World and Settings passed.

func (*WorldHandler) HandleLiquidFlow

func (w *WorldHandler) HandleLiquidFlow(ctx *event.Context, _, into cube.Pos, _, _ world.Block)

HandleLiquidFlow prevents liquid from flowing out of a plot.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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