import { Client } from 'minecraft-protocol' import { Logger } from 'pino' type ModuleLoader = >(module: IModuleType) => T /** Typeof Module */ export interface IModuleType { name: string new(client: Client, logger: Logger, conf: object, getModule: ModuleLoader): Module<{}> } /** Management unit */ export default abstract class Module { protected logger: Logger protected client: Client protected conf: T private readonly getModule: ModuleLoader constructor(client: Client, logger: Logger, conf: object, getModule: ModuleLoader) { this.client = client this.logger = logger this.conf = {...this.getConf(), ...conf} this.getModule = getModule this.mount() } /** Mostly to clean timers */ public umount() { // nothing } /** Default values of config */ protected abstract getConf(): T /** Setup listener on client */ protected abstract mount(): void /** Get reference to another module */ protected load>(module: IModuleType): M { return this.getModule(module) } }