|
|
import { Bot } from 'mineflayer' |
|
|
|
|
|
class Subscription { |
|
|
constructor (readonly eventName: string, readonly callback: Function) {} |
|
|
} |
|
|
|
|
|
export class TemporarySubscriber { |
|
|
private readonly subscriptions: Subscription[] = [] |
|
|
|
|
|
constructor (readonly bot: Bot) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subscribeTo (event: string, callback: Function): void { |
|
|
this.subscriptions.push(new Subscription(event, callback)) |
|
|
|
|
|
|
|
|
this.bot.on(event, callback) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cleanup (): void { |
|
|
for (const sub of this.subscriptions) { |
|
|
|
|
|
this.bot.removeListener(sub.eventName, sub.callback) |
|
|
} |
|
|
} |
|
|
} |
|
|
|