36 lines
726 B
TypeScript
36 lines
726 B
TypeScript
|
import { World } from './world';
|
||
|
import { addBridge } from 'scriptcraft-core';
|
||
|
|
||
|
/**
|
||
|
* Tick Event
|
||
|
*/
|
||
|
export class TickEvent {
|
||
|
/**
|
||
|
* Instance
|
||
|
*/
|
||
|
static INSTANCE: TickEvent = new TickEvent();
|
||
|
/**
|
||
|
* @internal
|
||
|
*/
|
||
|
#listeners: ((world: World) => void)[];
|
||
|
|
||
|
/**
|
||
|
* Add Event Listener
|
||
|
* @param listener Event Listener
|
||
|
*/
|
||
|
addListener(listener: (world: World) => void): void {
|
||
|
this.#listeners.push(listener);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @internal
|
||
|
*/
|
||
|
run(world: World): void {
|
||
|
for (const listener of this.#listeners) {
|
||
|
listener(world);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
addBridge('TickEvent.run', (world: JavaObject) => TickEvent.INSTANCE.run(new World(world)));
|