[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / scripting/events/worldEvents

# scripting/events/worldEvents

## Interfaces

### ScriptWorldEvents

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:43](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L43)

What a level's scripts hear of the world events [WorldEventSource](#worldeventsource) describes.

#### Methods

##### events()

> **events**(`listener`): () => `void`

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:45](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L45)

###### Parameters

###### listener

(`event`) => `void`

###### Returns

() => `void`

##### guard()

> **guard**(`guard`): () => `void`

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:44](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L44)

###### Parameters

###### guard

[`ScriptGameEventGuard`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptgameeventguard)

###### Returns

() => `void`

##### poll()

> **poll**(): `void`

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:47](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L47)

Sends the changes of the state the sources compare, before the script flush takes the events.

###### Returns

`void`

***

### WorldEventSource

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:24](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L24)

One game system's world events.

#### Methods

##### events()?

> `optional` **events**(`listener`): () => `void`

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:34](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L34)

Calls `listener` with each of this system's after-events, once the world has kept the change.

###### Parameters

###### listener

(`event`) => `void`

###### Returns

A function that stops it.

() => `void`

##### guard()?

> `optional` **guard**(`guard`): () => `void`

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:29](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L29)

Adds a guard to the actions this system's before-events are about.

###### Parameters

###### guard

[`ScriptGameEventGuard`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptgameeventguard)

###### Returns

A function that removes it.

() => `void`

##### poll()?

> `optional` **poll**(): `void`

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:39](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L39)

Compares the state this system's events are about with what the last call saw, and sends
the listener an after-event for each change, once a tick before the script flush.

###### Returns

`void`

## Functions

### levelWorldEvents()

> **levelWorldEvents**(`server`, `level`): [`ScriptWorldEvents`](#scriptworldevents)

Defined in: [packages/prismarine/src/scripting/events/worldEvents.ts:62](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/events/worldEvents.ts#L62)

The world events of one level's scripts.

#### Parameters

##### server

[`Server`](https://jsprismarine.dev/api/@jsprismarine/prismarine/Server/classes/Server.md)

The server whose events carry the game systems' changes.

##### level

[`Level`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/Level/classes/Level.md)

The level whose worlds the scripts see.

#### Returns

[`ScriptWorldEvents`](#scriptworldevents)
