forked from JSPrismarine/JSPrismarine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
64 lines (52 loc) · 1.59 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const fs = require('fs')
const readline = require('readline')
const path = require('path')
const Prismarine = require('./src/prismarine')
const logger = require('./src/utils/logger')
const ConsoleSender = require('./src/command/console-sender')
const PaletteManager = require('./src/world/palette-manager')
'use strict'
// TODO: read config
const server = new Prismarine(logger)
// Create folders
if (!(fs.existsSync(__dirname + '/plugins'))) {
fs.mkdirSync(__dirname + '/plugins')
}
if (!(fs.existsSync(__dirname + '/worlds'))) {
fs.mkdirSync(__dirname + '/worlds')
}
// Load default level
// TODO: get its name from a config
server.getWorldManager().loadWorld('world')
// Init block states
PaletteManager.init()
// Load all plugins
let pluginFolders = fs.readdirSync('./plugins')
for (let i = 0; i < pluginFolders.length; i++) {
const folderName = pluginFolders[i]
try {
server.getPluginManager().loadPlugin(
path.resolve('./plugins', folderName)
)
} catch (error) {
logger.warn(
`Error while loading plugin §b${folderName}§r: §c${error}`
)
}
}
// Console command reader
let rl = readline.createInterface({input: process.stdin})
rl.on('line', (input) => {
if (typeof input !== 'string') {
return logger.warn('Got an invalid command!')
}
if (!(input.startsWith('/'))) {
input = `/${input}`
}
server.getCommandManager().dispatchCommand(
new ConsoleSender(server), input
)
})
server.listen().catch(() =>
logger.error(`Cannot start the server, is it already running on the same port?`)
)