import { WebInterface } from "./webserver" ; import { Config } from "./Config" ; import { Bridge , BridgeManager } from "./bridging" ; import { MatrixInterface } from "./matrix" ; import { DBController } from "./db" ; import { MxEvents , MCEvents , PlayerManager } from "./minecraft" ; import { MxMessage } from "./matrix/MatrixInterface" ; /**
 * This is the Main classes both the WebInterface and MatrixInterface
 * communicate to this class to exchange messages between Minecraft and Matrix.
 *
 * Visual Representation:
 * Minecraft Server -> WebInterface -> Main -> Matrix
 * Minecraft Server <- WebInterface <- Main <- Matrix
 */ export class Main { public readonly matrix : MatrixInterface ; public readonly webserver : WebInterface ; public readonly bridges : BridgeManager ; public readonly players : PlayerManager ; constructor ( ) { const config = Config . getConfig ( ) ; const db = new DBController ( config ) ; this . webserver = new WebInterface ( config , this ) ; this . matrix = new MatrixInterface ( config , this ) ; this . bridges = new BridgeManager ( config , db ) ; this . players = new PlayerManager ( ) ; } /**
     * This starts up the webserver and matrix appservice.
     */ public async start ( ) { await this . matrix . start ( ) ; const router = this . matrix . appservice . expressAppInstance ; this . webserver . start ( router ) ; } param { MxMessage } message throws public sendToMinecraft ( message ) { this . matrix . addNewMxMessage ( message ) ; } returns { MxEvents . Event [ ] } public getNewMxMessages ( bridge ) { return this . matrix . getNewMxMessages ( bridge ) ; } param { Bridge } bridge param { MCEvents . Message } message returns { Promise < void > } throws public sendToMatrix ( bridge , message ) { return this . matrix . sendMessage ( bridge , message ) ; } param { Bridge } bridge param { MCEvents . Join } join returns { Promise < void > } throws public joinToMatrix ( bridge , join ) { return this . matrix . sendJoin ( bridge , join ) ; } param { Bridge } bridge param { MCEvents . Quit } quit returns { Promise < void > } throws public quitToMatrix ( bridge , quit ) { return this . matrix . sendQuit ( bridge , quit ) ; } param { Bridge } bridge param { MCEvents . Kick } kick returns { Promise < void > } throws public kickToMatrix ( bridge , kick ) { return this . matrix . sendKick ( bridge , kick ) ; } }