CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/lib/scoreboard.js
Views: 789
1
const sortItems = (a, b) => {
2
if (a.value > b.value) return -1
3
if (a.value < b.value) return 1
4
return 1
5
}
6
7
module.exports = (bot) => {
8
const ChatMessage = require('prismarine-chat')(bot.registry)
9
10
class ScoreBoard {
11
constructor (packet) {
12
this.name = packet.name
13
this.setTitle(packet.displayText)
14
this.itemsMap = {}
15
}
16
17
setTitle (title) {
18
try {
19
this.title = JSON.parse(title).text // version>1.13
20
} catch {
21
this.title = title
22
}
23
}
24
25
add (name, value) {
26
this.itemsMap[name] = { name, value }
27
this.itemsMap[name] = {
28
name,
29
value,
30
get displayName () {
31
if (name in bot.teamMap) {
32
return bot.teamMap[name].displayName(name)
33
}
34
return new ChatMessage(name)
35
}
36
}
37
return this.itemsMap[name]
38
}
39
40
remove (name) {
41
const removed = this.itemsMap[name]
42
delete this.itemsMap[name]
43
return removed
44
}
45
46
get items () {
47
return Object.values(this.itemsMap).sort(sortItems)
48
}
49
}
50
51
ScoreBoard.positions = {
52
get list () {
53
return this[0]
54
},
55
56
get sidebar () {
57
return this[1]
58
},
59
60
get belowName () {
61
return this[2]
62
}
63
}
64
return ScoreBoard
65
}
66
67