-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexampleWrapClient.js
executable file
·47 lines (41 loc) · 1.19 KB
/
exampleWrapClient.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
#!/usr/bin/env node
const WrapClient = require('../').WrapClient
const path = require('path')
if (process.argv.length < 0) {
console.log('Usage : node exampleWrapClient.js [<minecraft dir>] [<version>] [<username>] [<password>] [<stop>]')
process.exit(0)
}
const version = process.argv[3]
const dir = process.argv[2] ? path.isAbsolute(process.argv[2]) ? process.argv[2] : path.join(process.cwd(), process.argv[2]) : null
const vClient = new WrapClient(dir, version)
const username = process.argv[4]
const password = process.argv[5]
const stop = process.argv[6]
vClient.on('line', function (line) {
console.log(line)
})
Promise.resolve()
.then(() => vClient.auth(username, password))
.then(() => console.log('User logged in !'))
.then(() => vClient.prepare())
.then(() => console.log('Client prepared !'))
.then(() => vClient.start())
.then(() => {
console.log('Client Started !')
})
.then(() => {
if (stop) {
setTimeout(() => {
vClient.stop()
.then(() => {
console.log('Client Stopped !')
})
.catch((err) => {
console.log(err)
})
}, 3000)
}
})
.catch((err) => {
console.log(err)
})