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/examples/plugins/afk.js
Views: 789
1
/*
2
Make a function that is exported, this will be the "inject function", which is called when loading the plugin into mineflayer.
3
You can load this plugin into mineflayer in three ways:
4
5
1.
6
```
7
bot.createBot({
8
plugins: [require('./plugin')]
9
})
10
```
11
12
2.
13
```
14
bot.createBot({
15
plugins: {
16
afk: require('./plugin')
17
}
18
})
19
```
20
21
3.
22
```
23
const bot = bot.createBot()
24
bot.loadPlugin(require('./plugin'))
25
```
26
*/
27
module.exports = bot => {
28
/*
29
Inside the scope of this function, you should do anything you need to with the bot object, like add properties to it, like `bot.afk`,
30
this function will be called when this plugin is called during the login process
31
*/
32
let rotater
33
let rotated = false
34
bot.afk = {}
35
36
bot.afk.start = () => {
37
if (rotater) return
38
rotater = setInterval(rotate, 3000)
39
}
40
41
bot.afk.stop = () => {
42
if (!rotater) return
43
clearInterval(rotater)
44
}
45
46
function rotate () {
47
bot.look(rotated ? 0 : Math.PI, 0)
48
rotated = !rotated
49
}
50
}
51
52