Skip to content

Go: Events

Functions

Subscribe

Go
func Subscribe(id string, priority Priority, fn func(*Event)) (*Listener, error)

Subscribe calls fn for every event with this id, on the server thread. The id is the full one, such as "ll::event::PlayerJoinEvent", or a unique suffix of it. Server thread only.

  • Parameters:
    • id : string
    • priority : Priority
    • fn : func(*Event)
  • Return type: (*Listener, error)
  • Slots: subscribe_event

ListEvents

Go
func ListEvents() ([]string, error)

ListEvents lists every event id this host can subscribe to. Server thread only.

Event

Go
1
2
3
4
5
type Event struct {
    ID   string
    SNBT string
    // unexported fields
}

Event is one event as a listener receives it. SNBT is the payload, whose fields the event payload reference documents; it is a copy, valid after the callback returns.

Event.Payload

Go
func (e *Event) Payload() (*Nbt, error)

Payload is SNBT parsed, once per event.

  • Return type: (*Nbt, error)

Event.Unresolved

Go
func (e *Event) Unresolved() []string

Unresolved lists the fields the host could not resolve, from _unresolved. It is empty too when the payload does not parse, which CheckComplete does not count as complete.

  • Return type: []string

Event.CheckComplete

Go
func (e *Event) CheckComplete() bool

CheckComplete reports whether the payload parsed and nothing in it is unresolved. A protection decision on an incomplete payload should refuse rather than guess.

  • Return type: bool

Event.Dim

Go
func (e *Event) Dim() (int32, error)

Dim is the dimension the event happened in. An unreadable or incomplete payload is an error and never 0: read as the overworld it would let an event in a custom dimension pass a rule made for the overworld.

  • Return type: (int32, error)

Event.Set

Go
func (e *Event) Set(key string, value *Nbt)

Set writes key back into the event when the callback returns. Only the keys set go back, and the host merges them, so two listeners setting different keys keep both.

  • Parameters:
    • key : string
    • value : *Nbt

Event.Cancel

Go
func (e *Event) Cancel()

Cancel asks the host to cancel the event once the callback returns. An event that cannot be cancelled ignores it; the documentation of each event says whether it can be.

Event.Uncancel

Go
func (e *Event) Uncancel()

Uncancel undoes a Cancel of this callback. A cancel made by an earlier listener stays.

Listener

Go
1
2
3
type Listener struct {
    // unexported fields
}

Listener is one subscription, kept to end it.

Listener.Unsubscribe

Go
func (l *Listener) Unsubscribe() error

Unsubscribe ends the subscription. Calling it twice is harmless. Server thread only.

ListenerHandle

Go
type ListenerHandle struct{ p unsafe.Pointer }
type ListenerHandle struct{ p unsafe.Pointer }

ListenerHandle is an event listener as the host names it.

ListenerHandle.IsZero

Go
func (h ListenerHandle) IsZero() bool

IsZero reports whether the handle names nothing.

  • Return type: bool

Priority

Go
type Priority int32

Priority orders the listeners of one event; it mirrors ll::event::EventPriority.

Name Value Description
PriorityHighest 0
PriorityHigh 1
PriorityNormal 2
PriorityLow 3
PriorityLowest 4