Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/examples/bossbar.js
9427 views
1
const mineflayer = require('mineflayer')
2
3
if (process.argv.length < 4 || process.argv.length > 6) {
4
console.log('Usage : node bossbar.js <host> <port> [<name>] [<password>]')
5
process.exit(1)
6
}
7
8
const bot = mineflayer.createBot({
9
host: process.argv[2],
10
port: parseInt(process.argv[3]),
11
username: process.argv[4] ? process.argv[4] : 'bossbar_bot',
12
password: process.argv[5]
13
})
14
15
// Wait for spawn
16
bot.once('spawn', () => {
17
console.log('Bot spawned!')
18
19
// Create a boss bar
20
bot.chat('/bossbar add test:bar "Test Boss Bar"')
21
bot.chat('/bossbar set test:bar players ' + bot.username)
22
bot.chat('/bossbar set test:bar color red')
23
bot.chat('/bossbar set test:bar style notched_6')
24
bot.chat('/bossbar set test:bar value 50')
25
})
26
27
// Listen for boss bar events
28
bot.on('bossBarCreated', (bossBar) => {
29
console.log('Boss bar created:', bossBar.title.toString())
30
})
31
32
bot.on('bossBarUpdated', (bossBar) => {
33
console.log('Boss bar updated:', {
34
title: bossBar.title.toString(),
35
health: bossBar.health,
36
color: bossBar.color,
37
dividers: bossBar.dividers
38
})
39
})
40
41
bot.on('bossBarDeleted', (bossBar) => {
42
console.log('Boss bar deleted:', bossBar.title.toString())
43
})
44
45
// After 5 seconds, update the boss bar
46
setTimeout(() => {
47
bot.chat('/bossbar set test:bar color blue')
48
bot.chat('/bossbar set test:bar style notched_10')
49
bot.chat('/bossbar set test:bar value 75')
50
}, 5000)
51
52
// After 10 seconds, remove the boss bar
53
setTimeout(() => {
54
bot.chat('/bossbar remove test:bar')
55
}, 10000)
56
57