Documentation ¶
Overview ¶
Package peex This file was generated using the event generator. Do not edit.
Index ¶
- func ComponentFromSession[T Component](s *Session) (T, bool)
- type Adder
- type Component
- type ComponentProvider
- type Config
- type GenericProvider
- type Handler
- type Manager
- func (m *Manager) Accept(p *player.Player, components ...Component) (*Session, error)
- func (m *Manager) QueryAll(queryFunc any) int
- func (m *Manager) QueryID(id uuid.UUID, queryFunc any) (bool, error)
- func (m *Manager) SessionFromPlayer(p *player.Player) (*Session, bool)
- func (m *Manager) SessionFromUUID(id uuid.UUID) (*Session, bool)
- func (m *Manager) Sessions() []*Session
- type Option
- type ProviderWrapper
- type Query
- type Remover
- type Session
- func (s *Session) Component(c Component) (Component, bool)
- func (s *Session) HandleAttackEntity(ctx *event.Context, e world.Entity, force, height *float64, critical *bool)
- func (s *Session) HandleBlockBreak(ctx *event.Context, pos cube.Pos, drops *[]item.Stack, xp *int)
- func (s *Session) HandleBlockPick(ctx *event.Context, pos cube.Pos, b world.Block)
- func (s *Session) HandleBlockPlace(ctx *event.Context, pos cube.Pos, b world.Block)
- func (s *Session) HandleChangeWorld(before, after *world.World)
- func (s *Session) HandleChat(ctx *event.Context, message *string)
- func (s *Session) HandleCommandExecution(ctx *event.Context, command cmd.Command, args []string)
- func (s *Session) HandleDeath(src world.DamageSource, keepInv *bool)
- func (s *Session) HandleDiagnostics(d diagnostics.Diagnostics)
- func (s *Session) HandleExperienceGain(ctx *event.Context, amount *int)
- func (s *Session) HandleFireExtinguish(ctx *event.Context, pos cube.Pos)
- func (s *Session) HandleFoodLoss(ctx *event.Context, from int, to *int)
- func (s *Session) HandleHeal(ctx *event.Context, health *float64, src world.HealingSource)
- func (s *Session) HandleHurt(ctx *event.Context, damage *float64, attackImmunity *time.Duration, ...)
- func (s *Session) HandleItemConsume(ctx *event.Context, item item.Stack)
- func (s *Session) HandleItemDamage(ctx *event.Context, i item.Stack, damage int)
- func (s *Session) HandleItemDrop(ctx *event.Context, e world.Entity)
- func (s *Session) HandleItemPickup(ctx *event.Context, i *item.Stack)
- func (s *Session) HandleItemUse(ctx *event.Context)
- func (s *Session) HandleItemUseOnBlock(ctx *event.Context, pos cube.Pos, face cube.Face, clickPos mgl64.Vec3)
- func (s *Session) HandleItemUseOnEntity(ctx *event.Context, e world.Entity)
- func (s *Session) HandleJump()
- func (s *Session) HandleLecternPageTurn(ctx *event.Context, pos cube.Pos, oldPage int, newPage *int)
- func (s *Session) HandleMove(ctx *event.Context, newPos mgl64.Vec3, newYaw, newPitch float64)
- func (s *Session) HandlePunchAir(ctx *event.Context)
- func (s *Session) HandleQuit()
- func (s *Session) HandleRespawn(pos *mgl64.Vec3, w **world.World)
- func (s *Session) HandleSignEdit(ctx *event.Context, pos cube.Pos, frontSide bool, oldText, newText string)
- func (s *Session) HandleSkinChange(ctx *event.Context, skin *skin.Skin)
- func (s *Session) HandleStartBreak(ctx *event.Context, pos cube.Pos)
- func (s *Session) HandleTeleport(ctx *event.Context, pos mgl64.Vec3)
- func (s *Session) HandleToggleSneak(ctx *event.Context, after bool)
- func (s *Session) HandleToggleSprint(ctx *event.Context, after bool)
- func (s *Session) HandleTransfer(ctx *event.Context, addr *net.UDPAddr)
- func (s *Session) InsertComponent(c Component) error
- func (s *Session) Player() *player.Player
- func (s *Session) Query(queryFunc any) bool
- func (s *Session) RemoveComponent(c Component) (Component, error)
- func (s *Session) Save(c Component) error
- func (s *Session) SaveAll() error
- func (s *Session) SetComponent(c Component)
- type With
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComponentFromSession ¶
ComponentFromSession returns and automatically type casts a user's component to the correct type if it is present.
Types ¶
type Adder ¶
type Adder interface { Component // Add gets called right after the component is added to a Session. This is always called regardless of how the // component is added. It is also called when another component of the same type was present but got replaced. The // owner of the session will be passed along as an argument. Gets called after the component has been loaded. Add(p *player.Player) }
Adder represents a Component that has a function that is called when the component is added to a Session in any way.
type Component ¶
type Component interface{}
Component represents some data type that can be stored in a player session. There can only be one component of each type per player, but each player does not necessarily need to have every component.
type ComponentProvider ¶
type ComponentProvider interface {
// contains filtered or unexported methods
}
ComponentProvider is the interface representation of any type of ProviderWrapper, allowing them to be passed in the Config.
type Config ¶
type Config struct { // Logger allows for an optional logger to be supplied. This will log things such as errors when saving components // when a player is leaving. Logger server.Logger // Handlers contains all the handlers that will run during the lifetime of the manager. These will always be active, // but can be controlled through adding or removing components from users. Handlers []Handler // Providers allows for passing of a list of ComponentProviders which can load & save components for players at // runtime. The providers must be wrapped in a ProviderWrapper using the WrapProvider function. Providers []ComponentProvider }
Config is a struct passed to the New function when creating a new Manager. It allows for customizing several aspects such as specifying handlers and component providers. Many of these cannot be modified after the manager has been created.
type GenericProvider ¶
type GenericProvider[c Component] interface { // Load loads & writes data stored under the provider UUID to the pointer to the component c. Comp can be nil if it // is being loaded from an offline player. Load(id uuid.UUID, comp *c) error // Save writes the component to storage, using the UUID to identify the owner of the data. Save(id uuid.UUID, comp *c) error }
GenericProvider represent a struct that can load & save data associated to a player for a certain component.
type Handler ¶
type Handler interface { }
Handler is a struct that handles player-related events. It can query for certain components contained in the player session, and will only run if all those components are present.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager stores all current sessions. It also contains all the registered handlers and component types.
func New ¶
New creates a new Session Manager. It also inserts all the provided handlers into the manager. Events will be called in the order the handlers are added to the manager. These handlers can query for specific components to be present in a player Session in order to actually run.
func (*Manager) Accept ¶
Accept assigns a Session to a player. This also works for disconnected players or fake players. Initial components can be provided for the player to start with. The add function will be called on any component that implements Adder. Providing multiple components of the same type is not allowed and will return an error.
func (*Manager) QueryAll ¶
QueryAll runs a query on all currently online players. This works the same as if a query is run on every Session separately (albeit slightly faster). A number of players on which the query executed successfully is returned.
func (*Manager) QueryID ¶
QueryID executes a query on a player by their UUID, regardless of whether they are online or not. If the player is online with a stored session, components will be fetched from that session. If the player is not online, or one of the components is not present, those components will be loaded if they have a provider. In this case, if at least one component has no provider or there was a provider error, the query will not run. Loaded components will be saved again. Returns any error that occurred and whether the query ran. Should be handled independently.
func (*Manager) SessionFromPlayer ¶
SessionFromPlayer returns a player's session.
func (*Manager) SessionFromUUID ¶
SessionFromUUID returns the session of the player with the corresponding UUID. Only works for currently online players.
type Option ¶
Option is a query that allows the query to specify whether a certain Component is present in the session, passing along its value if it exists. This value can be accessed through Option.Load().
type ProviderWrapper ¶
type ProviderWrapper[c Component] struct { // contains filtered or unexported fields }
ProviderWrapper is a wrapper around a GenericProvider to ensure strict typing of components and to easily allow for Peex to resolve the component type.
func WrapProvider ¶
func WrapProvider[c Component](p GenericProvider[c]) ProviderWrapper[c]
WrapProvider creates a new wrapper around a provider of the desired type.
type Query ¶
Query is used to query for a certain component type, passing its value to the handler. Query.Load() can be used to get the value.
type Remover ¶
type Remover interface { Component // Remove gets called right before the current component instance gets removed from the Session. This means the // method is also called when the component gets replaced with another of the same type. The owner of the session is // passed along as argument. Gets called before the component is saved. Remove(p *player.Player) }
Remover represents a Component that has extra logic that runs when the component is removed from a session in any way.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a unique object that stores a player's data and handles player events. Data is stored in components, which can be added and removed from the Session at any time.
func (*Session) Component ¶
Component returns the Component in the Session of the same type as the argument if it was found.
func (*Session) HandleAttackEntity ¶
func (*Session) HandleBlockBreak ¶
func (*Session) HandleBlockPick ¶
func (*Session) HandleBlockPlace ¶
func (*Session) HandleChangeWorld ¶
func (*Session) HandleCommandExecution ¶
func (*Session) HandleDeath ¶
func (s *Session) HandleDeath(src world.DamageSource, keepInv *bool)
func (*Session) HandleDiagnostics ¶
func (s *Session) HandleDiagnostics(d diagnostics.Diagnostics)
func (*Session) HandleExperienceGain ¶
func (*Session) HandleFireExtinguish ¶
func (*Session) HandleFoodLoss ¶
func (*Session) HandleHeal ¶
func (*Session) HandleHurt ¶
func (*Session) HandleItemConsume ¶
func (*Session) HandleItemDamage ¶
func (*Session) HandleItemDrop ¶
func (*Session) HandleItemPickup ¶
func (*Session) HandleItemUse ¶
func (*Session) HandleItemUseOnBlock ¶
func (*Session) HandleItemUseOnEntity ¶
func (*Session) HandleJump ¶
func (s *Session) HandleJump()
func (*Session) HandleLecternPageTurn ¶
func (*Session) HandleMove ¶
func (*Session) HandlePunchAir ¶
func (*Session) HandleQuit ¶
func (s *Session) HandleQuit()
func (*Session) HandleSignEdit ¶
func (*Session) HandleSkinChange ¶
func (*Session) HandleStartBreak ¶
func (*Session) HandleTeleport ¶
func (*Session) HandleToggleSneak ¶
func (*Session) HandleToggleSprint ¶
func (*Session) HandleTransfer ¶
func (*Session) InsertComponent ¶
InsertComponent adds the Component to the player, keeping all it's values. An error is returned if the Component was already present. Also loads the component if a provider for it has been set in the config.
func (*Session) Player ¶
Player returns the Player that owns the Session. Returns nil if the Session is owned by a player that is no longer online.
func (*Session) Query ¶
Query runs a query function on the session. This function must use the Query, With and Option types as input parameters. These will work like they do in a Handler. True is returned if the query actually ran, else false.
func (*Session) RemoveComponent ¶
RemoveComponent tries to remove the component with the same type as the provided argument from the Session. The value of the component will also be returned, If the Session does not have the component, nothing happens, and nil is returned. Also saves the component if a provider for it has been set in the config.
func (*Session) Save ¶
Save saves a single component type for the session. Saves the component of the same type as the argument that is currently present as opposed to the one provided as argument.
func (*Session) SaveAll ¶
SaveAll saves every component that can be saved. If for any component an error is returned, the last error will be returned by this function.
func (*Session) SetComponent ¶
SetComponent updates the value of a Component currently present in the Session. This is done regardless of whether this Component was present before. If the component was already present, and it implements Remover, the Remove method will first be called on the previous instance of the component. The Add method will be called on the new Component if it implements Adder.
NOTE: does NOT load the component!