Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Added plugins loaded in process title
Browse files Browse the repository at this point in the history
  • Loading branch information
PMK744 committed Jul 11, 2021
1 parent 287ac81 commit ff007fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/bewss/plugin/pluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface examplePlugin {
class pluginManager {
private bewss: bewss
private plugins = new Map<string, { config: examplePluginConfig, plugin: examplePlugin }>() // path: { config, plugin }
private pluginNames: Array<string> = []
private latestInterface = "https://raw.githubusercontent.com/PMK744/Node-BEWSS/main/src/bewss/%40interface/bewss.i.ts"
public root = path.resolve(process.cwd())
public pluginsPath = path.resolve(this.root, './plugins')
Expand Down Expand Up @@ -123,6 +124,7 @@ class pluginManager {
const plugin: examplePlugin = require(entryPoint)
const newPlugin: examplePlugin = new plugin(new pluginApi(this.bewss, config, path))
this.info(`Successfully loaded plugin "${config.displayName || path}"`)
this.pluginNames.push(config.displayName || config.name || path)
this.plugins.set(path, {
config,
plugin: newPlugin,
Expand Down Expand Up @@ -332,6 +334,9 @@ class pluginManager {
return true
}

getPlugins(): Array<string> {
return this.pluginNames
}

private info(...content: unknown[]): void {
console.log(`${chalk.gray(moment().format("HH:mm:ss"))} ${chalk.blue("[PluginManager]")} ${chalk.cyan("[Info]")}`, ...content)
Expand Down
14 changes: 13 additions & 1 deletion src/bewss/server/serverManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class serverManager extends EventEmitter {
private ws: Websocket.Server
private server: Websocket
private port: number
private inv

constructor (bewss: bewss, port: number) {
super()
Expand All @@ -15,11 +16,12 @@ class serverManager extends EventEmitter {
}

async onEnabled(): Promise<void> {
process.title = 'Minecraft Bedrock Edition - BeWss'
this.startProcessTitle()
await this.createServer()
}

async onDisabled(): Promise<void> {
clearInterval(this.inv)
this.ws.close()
this.emit('wssclosed')
this.bewss.getLogger().info('Websocket server closed.')
Expand Down Expand Up @@ -56,6 +58,16 @@ class serverManager extends EventEmitter {
})
}

private startProcessTitle(): void {
this.inv = setInterval(() => {
const plugins = this.bewss.getPluginManager().getPlugins()
let pluginDisplay = plugins.join(', ')
if (plugins.length == 0) pluginDisplay = 'None'

process.title = `Minecraft Bedrock Edition - BeWss | Plugins Loaded - ${pluginDisplay}`
}, 10)
}

sendJSON(json: JSON): void {
this.server.send(JSON.stringify(json))
}
Expand Down

0 comments on commit ff007fa

Please sign in to comment.